Subject: Removing the arg_index field from cpp_hashnode

Neil Booth neil@daikokuya.co.uk
Thu Nov 7 00:33:00 GMT 2002


Per Bothner wrote:-

> I suggest we start out by getting rid of the arg_index field of
> cpp_hashnode, which is embedded in all IDENTIFIER_NODE for C/C++/ObjC.
> Getting rid of arg_index directly saves 16 bits; on 32-bit machines it
> saves a whole 4 bytes due to alignment.

I like the idea.
 
> A simple replacement is to add a new flag:
> #define NODE_MACROARG   (1 << 6)  /* Parameter in current macro def. */
> When a macro parameter is seen, the NODE_MACROARG bit is set in the
> flags field of the cpp_hashnode.  The bit is cleared at the end of the
> macro definition, just as we currently clear arg_index.  Testing for
> duplicate parameter names is trivial:  Just check the bit.
> 
> Harder is modifying lex_expansion_token, when we need to set the
> arg_no of the CPP_MACROARG token.  An easy fix is to search the
> argument list linearly looking for a match.  This causes O(M*N)
> behavior, when M is the number of parameters, and N is the number
> of references in the macro definition.  In practice both are likely
> to be small, but on general principles we to avoid quadratic
> algorithms.  And it is easy to avoid it.

I'm not sure it's worth the code complexity of trying to avoid
the O(M*N).  On average it's only M*N/2 comparisons, since matches are
guaranteed, and as you said M and N are normally small.

Does your suggestion handle C++'s alternative tokens in the expansion of
#define correctly, by still recording their special status?

Neil.



More information about the Gcc mailing list