[cfe-commits] r59636 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Parse/Parser.cpp test/SemaCXX/nested-name-spec.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Wed Nov 19 07:22:21 PST 2008
Author: akirtzidis
Date: Wed Nov 19 09:22:16 2008
New Revision: 59636
URL: http://llvm.org/viewvc/llvm-project?rev=59636&view=rev
Log:
Fix this:
With this snippet:
void f(a::b);
An assert is hit:
Assertion failed: CachedTokens[CachedLexPos-1].getLocation() == Tok.getAnnotationEndLoc() && "The annotation should be until the most recent cached token", file ..\..\lib\Lex\PPCaching.cpp, line 98
Introduce Preprocessor::RevertCachedTokens that reverts a specific number of tokens when backtracking is enabled.
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/SemaCXX/nested-name-spec.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=59636&r1=59635&r2=59636&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Nov 19 09:22:16 2008
@@ -369,6 +369,20 @@
return PeekAhead(N+1);
}
+ /// RevertCachedTokens - When backtracking is enabled and tokens are cached,
+ /// this allows to revert a specific number of tokens.
+ /// Note that the number of tokens being reverted should be up to the last
+ /// backtrack position, not more.
+ void RevertCachedTokens(unsigned N) {
+ assert(isBacktrackEnabled() &&
+ "Should only be called when tokens are cached for backtracking");
+ assert(signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back())
+ && "Should revert tokens up to the last backtrack position, not more");
+ assert(signed(CachedLexPos) - signed(N) >= 0 &&
+ "Corrupted backtrack positions ?");
+ CachedLexPos -= N;
+ }
+
/// EnterToken - Enters a token in the token stream to be lexed next. If
/// BackTrack() is called afterwards, the token will remain at the insertion
/// point.
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=59636&r1=59635&r2=59636&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed Nov 19 09:22:16 2008
@@ -731,9 +731,12 @@
if (SS.isNotEmpty()) {
// A C++ scope specifier that isn't followed by a typename.
- // Push the current token back into the token stream and use an annotation
- // scope token for current token.
- PP.EnterToken(Tok);
+ // Push the current token back into the token stream (or revert it if it is
+ // cached) and use an annotation scope token for current token.
+ if (PP.isBacktrackEnabled())
+ PP.RevertCachedTokens(1);
+ else
+ PP.EnterToken(Tok);
Tok.setKind(tok::annot_cxxscope);
Tok.setAnnotationValue(SS.getScopeRep());
Tok.setAnnotationRange(SS.getRange());
@@ -754,9 +757,12 @@
CXXScopeSpec SS;
ParseCXXScopeSpecifier(SS);
- // Push the current token back into the token stream and use an annotation
- // scope token for current token.
- PP.EnterToken(Tok);
+ // Push the current token back into the token stream (or revert it if it is
+ // cached) and use an annotation scope token for current token.
+ if (PP.isBacktrackEnabled())
+ PP.RevertCachedTokens(1);
+ else
+ PP.EnterToken(Tok);
Tok.setKind(tok::annot_cxxscope);
Tok.setAnnotationValue(SS.getScopeRep());
Tok.setAnnotationRange(SS.getRange());
Modified: cfe/trunk/test/SemaCXX/nested-name-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec.cpp?rev=59636&r1=59635&r2=59636&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/nested-name-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/nested-name-spec.cpp Wed Nov 19 09:22:16 2008
@@ -63,3 +63,6 @@
{ typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}}
{ typedef A::C A; A::cx = 0; }
}
+
+// make sure the following doesn't hit any asserts
+void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} // expected-error {{expected ')'}} expected-error {{to match this '('}} // expected-error {{variable has incomplete type 'void'}}
More information about the cfe-commits
mailing list