[cfe-dev] Weird behavior while parsing nested (and non) pragmas
Sebastian Redl
sebastian.redl at getdesigned.at
Wed Aug 25 13:47:59 PDT 2010
On Aug 25, 2010, at 12:26 PM, Simone Pellegrini wrote:
> On 08/25/2010 07:59 PM, Sebastian Redl wrote:
>> On Aug 25, 2010, at 8:47 AM, Simone Pellegrini wrote:
>>
>>
>>> I have to say,
>>> to be complete, that in order to parse the pragmas I manually call the
>>> ConsumeToken() of the Parser class, could be this the problem?
>>>
>> Yes. ConsumeToken returns the SourceLocation of the token just consumed. Now, ParseCompoundStatement asserts that the current token is an opening brace and then calls ParseCompoundStatementBody. PCSB doesn't contain an assert. It simply assumes that the first token is the opening brace and consumes it, storing the returned source location, which is then passed to ActOnCompoundStatement as the location of the lbrace.
>>
>>
> I see.
>> Now, if you do your own thing there, consume the lbrace, and leave some other random token in the stream for PCSB to consume, obviously the source location you get would be that of that random thing.
>>
> Ok, I understand, but how can I insert a token in the token stream?
You could just manipulate Tok as stored in Parser, but it would be better IMO to just capture the source location yourself and pass it on.
After reading the existing code more carefully, I still don't understand how you got to where you are without tripping over an assertion.
Sebastian
More information about the cfe-dev
mailing list