]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/gengtype.h
Add more C++ support in gengtype.
authorDiego Novillo <dnovillo@gcc.gnu.org>
Fri, 12 Oct 2012 15:17:17 +0000 (11:17 -0400)
committerDiego Novillo <dnovillo@gcc.gnu.org>
Fri, 12 Oct 2012 15:17:17 +0000 (11:17 -0400)
commit313465bbbd04019184339161f0e30a46a5c0e4ab
tree3f1c4b6afbebcb24454c2dce4ca0c8c5934987c0
parentb09e6a7074c0ff5ee74dd0735d5fb10ac450976a
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.

From-SVN: r192405
gcc/ChangeLog
gcc/doc/gty.texi
gcc/gengtype-lex.l
gcc/gengtype-parse.c
gcc/gengtype-state.c
gcc/gengtype.c
gcc/gengtype.h