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

Chris Lattner clattner at apple.com
Sat Aug 23 17:16:30 PDT 2008


On Aug 22, 2008, at 2:27 PM, Argiris Kirtzidis wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=55204&view=rev
> Log:
> Allow nested backtracks.

Woo, very nice.

>   ///
>   /// 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?

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.

> +/// 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.

-Chris



More information about the cfe-commits mailing list