]> granicus.if.org Git - clang/commitdiff
TryAnnotateTypeOrScopeToken and TryAnnotateCXXScopeToken can
authorChris Lattner <sabre@nondot.org>
Mon, 5 Jan 2009 01:24:05 +0000 (01:24 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 5 Jan 2009 01:24:05 +0000 (01:24 +0000)
only be called when they might be needed now, so make them assert
that their current token is :: or identifier.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61662 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
lib/Parse/ParseExprCXX.cpp
lib/Parse/ParseTemplate.cpp
lib/Parse/Parser.cpp

index 8770bc286419b60b0fba0c5ad77e703276051781..80e25ee6cb6f865b32c67dc38d0d2b4e35b51dc8 100644 (file)
@@ -637,7 +637,8 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
       return ParseCXXDeleteExpression(true, ColonColonTok.getLocation());
     // Turn the qualified name into a annot_qualtypename or annot_cxxscope if
     // it would be valid.
-    if (TryAnnotateTypeOrScopeToken(&ColonColonTok)) {
+    if ((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
+        TryAnnotateTypeOrScopeToken(&ColonColonTok)) {
       // If so, retry (tail recurse).
       return ParseCastExpression(isUnaryExpression);
     }
index f9514352ee71de91a295ff995979d3ffb50d2c85..a4b97e173be49c1cca69520103cba527c1013765 100644 (file)
@@ -35,7 +35,7 @@ using namespace clang;
 bool Parser::MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS,
                                          const Token *GlobalQualifier) {
   assert(getLang().CPlusPlus &&
-         "Call sites of this function should be guarded by checking for C++.");
+         "Call sites of this function should be guarded by checking for C++");
 
   if (Tok.is(tok::annot_cxxscope)) {
     assert(GlobalQualifier == 0 &&
@@ -183,13 +183,13 @@ Parser::OwningExprResult Parser::ParseCXXIdExpression() {
 
   case tok::kw_operator: {
     SourceLocation OperatorLoc = Tok.getLocation();
-    if (OverloadedOperatorKind Op = TryParseOperatorFunctionId()) {
+    if (OverloadedOperatorKind Op = TryParseOperatorFunctionId())
       return Owned(Actions.ActOnCXXOperatorFunctionIdExpr(
                          CurScope, OperatorLoc, Op, Tok.is(tok::l_paren), SS));
-    } else if (TypeTy *Type = ParseConversionFunctionId()) {
-      return Owned(Actions.ActOnCXXConversionFunctionExpr(
-                         CurScope, OperatorLoc, Type, Tok.is(tok::l_paren),SS));
-    }
+    if (TypeTy *Type = ParseConversionFunctionId())
+      return Owned(Actions.ActOnCXXConversionFunctionExpr(CurScope, OperatorLoc,
+                                                          Type,
+                                                     Tok.is(tok::l_paren), SS));
 
     // We already complained about a bad conversion-function-id,
     // above.
index 076aae38cc3a2c2d0af8830d961aa10d799012ff..f21854dc1e3a4274147be2d6558205f334bbf912 100644 (file)
@@ -318,7 +318,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
   // Parse this as a typename.
   Declarator ParamDecl(DS, Declarator::TemplateParamContext);
   ParseDeclarator(ParamDecl);
-  if(DS.getTypeSpecType() == DeclSpec::TST_unspecified && !DS.getTypeRep()) {
+  if (DS.getTypeSpecType() == DeclSpec::TST_unspecified && !DS.getTypeRep()) {
     // This probably shouldn't happen - and it's more of a Sema thing, but
     // basically we didn't parse the type name because we couldn't associate
     // it with an AST node. we should just skip to the comma or greater.
@@ -335,7 +335,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
   // Is there a default value? Parsing this can be fairly annoying because
   // we have to stop on the first non-nested (paren'd) '>' as the closure
   // for the template parameter list. Or a ','.
-  if(Tok.is(tok::equal)) {
+  if (Tok.is(tok::equal)) {
     // TODO: Implement default non-type values.
     SkipUntil(tok::comma, tok::greater, true, true);
   }
index 02ddb6823fb26e3b7c73070d23484965a6d8261d..16f0837240763ccce32c465917ca91b0ab47c402 100644 (file)
@@ -747,10 +747,10 @@ Parser::OwningExprResult Parser::ParseSimpleAsm() {
 /// Note that this routine emits an error if you call it with ::new or ::delete
 /// as the current tokens, so only call it in contexts where these are invalid.
 bool Parser::TryAnnotateTypeOrScopeToken(const Token *GlobalQualifier) {
-  // FIXME: what about template-ids?
-  if (Tok.is(tok::annot_qualtypename) || Tok.is(tok::annot_cxxscope))
-    return false;
-
+  assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
+         "Cannot be a type or scope token!");
+  
+  // FIXME: Implement template-ids
   CXXScopeSpec SS;
   if (getLang().CPlusPlus)
     MaybeParseCXXScopeSpecifier(SS, GlobalQualifier);
@@ -818,9 +818,8 @@ bool Parser::TryAnnotateTypeOrScopeToken(const Token *GlobalQualifier) {
 bool Parser::TryAnnotateCXXScopeToken() {
   assert(getLang().CPlusPlus &&
          "Call sites of this function should be guarded by checking for C++");
-
-  if (Tok.is(tok::annot_cxxscope))
-    return false;
+  assert((Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
+         "Cannot be a type or scope token!");
 
   CXXScopeSpec SS;
   if (!MaybeParseCXXScopeSpecifier(SS))