[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sun, 26 Mar 2023 11:06:55 -0400 (EDT) |
branch: master
commit b328cdf7f9a7677c7366cce7153a4eab433ae5e6
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Mar 26 17:00:28 2023 +0200
* tp/Texinfo/XS/parsetexi/def.c (parse_def),
tp/Texinfo/XS/parsetexi/end_line.c (end_line_def_line),
tp/Texinfo/XS/parsetexi/tree_types.h (DEF_ARG): return parsed
definition information as a list of DEF_ARG argument type name and
element, instead of setting the types of arguments as structure
firelds. Remove DEF_INFO type.
---
ChangeLog | 9 +++++
tp/Texinfo/XS/parsetexi/def.c | 72 +++++++++++++++++-------------------
tp/Texinfo/XS/parsetexi/def.h | 2 +-
tp/Texinfo/XS/parsetexi/end_line.c | 50 ++++++++++++++++---------
tp/Texinfo/XS/parsetexi/tree_types.h | 9 ++---
5 files changed, 79 insertions(+), 63 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 55577f37ef..cbc3cb0e1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,15 @@
* NEWS: add 7.0.3 news.
* README-hacking: update
+2023-03-26 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/parsetexi/def.c (parse_def),
+ tp/Texinfo/XS/parsetexi/end_line.c (end_line_def_line),
+ tp/Texinfo/XS/parsetexi/tree_types.h (DEF_ARG): return parsed
+ definition information as a list of DEF_ARG argument type name and
+ element, instead of setting the types of arguments as structure
+ firelds. Remove DEF_INFO type.
+
2023-03-26 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/parsetexi/def.c (DEF_MAP, def_maps, parse_def): pass
diff --git a/tp/Texinfo/XS/parsetexi/def.c b/tp/Texinfo/XS/parsetexi/def.c
index 79e37aef7c..2a4d5de8c4 100644
--- a/tp/Texinfo/XS/parsetexi/def.c
+++ b/tp/Texinfo/XS/parsetexi/def.c
@@ -154,6 +154,14 @@ typedef struct {
char **arguments;
} DEF_MAP;
+ /*
+ Meaning of these:
+ CATEGORY - type of entity, e.g. "Function"
+ CLASS - class for object-oriented programming
+ TYPE - data type of a variable or function return value
+ NAME - name of entity being documented
+ ARGUMENTS - arguments to a function or macro */
+
char *defline_arguments[] = {"category", "name", "arg", 0};
char *defvr_arguments[] = {"category", "name", 0};
char *deftypefn_arguments[] = {"category", "type", "name", "argtype", 0};
@@ -314,17 +322,15 @@ split_def_args (ELEMENT *current, int starting_idx)
}
}
-DEF_INFO *
+DEF_ARG **
parse_def (enum command_id command, ELEMENT *current)
{
- DEF_INFO *ret;
int contents_idx = 0;
int type, next_type;
int i, i_def;
+ int arg_types_nr;
ELEMENT *e, *e1;
-
- ret = malloc (sizeof (DEF_INFO));
- memset (ret, 0, sizeof (DEF_INFO));
+ DEF_ARG **result;
split_def_args (current, contents_idx);
@@ -365,14 +371,8 @@ parse_def (enum command_id command, ELEMENT *current)
insert_into_contents (current, e, contents_idx + 1);
}
- /* Read arguments as CATEGORY [CLASS] [TYPE] NAME [ARGUMENTS].
+ /* Read arguments as CATEGORY [CLASS] [TYPE] NAME [ARGUMENTS]. */
- Meaning of these:
- CATEGORY - type of entity, e.g. "Function"
- CLASS - class for object-oriented programming
- TYPE - data type of a variable or function return value
- NAME - name of entity being documented
- ARGUMENTS - arguments to a function or macro */
for (i_def = 0; i_def < sizeof (def_maps) / sizeof (*def_maps); i_def++)
{
@@ -382,38 +382,32 @@ parse_def (enum command_id command, ELEMENT *current)
fatal ("no arguments for def command");
def_found:
- i = 0;
- while (def_maps[i_def].arguments[i])
+ /* determine non arg/argtype number of arguments */
+ arg_types_nr = 0;
+ while (def_maps[i_def].arguments[arg_types_nr])
{
- char *arg_type_name = def_maps[i_def].arguments[i];
+ char *arg_type_name = def_maps[i_def].arguments[arg_types_nr];
- if (!strcmp (arg_type_name, "category"))
- ret->category = next_bracketed_or_word_agg (current, &contents_idx);
- else if (!strcmp (arg_type_name, "class"))
- ret->class = next_bracketed_or_word_agg (current, &contents_idx);
- else if (!strcmp (arg_type_name, "type"))
- ret->type = next_bracketed_or_word_agg (current, &contents_idx);
- else if (!strcmp (arg_type_name, "name"))
- ret->name = next_bracketed_or_word_agg (current, &contents_idx);
- i++;
+ /* FIXME keep information about arg/argtype? */
+ if (!strcmp (arg_type_name, "arg")
+ || !strcmp (arg_type_name, "argtype"))
+ break;
+ arg_types_nr++;
}
+ result = malloc ((arg_types_nr+1) * sizeof (DEF_ARG *));
- if (ret->category)
- {
- add_extra_string_dup (ret->category, "def_role", "category");
- }
- if (ret->class)
+ for (i = 0; i < arg_types_nr; i++)
{
- add_extra_string_dup (ret->class, "def_role", "class");
- }
- if (ret->type)
- {
- add_extra_string_dup (ret->type, "def_role", "type");
- }
- if (ret->name)
- {
- add_extra_string_dup (ret->name, "def_role", "name");
+ char *arg_type_name = def_maps[i_def].arguments[i];
+ DEF_ARG *def_arg = malloc (sizeof (DEF_ARG));
+
+ result[i] = def_arg;
+ def_arg->arg_type = strdup(arg_type_name);
+ def_arg->element = next_bracketed_or_word_agg (current, &contents_idx);
+ if (def_arg->element)
+ add_extra_string_dup (def_arg->element, "def_role", arg_type_name);
}
+ result[i] = 0;
/* Process args */
split_delimiters (current, contents_idx);
@@ -450,5 +444,5 @@ parse_def (enum command_id command, ELEMENT *current)
(type == 1 ? "arg" : "typearg"));
type *= next_type;
}
- return ret;
+ return result;
}
diff --git a/tp/Texinfo/XS/parsetexi/def.h b/tp/Texinfo/XS/parsetexi/def.h
index 074e5286e0..906b744038 100644
--- a/tp/Texinfo/XS/parsetexi/def.h
+++ b/tp/Texinfo/XS/parsetexi/def.h
@@ -5,5 +5,5 @@
#include "tree_types.h"
void gather_def_item (ELEMENT *current, enum command_id next_command);
-DEF_INFO *parse_def (enum command_id command, ELEMENT *current);
+DEF_ARG **parse_def (enum command_id command, ELEMENT *current);
#endif
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index 2c16d94ea0..68088201b4 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -638,9 +638,13 @@ ELEMENT *
end_line_def_line (ELEMENT *current)
{
enum command_id def_command;
- DEF_INFO *def_info = 0;
- static DEF_INFO zero_def_info; /* always stays zeroed */
+ DEF_ARG **def_info = 0;
KEY_PAIR *k;
+ ELEMENT *index_entry = 0; /* Index entry text. */
+ ELEMENT *def_info_name = 0;
+ ELEMENT *def_info_class = 0;
+ ELEMENT * def_info_category = 0;
+ int i = 0;
if (pop_context () != ct_def)
fatal ("def context expected");
@@ -653,35 +657,41 @@ end_line_def_line (ELEMENT *current)
current = current->parent;
/* Record the index entry if def_info is not empty. */
- if (!memcmp(def_info, &zero_def_info, sizeof (DEF_INFO)))
+
+ while (def_info[i] != 0 && def_info[i]->element != 0)
{
- free (def_info);
- k = lookup_extra (current, "original_def_cmdname");
- command_warn (current, "missing category for @%s", (char *) k->value);
+ if (!strcmp(def_info[i]->arg_type, "name"))
+ def_info_name = def_info[i]->element;
+ else if (!strcmp(def_info[i]->arg_type, "class"))
+ def_info_class = def_info[i]->element;
+ else if (!strcmp(def_info[i]->arg_type, "category"))
+ def_info_category = def_info[i]->element;
+ free (def_info[i]->arg_type);
+ free (def_info[i]);
+ i++;
}
- else
- {
- ELEMENT *index_entry = 0; /* Index entry text. */
+ free (def_info);
- if (def_info->name)
+ if (def_info_category)
+ {
+ if (def_info_name)
{
char *t;
/* Set index_entry unless an empty ET_bracketed_arg. */
- if (def_info->name->type == ET_bracketed_arg
- && (def_info->name->contents.number == 0
- || (def_info->name->contents.number == 1
- && (t = def_info->name->contents.list[0]->text.text)
+ if (def_info_name->type == ET_bracketed_arg
+ && (def_info_name->contents.number == 0
+ || (def_info_name->contents.number == 1
+ && (t = def_info_name->contents.list[0]->text.text)
&& t[strspn (t, whitespace_chars)] == '\0')))
{
}
else
- index_entry = def_info->name;
+ index_entry = def_info_name;
}
if (index_entry)
{
-
- if (def_info->class &&
+ if (def_info_class &&
(def_command == CM_defop
|| def_command == CM_deftypeop
|| def_command == CM_defmethod
@@ -711,6 +721,12 @@ end_line_def_line (ELEMENT *current)
command_warn (current, "missing name for @%s", (char *) k->value);
}
}
+ else
+ {
+ k = lookup_extra (current, "original_def_cmdname");
+ command_warn (current, "missing category for @%s", (char *) k->value);
+ }
+
current = current->parent;
current = begin_preformatted (current);
diff --git a/tp/Texinfo/XS/parsetexi/tree_types.h
b/tp/Texinfo/XS/parsetexi/tree_types.h
index 733bba4d1f..e4a742bcf5 100644
--- a/tp/Texinfo/XS/parsetexi/tree_types.h
+++ b/tp/Texinfo/XS/parsetexi/tree_types.h
@@ -149,12 +149,9 @@ typedef struct {
ELEMENT **out_of_tree_elements;
} NODE_SPEC_EXTRA;
-/* For @def*. */
typedef struct {
- ELEMENT *category;
- ELEMENT *class;
- ELEMENT *type;
- ELEMENT *name;
-} DEF_INFO;
+ char *arg_type;
+ ELEMENT *element;
+} DEF_ARG;
#endif