diff options
author | Chris Lattner <sabre@nondot.org> | 2009-12-10 00:32:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-12-10 00:32:41 +0000 |
commit | d5c1c9d0aee99246a68fd48131f97245efc0c104 (patch) | |
tree | 07685be314ee8e5694570224425ba79f6f331cdd | |
parent | 633c6f6f368634648318c4da6e1a123be3d46690 (diff) | |
download | bcm5719-llvm-d5c1c9d0aee99246a68fd48131f97245efc0c104.tar.gz bcm5719-llvm-d5c1c9d0aee99246a68fd48131f97245efc0c104.zip |
refactor the 'ColonIsSacred' argument to ParseOptionalCXXScopeSpecifier
to be a bool in Parser that is twiddled by the ColonProtectionRAIIObject
class. No functionality change.
llvm-svn: 91014
-rw-r--r-- | clang/include/clang/Parse/Parser.h | 11 | ||||
-rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Parse/ParseExprCXX.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Parse/RAIIObjectsForParser.h | 21 |
5 files changed, 40 insertions, 13 deletions
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index c6dad07aaa6..1b2c32cddb1 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -30,6 +30,7 @@ namespace clang { class DiagnosticBuilder; class Parser; class PragmaUnusedHandler; + class ColonProtectionRAIIObject; /// PrettyStackTraceParserEntry - If a crash happens while the parser is active, /// an entry is printed for it. @@ -47,6 +48,7 @@ public: /// class Parser { friend class PragmaUnusedHandler; + friend class ColonProtectionRAIIObject; PrettyStackTraceParserEntry CrashInfo; Preprocessor &PP; @@ -90,6 +92,12 @@ class Parser { /// template argument list, where the '>' closes the template /// argument list. bool GreaterThanIsOperator; + + /// ColonIsSacred - When this is false, we aggressively try to recover from + /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not + /// safe in case statements and a few other things. This is managed by the + /// ColonProtectionRAIIObject RAII object. + bool ColonIsSacred; /// The "depth" of the template parameters currently being parsed. unsigned TemplateParameterDepth; @@ -890,8 +898,7 @@ private: bool ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, TypeTy *ObjectType, - bool EnteringContext, - bool ColonIsSacred = false); + bool EnteringContext); //===--------------------------------------------------------------------===// // C++ 5.2p1: C++ Casts diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index f96b3c7cb22..d9c8d7da76f 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -601,10 +601,14 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Parse the (optional) nested-name-specifier. CXXScopeSpec SS; - if (getLang().CPlusPlus && - ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, true, true)) - if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) - Diag(Tok, diag::err_expected_ident); + if (getLang().CPlusPlus) { + // "FOO : BAR" is not a potential typo for "FOO::BAR". + ColonProtectionRAIIObject X(*this); + + if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, true)) + if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) + Diag(Tok, diag::err_expected_ident); + } TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index ae2a47befd4..abd26d7d490 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -45,14 +45,10 @@ using namespace clang; /// \param EnteringContext whether we will be entering into the context of /// the nested-name-specifier after parsing it. /// -/// \param ColonIsSacred - If this is true, then a colon is valid after the -/// specifier, so we should not try to recover from colons aggressively. -/// /// \returns true if a scope specifier was parsed. bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, Action::TypeTy *ObjectType, - bool EnteringContext, - bool ColonIsSacred) { + bool EnteringContext) { assert(getLang().CPlusPlus && "Call sites of this function should be guarded by checking for C++"); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index a29d4993dd5..a864e7c24cb 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -36,7 +36,8 @@ public: Parser::Parser(Preprocessor &pp, Action &actions) : CrashInfo(*this), PP(pp), Actions(actions), Diags(PP.getDiagnostics()), - GreaterThanIsOperator(true), TemplateParameterDepth(0) { + GreaterThanIsOperator(true), ColonIsSacred(false), + TemplateParameterDepth(0) { Tok.setKind(tok::eof); CurScope = 0; NumCachedScopes = 0; diff --git a/clang/lib/Parse/RAIIObjectsForParser.h b/clang/lib/Parse/RAIIObjectsForParser.h index d642da58d50..d18d2f80263 100644 --- a/clang/lib/Parse/RAIIObjectsForParser.h +++ b/clang/lib/Parse/RAIIObjectsForParser.h @@ -36,6 +36,25 @@ namespace clang { Diags.DecrementAllExtensionsSilenced(); } }; -} + + // TODO: move GreaterThanIsOperatorScope here. + + /// ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and + /// restores it when destroyed. This says that "foo:" should not be + /// considered a possible typo for "foo::" for error recovery purposes. + class ColonProtectionRAIIObject { + Parser &P; + bool OldVal; + public: + ColonProtectionRAIIObject(Parser &p) : P(p), OldVal(P.ColonIsSacred) { + P.ColonIsSacred = true; + } + + ~ColonProtectionRAIIObject() { + P.ColonIsSacred = OldVal; + } + }; + +} // end namespace clang #endif |