Handling of unknown pragmas and cached lexing mode

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Handling of unknown pragmas and cached lexing mode

David Blaikie via cfe-dev
Hi @list,

I refer to the source code version at https://github.com/llvm-mirror/clang,
function Preprocessor::HandlePragmaDirective at Lex/Pragma.cpp:127.

I've installed a pragma callback via Preprocessor::addPPCallbacks. The callback
function just stores the text of the pragma line. For this I use Preprocessor::Lex
and Preprocessor::getSpelling, which works fine.
Since the pragma line has to be handled normally afterwards, I start in my callback with
Preprocessor::EnableBacktrackAtThisPos and call Preprocessor::Backtrack before returning.
This works as long as the pragma is known and somehow parsed and handled at line 139.
If it is not handled there, then the parser has to move to Tok::eod, which is actually achieved at line 144.
However this doesn't work in my case, since EnableBacktrackAtThisPos enters the caching mode, but
Backtrack doesn't leave it. Then CurPPLexer is 0 and the next pragma token is lexed as part of the
program (and compilation will normally fail).
I guess that's a bug.

I've tried LookAhead instead of Lex and backtracking, but this fails too for the same reason. Now I am
 out of ideas how to work around this bug.
Has anyone a hint?


Thanks in advance
Olaf

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev