]> granicus.if.org Git - clang/commitdiff
Simplify the parser's handling of Sema::ClassifyName() for types, by
authorDouglas Gregor <dgregor@apple.com>
Wed, 27 Apr 2011 05:41:15 +0000 (05:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 27 Apr 2011 05:41:15 +0000 (05:41 +0000)
creating a type-annotation token rather than jumping into the
declaration parsing.

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

include/clang/Parse/Parser.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseExprCXX.cpp
lib/Parse/ParseStmt.cpp

index 0311c06ece84825b2efc1f7236a5cf4057621fe8..8ed6919208c510738e4d97970edb898da64414e5 100644 (file)
@@ -149,7 +149,7 @@ class Parser : public CodeCompletionHandler {
   /// ColonProtectionRAIIObject RAII object.
   bool ColonIsSacred;
 
-  /// \brief When true, we are directly inside an Ojective-C messsage 
+  /// \brief When true, we are directly inside an Objective-C messsage 
   /// send expression.
   ///
   /// This is managed by the \c InMessageExpressionRAIIObject class, and
index c09a93a84f1dc798a65a6bbb5eb74b4a6e9be75c..a021b84d1577e52f3a32f5398f5f35c4859c6b8d 100644 (file)
@@ -2954,9 +2954,6 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
   case tok::kw_virtual:
   case tok::kw_explicit:
 
-    // typedef-name
-  case tok::annot_typename:
-
     // static_assert-declaration
   case tok::kw__Static_assert:
 
@@ -2971,6 +2968,11 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
   case tok::less:
     return getLang().ObjC1;
 
+    // typedef-name
+  case tok::annot_typename:
+    return !DisambiguatingWithExpression ||
+           !isStartOfObjCClassMessageMissingOpenBracket();
+      
   case tok::kw___declspec:
   case tok::kw___cdecl:
   case tok::kw___stdcall:
index e6abac3b4ce04e2acb4b265235d283b556b34d2d..7bf76a917f23cd181780c3c7b8a55aa212924f4a 100644 (file)
@@ -956,8 +956,7 @@ bool Parser::isCXXSimpleTypeSpecifier() const {
   case tok::kw_char16_t:
   case tok::kw_char32_t:
   case tok::kw_bool:
-    // FIXME: C++0x decltype support.
-  // GNU typeof support.
+  case tok::kw_decltype:
   case tok::kw_typeof:
     return true;
 
index 5138cc159546a34225548cd302ade0d8501cdedb..28be864bdf6181520613d1b75cfaa35d40a1ad65 100644 (file)
@@ -114,7 +114,6 @@ Retry:
     }
     
     if (Next.isNot(tok::coloncolon)) {
-      // FIXME: Temporarily enable this code only for C.
       CXXScopeSpec SS;
       IdentifierInfo *Name = Tok.getIdentifierInfo();
       SourceLocation NameLoc = Tok.getLocation();
@@ -147,63 +146,13 @@ Retry:
         // we're in a syntactic context we haven't handled yet. 
         break;     
           
-      case Sema::NC_Type: {
-        // We have a type. In C, this means that we have a declaration.
-        if (!getLang().CPlusPlus) {
-          ParsedType Type = Classification.getType();
-          const char *PrevSpec = 0;
-          unsigned DiagID;
-          ConsumeToken(); // the identifier
-          ParsingDeclSpec DS(*this);
-          DS.takeAttributesFrom(attrs);
-          DS.SetTypeSpecType(DeclSpec::TST_typename, NameLoc, PrevSpec, DiagID,
-                             Type);
-          DS.SetRangeStart(NameLoc);
-          DS.SetRangeEnd(NameLoc);
-          
-          // In Objective-C, check whether this is the start of a class message
-          // send that is missing an opening square bracket ('[').
-          if (getLang().ObjC1 && Tok.is(tok::identifier) && 
-              Type.get()->isObjCObjectOrInterfaceType() &&
-              isColonOrRSquareBracket(NextToken())) {
-            // Fake up a Declarator to use with ActOnTypeName.
-            Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
-            TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
-            if (Ty.isInvalid()) {
-              SkipUntil(tok::r_brace, /*StopAtSemi=*/true, /*DontConsume=*/true);
-              if (Tok.is(tok::semi))
-                ConsumeToken();
-              return StmtError();
-            }
-            
-            ExprResult MsgExpr = ParseObjCMessageExpressionBody(SourceLocation(), 
-                                                                SourceLocation(),
-                                                                Ty.get(), 0);
-            return ParseExprStatement(attrs, MsgExpr);
-          }
-          
-          // Objective-C supports syntax of the form 'id<proto1,proto2>' where 
-          // 'id' is a specific typedef and 'itf<proto1,proto2>' where 'itf' is 
-          // an Objective-C interface. 
-          if (Tok.is(tok::less) && getLang().ObjC1)
-            ParseObjCProtocolQualifiers(DS);
-
-          SourceLocation DeclStart = NameLoc, DeclEnd;
-          DeclGroupPtrTy Decl = ParseSimpleDeclaration(DS, Stmts, 
-                                                       Declarator::BlockContext,
-                                                       DeclEnd, true);
-          return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
-        }
-          
-        // In C++, we might also have a functional-style cast. Just annotate
-        // this as a type token.
+      case Sema::NC_Type:
         Tok.setKind(tok::annot_typename);
         setTypeAnnotation(Tok, Classification.getType());
         Tok.setAnnotationEndLoc(NameLoc);
         Tok.setLocation(NameLoc);
         PP.AnnotateCachedTokens(Tok);
         break;
-      }
           
       case Sema::NC_Expression:
         ConsumeToken(); // the identifier