aboutsummaryrefslogtreecommitdiff
path: root/gcc/gengtype.c
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.c
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.c')
-rw-r--r--gcc/gengtype.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/gcc/gengtype.c b/gcc/gengtype.c
index 213567653fe..b9fbd96fcbf 100644
--- a/gcc/gengtype.c
+++ b/gcc/gengtype.c
@@ -497,10 +497,10 @@ struct type scalar_char = {
/* Lists of various things. */
-pair_p typedefs;
-type_p structures;
-type_p param_structs;
-pair_p variables;
+pair_p typedefs = NULL;
+type_p structures = NULL;
+type_p param_structs = NULL;
+pair_p variables = NULL;
static type_p find_param_structure (type_p t, type_p param[NUM_PARAM]);
static type_p adjust_field_tree_exp (type_p t, options_p opt);
@@ -611,6 +611,7 @@ resolve_typedef (const char *s, struct fileloc *pos)
return create_user_defined_type (s, pos);
}
+
/* Create and return a new structure with tag NAME at POS with fields
FIELDS and options O. The KIND of structure must be one of
TYPE_STRUCT, TYPE_UNION or TYPE_USER_STRUCT. */
@@ -676,8 +677,7 @@ new_structure (const char *name, enum typekind kind, struct fileloc *pos,
structures = s;
}
- if (s->u.s.line.file != NULL
- || (s->u.s.lang_struct && (s->u.s.lang_struct->u.s.bitmap & bitmap)))
+ if (s->u.s.lang_struct && (s->u.s.lang_struct->u.s.bitmap & bitmap))
{
error_at_line (pos, "duplicate definition of '%s %s'",
isunion ? "union" : "struct", s->u.s.tag);
@@ -763,6 +763,7 @@ create_scalar_type (const char *name)
return &scalar_nonchar;
}
+
/* Return a pointer to T. */
type_p
@@ -2636,7 +2637,7 @@ walk_type (type_p t, struct walk_type_data *d)
/* If a pointer type is marked as "atomic", we process the
field itself, but we don't walk the data that they point to.
-
+
There are two main cases where we walk types: to mark
pointers that are reachable, and to relocate pointers when
writing a PCH file. In both cases, an atomic pointer is
@@ -3514,7 +3515,7 @@ write_func_for_structure (type_p orig_s, type_p s, type_p *param,
{
oprintf (d.of, " %s (x);\n", mark_hook_name);
}
-
+
d.prev_val[2] = "*x";
d.indent = 6;
if (orig_s->kind != TYPE_USER_STRUCT)