[cfe-commits] r110436 - in /cfe/trunk: include/clang/Basic/TokenKinds.def lib/Parse/ParseCXXInlineMethods.cpp lib/Parse/ParseDecl.cpp test/Parser/cxx-default-args.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Aug 6 02:47:24 PDT 2010
Author: akirtzidis
Date: Fri Aug 6 04:47:24 2010
New Revision: 110436
URL: http://llvm.org/viewvc/llvm-project?rev=110436&view=rev
Log:
Introduce a new token kind 'cxx_defaultarg_end' to mark the end of C++ default arguments that were part of
lexed method declarations.
This avoid interference with tokens coming after the point where the default arg tokens were 'injected', e.g. for
typedef struct Inst {
void m(int x=0);
} *InstPtr;
when parsing '0' the next token would be '*' and things would be messed up.
Modified:
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/Parser/cxx-default-args.cpp
Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=110436&r1=110435&r2=110436&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Fri Aug 6 04:47:24 2010
@@ -96,6 +96,7 @@
TOK(eof) // End of file.
TOK(eom) // End of macro (end of line inside a macro).
TOK(code_completion) // Code completion marker
+TOK(cxx_defaultarg_end) // C++ default argument end marker
// C99 6.4.9: Comments.
TOK(comment) // Comment (only in -E -C[C] mode)
Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=110436&r1=110435&r2=110436&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Fri Aug 6 04:47:24 2010
@@ -142,9 +142,13 @@
OwningExprResult DefArgResult(ParseAssignmentExpression());
if (DefArgResult.isInvalid())
Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param);
- else
+ else {
+ assert(Tok.is(tok::cxx_defaultarg_end) &&
+ "We didn't parse the whole default arg!");
+ ConsumeToken(); // Consume tok::cxx_defaultarg_end.
Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc,
move(DefArgResult));
+ }
assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
Tok.getLocation()) &&
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=110436&r1=110435&r2=110436&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Aug 6 04:47:24 2010
@@ -3085,9 +3085,17 @@
delete DefArgToks;
DefArgToks = 0;
Actions.ActOnParamDefaultArgumentError(Param);
- } else
+ } else {
+ // Mark the end of the default argument so that we know when to
+ // stop when we parse it later on.
+ Token DefArgEnd;
+ DefArgEnd.startToken();
+ DefArgEnd.setKind(tok::cxx_defaultarg_end);
+ DefArgEnd.setLocation(Tok.getLocation());
+ DefArgToks->push_back(DefArgEnd);
Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
(*DefArgToks)[1].getLocation());
+ }
} else {
// Consume the '='.
ConsumeToken();
Modified: cfe/trunk/test/Parser/cxx-default-args.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-default-args.cpp?rev=110436&r1=110435&r2=110436&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-default-args.cpp (original)
+++ cfe/trunk/test/Parser/cxx-default-args.cpp Fri Aug 6 04:47:24 2010
@@ -7,3 +7,6 @@
void m(int x = undecl + 0); // expected-error {{use of undeclared identifier 'undecl'}}
};
+typedef struct Inst {
+ void m(int x=0);
+} *InstPtr;
More information about the cfe-commits
mailing list