[cfe-dev] Weird behavior while parsing nested (and non) pragmas
Simone Pellegrini
spellegrini at dps.uibk.ac.at
Thu Aug 26 06:45:32 PDT 2010
On 08/25/2010 10:47 PM, Sebastian Redl wrote:
> 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.
>
>
I actually managed to solve the problem by overwriting the
SourceLocation of the left bracket passed to the ActOnCompoundStmt()
function. This works for me but it is just a workaround of a strange
behavior which to me looks like a bug in the clang parser.
cheers, Simone
> Sebastian
More information about the cfe-dev
mailing list