On 2012-08-29 20:31 , Aaron Gray wrote:
2012-08-30 Aaron Gray <aaronngray.li...@gmail.com>
* gengtype-lex.l: Support for FILE
Support for C++ single line Comments
Support for classes
Support for enums
ignore 'static'
ignore 'inline'
ignore 'public:'
ignore 'protected:'
ignore 'private:'
ignore 'friend'
support for 'operator' token
support for 'new'
support for 'delete'
added support for '+' as a token for summations in enum bodies
* gengtype.h: added 'TYPE_ENUM' to 'enum typekind'
added enum TYPE_ENUM to 'struct type' union
Write entries like these as:
* gengtype.h (enum type_kind): Add TYPE_ENUM.
(struct type): Add TYPE_ENUM.
added OPERATOR_KEYWORD and OPERATOR keywords to Token Code enum
Likewise.
* gengtype-parser.c: updated 'token_names[]'
(direct_declarator): support for parsing limited operators
support for parsing constructors with no parameters
support for parsing enums
* gengtype.c: added 'type_p enums' to maintain list of enums
(resolve_typedef): added support for stucture types and enums
added 'new_enum()'
diff --git a/gcc/gengtype-lex.l b/gcc/gengtype-lex.l
index 5788a6a..af9696a 100644
--- a/gcc/gengtype-lex.l
+++ b/gcc/gengtype-lex.l
@@ -53,11 +53,11 @@ update_lineno (const char *l, size_t len)
ID [[:alpha:]_][[:alnum:]_]*
WS [[:space:]]+
HWS [ \t\r\v\f]*
-IWORD
short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD|CPPCHAR_SIGNED_T|ino_t|dev_t|HARD_REG_SET
+IWORD
short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD|CPPCHAR_SIGNED_T|ino_t|dev_t|HARD_REG_SET|FILE
ITYPE {IWORD}({WS}{IWORD})*
EOID [^[:alnum:]_]
-%x in_struct in_struct_comment in_comment
+%x in_struct in_struct_comment in_comment in_line_comment
in_line_struct_comment
%option warn noyywrap nounput nodefault perf-report
%option 8bit never-interactive
%%
@@ -83,6 +83,14 @@ EOID [^[:alnum:]_]
BEGIN(in_struct);
return UNION;
}
+^{HWS}class/{EOID} {
+ BEGIN(in_struct);
+ return STRUCT;
+}
+^{HWS}enum/{EOID} {
+ BEGIN(in_struct);
+ return ENUM;
+}
^{HWS}extern/{EOID} {
BEGIN(in_struct);
return EXTERN;
@@ -101,10 +109,20 @@ EOID [^[:alnum:]_]
\\\n { lexer_line.line++; }
"const"/{EOID} /* don't care */
+"static"/{EOID} /* don't care */
+"inline"/{EOID} /* don't care */
+"public:" /* don't care */
+"private:" /* don't care */
+"protected:" /* don't care */
+"operator"/{EOID} { return OPERATOR_KEYWORD; }
+"new"/{EOID} { *yylval = XDUPVAR (const char,
yytext+1, yyleng-2, yyleng-1); return OPERATOR; }
+"delete"/{EOID} { *yylval = XDUPVAR (const char,
yytext+1, yyleng-2, yyleng-1); return OPERATOR; }
+"friend"/{EOID}
"GTY"/{EOID} { return GTY_TOKEN; }
"VEC"/{EOID} { return VEC_TOKEN; }
"union"/{EOID} { return UNION; }
"struct"/{EOID} { return STRUCT; }
+"class"/{EOID} { return CLASS; }
Why not just return STRUCT here?
@@ -3,7 +3,7 @@
This file is part of GCC.
- GCC is free software; you can redistribute it and/or modify it under
+ /GCC is free software; you can redistribute it and/or modify it under
This seems out of place.
@@ -778,6 +791,7 @@ type (options_p *optsp, bool nested)
return resolve_typedef (s, &lexer_line);
case STRUCT:
+ case CLASS:
I think that as far as gengtype is concerned, 'struct' and 'class'
should be exactly the same thing. So, all the handling for 'CLASS' you
added should not be needed.
+/* enum definition: type() does all the work. */
+static void
+parse_enum (void)
+{
+ options_p dummy;
+ type (&dummy, false);
+ /* There may be junk after the type: notably, we cannot currently
+ distinguish 'struct foo *function(prototype);' from 'struct foo;'
+ ... we could call declarator(), but it's a waste of time at
+ present. Instead, just eat whatever token is currently lookahead
+ and go back to lexical skipping mode. */
+ advance ();
+}
+
I'm not quite sure what is this trying to do.
@@ -601,16 +602,93 @@ type_p
resolve_typedef (const char *s, struct fileloc *pos)
{
pair_p p;
+ type_p t;
+ type_p e;
+
for (p = typedefs; p != NULL; p = p->next)
if (strcmp (p->name, s) == 0)
return p->type;
+ for (t = structures; t != NULL; t = t->next)
+ {
+ switch ( t->kind)
+ {
+ case TYPE_NONE:
+ if (do_debug)
+ fprintf(stderr, "TYPE_NONE:\n");
+ break;
+ case TYPE_SCALAR:
+ if (do_debug)
+ fprintf(stderr, "TYPE_SCALAR:\n");
+ break;
+ case TYPE_STRING:
+ if (do_debug)
+ fprintf(stderr, "TYPE_STRING:\n");
+ break;
+ case TYPE_STRUCT:
+ if (do_debug)
+ fprintf(stderr, "TYPE_STRUCT: '%s'\n", t->u.s.tag);
+ goto structure;
+ case TYPE_UNION:
+ if (do_debug)
+ fprintf(stderr, "TYPE_UNION: '%s'\n", t->u.s.tag);
+ goto structure;
+ case TYPE_LANG_STRUCT:
+ if (do_debug)
+ fprintf(stderr, "TYPE_LANG_STRUCT: '%s'\n", t->u.s.tag);
+ structure:
+ if (strcmp (t->u.s.tag, s) == 0)
+ return t;
+ break;
+ case TYPE_POINTER:
+ if (do_debug)
+ fprintf(stderr, "TYPE_POINTER:\n");
+ break;
+ case TYPE_ARRAY:
+ if (do_debug)
+ fprintf(stderr, "TYPE_ARRAY:\n");
+ break;
+ case TYPE_PARAM_STRUCT:
+ if (do_debug)
+ fprintf(stderr, "TYPE_PARAM_STRUCT:\n");
+ break;
+ default:
+ if (do_debug)
+ fprintf(stderr, "default:\n");
+ break;
+ }
+ };
+
Yikes. What are you trying to do here?
@@ -148,9 +149,10 @@ enum typekind {
param1_is, param2_is,... use_param1,
use_param_2,... use_params) GTY
options. */
- TYPE_USER_STRUCT /* User defined type. Walkers and markers for
+ TYPE_USER_STRUCT, /* User defined type. Walkers and markers for
this type are assumed to be provided by the
user. */
+ TYPE_ENUM /* Type for enums. */
What are enums used for? Do they affect gengtype's operation in any way?
};
/* Discriminating kind for options. */
@@ -309,6 +311,11 @@ struct type {
struct fileloc line; /* The source location. */
} param_struct;
+ /* when TYPE_ENUM */
+
+ struct {
+ const char *tag; /* the aggragate tag, if any. */
s/aggragate/aggregate/
Diego.