Introduce a parsing action to distinguish between class, instance, and
super message sends in Objective-C. No actual functionality change
here, but it provides a hook so that Sema can typo-correct the
receiver in some cases.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101207 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp
index e755692..fc06a0d 100644
--- a/lib/Parse/MinimalAction.cpp
+++ b/lib/Parse/MinimalAction.cpp
@@ -26,6 +26,20 @@
 ///  Out-of-line virtual destructor to provide home for Action class.
 Action::~Action() {}
 
+Action::ObjCMessageKind Action::getObjCMessageKind(Scope *S,
+                                                   IdentifierInfo *&Name,
+                                                   SourceLocation NameLoc,
+                                                   bool IsSuper,
+                                                   bool HasTrailingDot) {
+  if (IsSuper && !HasTrailingDot && S->isInObjcMethodScope())
+    return ObjCSuperMessage;
+      
+  if (getTypeName(*Name, NameLoc, S))
+    return ObjCClassMessage;
+      
+  return ObjCInstanceMessage;
+}
+
 // Defined out-of-line here because of dependecy on AttributeList
 Action::DeclPtrTy Action::ActOnUsingDirective(Scope *CurScope,
                                               SourceLocation UsingLoc,
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 6c5053d..6a20a08 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -1719,17 +1719,18 @@
   SourceLocation LBracLoc = ConsumeBracket(); // consume '['
 
   if (Tok.is(tok::identifier)) {
-    IdentifierInfo *II = Tok.getIdentifierInfo();
-
-    // If this is '[' 'super', then this is a magic superclass message.
-    // We parse '[' 'super' '.' 'foo'  as an expression?
-    if ((II == Ident_super && GetLookAheadToken(1).isNot(tok::period) &&
-         CurScope->isInObjcMethodScope()) ||
-        // Check to see if this is a typename.  If so, it is a class message.
-        Actions.getTypeName(*II, Tok.getLocation(), CurScope)) {
-      SourceLocation NameLoc = ConsumeToken();
-      return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, II,
+    IdentifierInfo *Name = Tok.getIdentifierInfo();
+    SourceLocation NameLoc = Tok.getLocation();
+    switch (Actions.getObjCMessageKind(CurScope, Name, NameLoc,
+                                       Name == Ident_super,
+                                       NextToken().is(tok::period))) {
+    case Action::ObjCSuperMessage:
+    case Action::ObjCClassMessage:
+      return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), Name,
                                             ExprArg(Actions));
+        
+    case Action::ObjCInstanceMessage:
+      break;
     }
   }