[cfe-commits] r64166 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp lib/Parse/ParseTemplate.cpp
Douglas Gregor
dgregor at apple.com
Mon Feb 9 13:04:56 PST 2009
Author: dgregor
Date: Mon Feb 9 15:04:56 2009
New Revision: 64166
URL: http://llvm.org/viewvc/llvm-project?rev=64166&view=rev
Log:
Implement Sebastian's idea for simplifying our handling of the greater-than operator/delimiter. Also, clean up after ourselves following a failed parse of a template-argument-list
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=64166&r1=64165&r2=64166&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Feb 9 15:04:56 2009
@@ -64,34 +64,18 @@
/// argument list.
bool GreaterThanIsOperator;
- /// \brief RAII object that makes '>' behave like the closing angle
- /// bracket for a template argument list.
- struct MakeGreaterThanTemplateArgumentListTerminator {
+ /// \brief RAII object that makes '>' behave either as an operator
+ /// or as the closing angle bracket for a template argument list.
+ struct GreaterThanIsOperatorScope {
bool &GreaterThanIsOperator;
bool OldGreaterThanIsOperator;
- MakeGreaterThanTemplateArgumentListTerminator(bool >IO)
+ GreaterThanIsOperatorScope(bool >IO, bool Val)
: GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
- GTIO = false;
+ GreaterThanIsOperator = Val;
}
- ~MakeGreaterThanTemplateArgumentListTerminator() {
- GreaterThanIsOperator = OldGreaterThanIsOperator;
- }
- };
-
- /// \brief RAII object that makes '>' behave like an
- /// operator. Occurs, for example, inside parentheses.
- struct MakeGreaterThanAnOperator {
- bool &GreaterThanIsOperator;
- bool OldGreaterThanIsOperator;
-
- MakeGreaterThanAnOperator(bool >IO)
- : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
- GTIO = true;
- }
-
- ~MakeGreaterThanAnOperator() {
+ ~GreaterThanIsOperatorScope() {
GreaterThanIsOperator = OldGreaterThanIsOperator;
}
};
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=64166&r1=64165&r2=64166&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Feb 9 15:04:56 2009
@@ -1112,7 +1112,7 @@
Parser::ParseParenExpression(ParenParseOption &ExprType,
TypeTy *&CastTy, SourceLocation &RParenLoc) {
assert(Tok.is(tok::l_paren) && "Not a paren expr!");
- MakeGreaterThanAnOperator G(GreaterThanIsOperator);
+ GreaterThanIsOperatorScope G(GreaterThanIsOperator, true);
SourceLocation OpenLoc = ConsumeParen();
OwningExprResult Result(Actions, true);
CastTy = 0;
Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=64166&r1=64165&r2=64166&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Mon Feb 9 15:04:56 2009
@@ -371,13 +371,17 @@
TemplateArgList TemplateArgs;
TemplateArgIsTypeList TemplateArgIsType;
{
- MakeGreaterThanTemplateArgumentListTerminator G(GreaterThanIsOperator);
+ GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
if (Tok.isNot(tok::greater) &&
ParseTemplateArgumentList(TemplateArgs, TemplateArgIsType)) {
// Try to find the closing '>'.
SkipUntil(tok::greater, true, true);
+
+ // Clean up any template arguments that we successfully parsed.
+ ASTTemplateArgsPtr TemplateArgsPtr(Actions, &TemplateArgs[0],
+ &TemplateArgIsType[0],
+ TemplateArgs.size());
- // FIXME: What's our recovery strategy for failed template-argument-lists?
return;
}
}
More information about the cfe-commits
mailing list