On Wed, May 23, 2012 at 9:49 PM, Diego Novillo dnovi...@google.com wrote:
Part 2 of the VEC C++ conversion. This patch implements the gengtype
changes.
I extended gengtype to understand templated types. These changes are
not as ugly as I thought they would be. Gengtype has some hardwired
knowledge of VEC_*, which I renamed to vec_t. I'm not even sure why
gengtype needs to care about vec_t in this way, but I was looking for
minimal changes, so I just did it.
The other change is more generic. It allows gengtype to deal with
templated types. There is a new function (filter_type_name) that
recognizes C++ special characters '', '' and ':'. It turns them
into '_'. This way, gengtype can generate a valid identifier for the
pre-processor. It only does this in contexts where it needs a
pre-processor identifier. For everything else, it emits the type
directly. So, the functions emitted in gt-*.h files have proper
template type references.
This is, of course, just a replacement of special-case handling for vec.h
with another special-case handling. It does not show us how templated
structs should work with gengtype in general. And no, I don't think
gengtype should keep the special-case for vec.h.
The point was to make all the gt_ggc_* functions function template
specializations so the code gengtype emits for walking a structs fields
would be just
mark (field1);
mark (field2);
...
and we could manually provide specializations for selected types
(well, the templates). Add a GTY((template)) marker to make gengtype
not emit the specializations itself (or simply make it recognize template
types and do nothing for them).
Richard.
2012-05-23 Diego Novillo dnovi...@google.com
* gengtype-lex.l (DEF_VEC_ALLOC_[IOP]/{EOID}): Remove.
* gengtype-parse.c (token_names): Remove DEF_VEC_ALLOC_[IOP].
(typedef_name): Emit vec_tC1 instead of VEC_C1_C2.
(def_vec_alloc): Remove. Update all callers.
* gengtype.c (filter_type_name): New.
(output_mangled_typename): Call it.
(write_func_for_structure): Likewise.
(write_types): Likewise.
(write_root): Likewise.
(write_typed_alloc_def): Likewise.
(note_def_vec): Emit vec_tTYPE_NAME instead of VEC_TYPE_NAME_base.
(note_def_vec_alloc): Remove.
* gengtype.h (note_def_vec_alloc): Remove.
(DEFVEC_ALLOC): Remove token code.
diff --git a/gcc/gengtype-lex.l b/gcc/gengtype-lex.l
index a71cce0..edfd4a1 100644
--- a/gcc/gengtype-lex.l
+++ b/gcc/gengtype-lex.l
@@ -100,10 +100,6 @@ EOID [^[:alnum:]_]
BEGIN(in_struct);
return DEFVEC_I;
}
-^{HWS}DEF_VEC_ALLOC_[IOP]/{EOID} {
- BEGIN(in_struct);
- return DEFVEC_ALLOC;
-}
}
in_struct{
diff --git a/gcc/gengtype-parse.c b/gcc/gengtype-parse.c
index 89f14e8..4fc2b07 100644
--- a/gcc/gengtype-parse.c
+++ b/gcc/gengtype-parse.c
@@ -79,7 +79,6 @@ static const char *const token_names[] = {
VEC,
DEF_VEC_[OP],
DEF_VEC_I,
- DEF_VEC_ALLOC_[IOP],
...,
ptr_alias,
nested_ptr,
@@ -227,7 +226,7 @@ typedef_name (void)
require (',');
c2 = require (ID);
require (')');
- r = concat (VEC_, c1, _, c2, (char *) 0);
+ r = concat (vec_t, c1, , (char *) 0);
free (CONST_CAST (char *, c1));
free (CONST_CAST (char *, c2));
return r;
@@ -916,31 +915,6 @@ def_vec (void)
return;
note_def_vec (type, is_scalar, lexer_line);
- note_def_vec_alloc (type, none, lexer_line);
-}
-
-/* Definition of an allocation strategy for a VEC structure:
-
- 'DEF_VEC_ALLOC_[IPO]' '(' id ',' id ')' ';'
-
- For purposes of gengtype, this just declares a wrapper structure. */
-static void
-def_vec_alloc (void)
-{
- const char *type, *astrat;
-
- require (DEFVEC_ALLOC);
- require ('(');
- type = require2 (ID, SCALAR);
- require (',');
- astrat = require (ID);
- require (')');
- require (';');
-
- if (!type || !astrat)
- return;
-
- note_def_vec_alloc (type, astrat, lexer_line);
}
/* Parse the file FNAME for GC-relevant declarations and definitions.
@@ -972,10 +946,6 @@ parse_file (const char *fname)
def_vec ();
break;
- case DEFVEC_ALLOC:
- def_vec_alloc ();
- break;
-
case EOF_TOKEN:
goto eof;
diff --git a/gcc/gengtype.c b/gcc/gengtype.c
index 814d9e0..82dca36 100644
--- a/gcc/gengtype.c
+++ b/gcc/gengtype.c
@@ -2295,6 +2295,34 @@ struct walk_type_data
int loopcounter;
};
+
+/* Given a string TYPE_NAME, representing a C++ typename, return a valid
+ pre-processor identifier to use in a #define directive. This replaces
+ special characters used in C++ identifiers like '', '' and ':' with
+ '_'.
+
+ If no C++ special characters are found in TYPE_NAME, return
+ TYPE_NAME. Otherwise, return a copy of TYPE_NAME with the special
+ characters replaced with '_'. In this case, the caller is
+