[cfe-commits] r55204 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Lex/PPCaching.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Sun Aug 24 08:11:53 PDT 2008


Chris Lattner wrote:
>>   ///
>>   /// NOTE: *DO NOT* forget to call either DisableBacktrack() or 
>> Backtrack() at
>>   /// some point after EnableBacktrackAtThisPos. If you don't, 
>> caching of tokens
>>   /// will continue indefinitely.
>>   ///
>
> With your new assert, I think that PP will abort if the backtrack 
> isn't either reverted or committed.  Is this true?

Yes.

>
> What do you think about using RAII to manage backtracking?  This would 
> allow us to write code like this:
>
> {
> BacktrackObj BT(PP);  // starts backtracking
> .. do something speculative..
>
> if (happy) {
>   BT.commit();
> } else {
>   BR.revert();
>   ... try something else ...
> }
> }
>
> The nice thing about this is that it a) might make the code simpler, 
> and b) the RAII object could immediately abort if it is destroyed 
> without either commit or revert being called on it.

Great idea! I use it in the new "disambiguation" patch.

>
>> +/// DisableBacktrack - Disable the last EnableBacktrackAtThisPos() 
>> call.
>> +void Preprocessor::DisableBacktrack() {
>
> How about using the name: "CommitBacktrackedTokens()".  "Disable" 
> makes it sound like the speculative parse failed or something.

Done:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080818/007180.html


-Argiris



More information about the cfe-commits mailing list