Patch to eliminate DECL_FIELD_SIZE

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Tue Feb 29 09:16:00 GMT 2000


 > From: kenner@vlsi1.ultra.nyu.edu (Richard Kenner)
 > 
 >     IMHO, the design here worries me since it looks easy for the string
 >     names in builtins.c and the "enum built_in_function" in tree.h to get
 >     out of sync.  Perhaps something like how the *.def files are handled
 >     would be better?
 > 
 > I was indeed concerned about that, and thought about putting comments
 > in both places to warn about it, which I forgot to do.  I think
 > something like the *.def files might be a bit "heavy" unless we also
 > use them for something else.  I was looking at the code in c-decl.c
 > and c-common.c and that's a candidate for that, but then we'd have to
 > put the function types in the *.def file and I'm not sure if that's
 > worth doing.  Plus, they are split between c-common.c and c-decl.c and
 > I don't know offhand if there's a real reason for that, but it would
 > make such a thing harder.
 > 
 > Your further thoughts?

The problem I have with comments asking someone to coordinate the two
places is that it relies on human vigilance, which is sporadic.  Even
if the gcc programmer is vigilant, it also relies on error prone
visual inspection of the two places.  Its easy to have a missing entry
and then all the strings following that entry are off by one.

I see your point about .def files being "heavy", especially for
`built_in_class_names' which only has four elements.  But I don't know
if I'd consider `built_in_names' in that category.

So anyway, another approach might be to use the enums themselves to
index the initialization of the string array.  E.g.

 > built_in_names[BUILT_IN_ALLOCA] = "BUILT_IN_ALLOCA";
 > [...]

Then at least we'd have no _mismatches_ because the visual inspection
has a clearly better chance to work.  We'd still have to ensure no
_missing_ entries.  We can do that like this:

 > const char *const built_in_class_names[4];
 > 
 > init_built_in_class_names()
 > {
 >   int i;
 > 
 >   bzero(built_in_class_names,
 >     sizeof (built_in_class_names[0]) * sizeof built_in_class_names);
 > 
 >   built_in_class_names[NOT_BUILT_IN] = "NOT_BUILT_IN";
 >   built_in_class_names[BUILT_IN_FRONTEND] = "BUILT_IN_FRONTEND";
 >   built_in_class_names[BUILT_IN_MD] = "BUILT_IN_MD";
 >   built_in_class_names[BUILT_IN_NORMAL] = "BUILT_IN_NORMAL";
 > 
 >   /* Ensure all names got an entry.  */
 >   for (i=0; i<4; i++)
 >     if (built_in_class_names[i] == 0)
 >       abort();
 > }

And do the same for `built_in_names' too.


You might want to define a macro which does this:

 > #define SET_BUILT_IN_CLASS_NAME(x) built_in_class_names[x] = STRINGIFY(x)
 > SET_BUILT_IN_CLASS_NAME(NOT_BUILT_IN);
 > SET_BUILT_IN_CLASS_NAME(BUILT_IN_FRONTEND);
 > [...]

		--Kaveh
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions


More information about the Gcc-patches mailing list