Migrate the responsibility for turning the receiver name in an
Objective-C class message expression into a type from the parser
(which was doing so in two places) to Action::getObjCMessageKind()
which, in the case of Sema, reduces the number of name lookups we need
to perform.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102026 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp
index fc06a0d..5a03767 100644
--- a/lib/Parse/MinimalAction.cpp
+++ b/lib/Parse/MinimalAction.cpp
@@ -27,15 +27,30 @@
 Action::~Action() {}
 
 Action::ObjCMessageKind Action::getObjCMessageKind(Scope *S,
-                                                   IdentifierInfo *&Name,
+                                                   IdentifierInfo *Name,
                                                    SourceLocation NameLoc,
                                                    bool IsSuper,
-                                                   bool HasTrailingDot) {
+                                                   bool HasTrailingDot,
+                                                   TypeTy *&ReceiverType) {
+  ReceiverType = 0;
+
   if (IsSuper && !HasTrailingDot && S->isInObjcMethodScope())
     return ObjCSuperMessage;
       
-  if (getTypeName(*Name, NameLoc, S))
+  if (TypeTy *TyName = getTypeName(*Name, NameLoc, S)) {
+    DeclSpec DS;
+    const char *PrevSpec = 0;
+    unsigned DiagID = 0;
+    if (!DS.SetTypeSpecType(DeclSpec::TST_typename, NameLoc, PrevSpec,
+                            DiagID, TyName)) {
+      DS.SetRangeEnd(NameLoc);
+      Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
+      TypeResult Ty = ActOnTypeName(S, DeclaratorInfo);
+      if (!Ty.isInvalid())
+        ReceiverType = Ty.get();
+    }
     return ObjCClassMessage;
+  }
       
   return ObjCInstanceMessage;
 }
diff --git a/lib/Parse/ParseInit.cpp b/lib/Parse/ParseInit.cpp
index b0735b3..1a2a226 100644
--- a/lib/Parse/ParseInit.cpp
+++ b/lib/Parse/ParseInit.cpp
@@ -130,15 +130,17 @@
     if (getLang().ObjC1 && Tok.is(tok::identifier)) {
       IdentifierInfo *II = Tok.getIdentifierInfo();
       SourceLocation IILoc = Tok.getLocation();
+      TypeTy *ReceiverType;
       // Three cases. This is a message send to a type: [type foo]
       // This is a message send to super:  [super foo]
       // This is a message sent to an expr:  [super.bar foo]
       switch (Action::ObjCMessageKind Kind
                 = Actions.getObjCMessageKind(CurScope, II, IILoc, 
                                              II == Ident_super,
-                                             NextToken().is(tok::period))) {
+                                             NextToken().is(tok::period),
+                                             ReceiverType)) {
       case Action::ObjCSuperMessage:
-      case Action::ObjCClassMessage: {
+      case Action::ObjCClassMessage:
         // If we have exactly one array designator, this used the GNU
         // 'designation: array-designator' extension, otherwise there should be no
         // designators at all!
@@ -154,36 +156,16 @@
                                                              ConsumeToken(),
                                                              0,
                                                              ExprArg(Actions));
-
-        // FIXME: This code is redundant with ParseObjCMessageExpr.
-        // Create the type that corresponds to the identifier (which
-        // names an Objective-C class).
-        TypeTy *Type = 0;
-        if (TypeTy *TyName = Actions.getTypeName(*II, IILoc, CurScope)) {
-          DeclSpec DS;
-          const char *PrevSpec = 0;
-          unsigned DiagID = 0;
-          if (!DS.SetTypeSpecType(DeclSpec::TST_typename, IILoc, PrevSpec,
-                                  DiagID, TyName)) {
-            DS.SetRangeEnd(IILoc);
-            Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
-            TypeResult Ty = Actions.ActOnTypeName(CurScope, DeclaratorInfo);
-            if (!Ty.isInvalid())
-              Type = Ty.get();
-          }
-        }
-
-        ConsumeToken(); // The identifier.
-        if (!Type) {
+        ConsumeToken(); // the identifier
+        if (!ReceiverType) {
           SkipUntil(tok::r_square);
           return ExprError();
         }
 
         return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, 
                                                            SourceLocation(), 
-                                                           Type, 
+                                                           ReceiverType, 
                                                            ExprArg(Actions));
-      }
 
       case Action::ObjCInstanceMessage:
         // Fall through; we'll just parse the expression and
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 56937a6..2a71bf0 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -1726,40 +1726,26 @@
   if (Tok.is(tok::identifier)) {
     IdentifierInfo *Name = Tok.getIdentifierInfo();
     SourceLocation NameLoc = Tok.getLocation();
+    TypeTy *ReceiverType;
     switch (Actions.getObjCMessageKind(CurScope, Name, NameLoc,
                                        Name == Ident_super,
-                                       NextToken().is(tok::period))) {
+                                       NextToken().is(tok::period),
+                                       ReceiverType)) {
     case Action::ObjCSuperMessage:
       return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 0,
                                             ExprArg(Actions));
 
-    case Action::ObjCClassMessage: {
-      // Create the type that corresponds to the identifier (which
-      // names an Objective-C class).
-      TypeTy *Type = 0;
-      if (TypeTy *TyName = Actions.getTypeName(*Name, NameLoc, CurScope)) {
-        DeclSpec DS;
-        const char *PrevSpec = 0;
-        unsigned DiagID = 0;
-        if (!DS.SetTypeSpecType(DeclSpec::TST_typename, NameLoc, PrevSpec,
-                                DiagID, TyName)) {
-          DS.SetRangeEnd(NameLoc);
-          Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
-          TypeResult Ty = Actions.ActOnTypeName(CurScope, DeclaratorInfo);
-          if (!Ty.isInvalid())
-            Type = Ty.get();
-        }
-      }
-
-      ConsumeToken(); // The identifier.
-      if (!Type) {
+    case Action::ObjCClassMessage:
+      if (!ReceiverType) {
         SkipUntil(tok::r_square);
         return ExprError();
       }
 
-      return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), Type,
+      ConsumeToken(); // the type name
+
+      return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 
+                                            ReceiverType,
                                             ExprArg(Actions));
-    }
         
     case Action::ObjCInstanceMessage:
       // Fall through to parse an expression.