aboutsummaryrefslogtreecommitdiff
path: root/gcc/gengtype.h
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2012-10-12 15:17:17 +0000
committerDiego Novillo <dnovillo@google.com>2012-10-12 15:17:17 +0000
commitd36e9f5b1646c9faeb3c598d0769a800cefae1aa (patch)
tree3f1c4b6afbebcb24454c2dce4ca0c8c5934987c0 /gcc/gengtype.h
parentb573483dbaa8f8aa27c955f769d7a2e6d7cfa3fe (diff)
Add more C++ support in gengtype.
This patch combines the changes from http://gcc.gnu.org/ml/gcc-patches/2012-08/msg02016.html with other additions to support C++ inside GTY'd structures. The main changes wrt Aaron's original patch are: - Support for function declarations inside classes. - Support scoping in identifiers. This does not mean that gengtype supports scopes, it just knows that 'Foo::id' is a single entity. - Explicit non-support for typedef and enum inside class/struct. Since gengtype does not really know about scopes, it cannot understand these types, but it knows enough to recognize and reject them. GTY'd struct/class that need to typedef their own types should use GTY((user)). - Documentation on what is and is not supported. There is one check I needed to remove that gave me some trouble. When a ctor is detected, we have already parsed the name of the ctor as a type, which is then registered in the list of structures. We go on to recognize it as a ctor *after* the type has been registered. We reject the field in declarator() and it is never added to the list of fields for the class. However, when we reach the end of the class, we find that the type we created while parsing the ctor has line number information in it (the line where the ctor was) and gengtype thinks that it is a duplicate structure definition. I took out this check for two reasons: (a) It is actually unnecessary because if there were really duplicate definitions of this structure, the code would not compile, and (b) all the other alternatives required making the parser much more convoluted and I'm trying hard not to make gengtype parser too smart. 2012-10-12 Aaron Gray <aaronngray.lists@gmail.com> Diego Novillo <dnovillo@google.com> * gengtype-lex.l: Support for C++ single line comments. Support for classes. (CXX_KEYWORD): New. Support C++ keywords inline, public, protected, private, template, operator, friend, &, ~. (TYPEDEF): New. Support typedef. * gengtype-parser.c: updated 'token_names[]' (direct_declarator): Add support for parsing functions and ctors. 2012-10-12 Diego Novillo <dnovillo@google.com> * doc/gty.texi: Document C++ limitations in gengtype. * gengtype-lex.l (CID): Rename from ID. (ID): Include scoping '::' as part of the identifier name. * gengtype-parse.c (token_names): Update. (token_value_format): Update. (consume_until_eos): Rename from consume_until_semi. Remove unused argument IMMEDIATE. Update all callers. Also consider '}' as a finalizer. (consume_until_comma_or_eos): Rename from consume_until_comma_or_semi. Remove unused argument IMMEDIATE. Update all callers. Also consider '}' as a finalizer. (direct_declarator): Add documentation on ctor support. Add argument IN_STRUCT. If the token following ID is a '(', consider ID a function and return NULL. If the token following '(' is not a '*', and IN_STRUCT is true, conclude that this is a ctor and return NULL. If the token is IGNORABLE_CXX_KEYWORD, return NULL. (inner_declarator): Add argument IN_STRUCT. Update all callers. (declarator): Add argument IN_STRUCT with default value false. Update all callers. (type): Document argument NESTED. Skip over C++ inheritance specifiers. If a token TYPEDEF is found, emit an error. If an enum is found inside a class/structure, emit an error. (typedefs, structures, param_structs, variables): Initialize. (new_structure): Do not complain about duplicate structures if S has a line location set. * gengtype-state.c (write_state_type): Remove default handler. Add handler for TYPE_NONE. (read_state_scalar_char_type): * gengtype.c: Fix spacing. * gengtype.h (enum gty_token): Add name. Add token IGNORABLE_CXX_KEYWORD. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@192405 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gengtype.h')
-rw-r--r--gcc/gengtype.h65
1 files changed, 32 insertions, 33 deletions
diff --git a/gcc/gengtype.h b/gcc/gengtype.h
index 4a178ec3967..e687e488567 100644
--- a/gcc/gengtype.h
+++ b/gcc/gengtype.h
@@ -308,7 +308,6 @@ struct type {
type_p param[NUM_PARAM]; /* The actual parameter types. */
struct fileloc line; /* The source location. */
} param_struct;
-
} u;
};
@@ -444,38 +443,38 @@ extern void parse_file (const char *name);
extern bool hit_error;
/* Token codes. */
-enum
- {
- EOF_TOKEN = 0,
-
- /* Per standard convention, codes in the range (0, UCHAR_MAX]
- represent single characters with those character codes. */
-
- CHAR_TOKEN_OFFSET = UCHAR_MAX + 1,
- GTY_TOKEN = CHAR_TOKEN_OFFSET,
- TYPEDEF,
- EXTERN,
- STATIC,
- UNION,
- STRUCT,
- ENUM,
- VEC_TOKEN,
- ELLIPSIS,
- PTR_ALIAS,
- NESTED_PTR,
- USER_GTY,
- PARAM_IS,
- NUM,
- SCALAR,
- ID,
- STRING,
- CHAR,
- ARRAY,
-
- /* print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have
- a meaningful value to be printed. */
- FIRST_TOKEN_WITH_VALUE = PARAM_IS
- };
+enum gty_token
+{
+ EOF_TOKEN = 0,
+
+ /* Per standard convention, codes in the range (0, UCHAR_MAX]
+ represent single characters with those character codes. */
+ CHAR_TOKEN_OFFSET = UCHAR_MAX + 1,
+ GTY_TOKEN = CHAR_TOKEN_OFFSET,
+ TYPEDEF,
+ EXTERN,
+ STATIC,
+ UNION,
+ STRUCT,
+ ENUM,
+ VEC_TOKEN,
+ ELLIPSIS,
+ PTR_ALIAS,
+ NESTED_PTR,
+ USER_GTY,
+ PARAM_IS,
+ NUM,
+ SCALAR,
+ ID,
+ STRING,
+ CHAR,
+ ARRAY,
+ IGNORABLE_CXX_KEYWORD,
+
+ /* print_token assumes that any token >= FIRST_TOKEN_WITH_VALUE may have
+ a meaningful value to be printed. */
+ FIRST_TOKEN_WITH_VALUE = PARAM_IS
+};
/* Level for verbose messages, e.g. output file generation... */