[cfe-dev] Returning original parsing state after parsing arbitrary tokens
Vassil Vassilev
vasil.georgiev.vasilev at cern.ch
Thu Oct 25 07:43:21 PDT 2012
Hi,
On 10/23/2012 12:02 PM, Eli Friedman wrote:
> On Tue, Oct 23, 2012 at 2:44 AM, ja_comp <ja_comp at yahoo.com> wrote:
>> Assume that a program did the following:
>>
>> 1) Called EnterTokenStream with arbitrary tokens (followed by a Semicolon
>> and Eof)
>> 2) Called setSuppressAllDiagnostics(true) to keep from emitting errors (in
>> case the next step fails)
>> 3) Called ParseStatement to produce a StmtResult from the additional tokens
>> (which may or may not produce a valid result)
>> 4) Lexed tokens (if necessary) to remove any unlexed added tokens
>> 5) Called setSuppressAllDiagnostics(false) to restore error handling
>>
>> What variables and/or other states should be saved to return the
>> Preprocessor/Parser/Lexer to the state they were in before step 1?
> It's impossible to completely save/restore the state of semantic
> analysis short of using fork() or equivalent. You might be able to
> get away with an approximation depending on your exact requirements,
> though.
>
> At a higher level, what are you trying to do?
That use case is particularly interesting to us, too. We want to be able
to support discovery at run-time of dependent library and their
automatic loading.
We want to be able to load a library + parse its headers on a failed
lookup and then retry the lookup, which will now succeed, and continue
the original parsing. This requires to save the current state of the
parser (and/or sema?) just after the 'failed' lookup, then do the
#include of the headers and finally restore to the previous.
Vassil
>
> -Eli
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list