[PATCH] New pragma handling mechanism
Mark Mitchell
mark@codesourcery.com
Fri Apr 8 23:52:00 GMT 2005
Zack Weinberg wrote:
> Richard Henderson <rth@redhat.com> writes:
>
>
>>On Fri, Apr 08, 2005 at 04:18:41PM -0700, Zack Weinberg wrote:
>>
>>>The theory is, the recursive descent parser encounters the CPP_PRAGMA
>>>token and calls the function pointer embedded therein, which points to
>>>a handler function just like the functions we have now. For OMP
>>>pragmas, that handler function can call back into the expression
>>>parser (for instance). Is this what you mean by 'normal recursive
>>>descent parsing'?
>>
>>Well, yes and no. Ok, say we've called some function to parse the
>>pragma. What's going to happen when we get to the CPP_EOF token
>>that marks the end of the pragma? Am I going to get no more tokens,
>>or can parsing continue?
>
>
> Currently you get an infinite stream of CPP_EOF tokens until the
> handler returns, which is IMO a valuable safety feature for most
> target pragmas, but we could introduce a mechanism to bypass it for
> pragmas, like these, that know what they are doing. So, given your example
>
I'd prefer we steal a concept used in other (non-GCC) front ends, as an
orthogonal issue to what goes in the token stream.
In particular, for each #pragma, have an "association".
A #pragma with no association is processed at the time it is seen. That
would apply to things like #pragma weak, or most of the other #pragmas
we have no. Examples of an associations would be "next-statement",
"next-declaration", etc.
When a #pragma with a next-statement association is processed, you parse
the #pragma itself, and save a representation of the #pragma, as a
"struct pragma *":
struct pragma {
enum pragma_kind kind;
};
struct foo_pragma {
struct pragma base;
... more stuff ...
};
Then, in the parser, before/after processing things (like statements),
you ask for any applicable #pragmas, as a pile of "struct pragma *"
thingies, and process them appropriately.
The advantage of this is that it avoids the #pragma stuff having to know
about the rest of parsing. For example, it avoids the problem that you
may want to do things differently in C vs. C++ vs. Fortran, but use the
same #pragma parsing routine. It also allows you to just hang the
"struct pragma *" on stuff, and pass it off to the middle-end to deal
with later.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
More information about the Gcc-patches
mailing list