aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-04-21 20:38:13 +0000
committerDouglas Gregor <dgregor@apple.com>2010-04-21 20:38:13 +0000
commit1569f95831a8c99e9f664137bf8f40e47ee3d90f (patch)
treea107f83099282227ab157ee9b055da87ca8319ab /lib/Sema
parentb99c666a940e93bcfcaeddc01515c94472e28a20 (diff)
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
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/Sema.h5
-rw-r--r--lib/Sema/SemaExprObjC.cpp31
2 files changed, 25 insertions, 11 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index a7e402dfcb..a284803ed6 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -3867,10 +3867,11 @@ public:
SourceLocation propertyNameLoc);
virtual ObjCMessageKind getObjCMessageKind(Scope *S,
- IdentifierInfo *&Name,
+ IdentifierInfo *Name,
SourceLocation NameLoc,
bool IsSuper,
- bool HasTrailingDot);
+ bool HasTrailingDot,
+ TypeTy *&ReceiverType);
virtual OwningExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
Selector Sel,
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index e9c391c3e9..3af0cfc2c4 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -503,10 +503,13 @@ ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
}
Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S,
- IdentifierInfo *&Name,
+ IdentifierInfo *Name,
SourceLocation NameLoc,
bool IsSuper,
- bool HasTrailingDot) {
+ bool HasTrailingDot,
+ TypeTy *&ReceiverType) {
+ ReceiverType = 0;
+
// If the identifier is "super" and there is no trailing dot, we're
// messaging super.
if (IsSuper && !HasTrailingDot && S->isInObjcMethodScope())
@@ -541,11 +544,19 @@ Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S,
// We found something. If it's a type, then we have a class
// message. Otherwise, it's an instance message.
NamedDecl *ND = Result.getFoundDecl();
- if (isa<ObjCInterfaceDecl>(ND) || isa<TypeDecl>(ND) ||
- isa<UnresolvedUsingTypenameDecl>(ND))
- return ObjCClassMessage;
-
- return ObjCInstanceMessage;
+ QualType T;
+ if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(ND))
+ T = Context.getObjCInterfaceType(Class);
+ else if (TypeDecl *Type = dyn_cast<TypeDecl>(ND))
+ T = Context.getTypeDeclType(Type);
+ else
+ return ObjCInstanceMessage;
+
+ // We have a class message, and T is the type we're
+ // messaging. Build source-location information for it.
+ TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
+ ReceiverType = CreateLocInfoType(T, TSInfo).getAsOpaquePtr();
+ return ObjCClassMessage;
}
}
@@ -561,7 +572,7 @@ Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S,
// If we found a declaration, correct when it refers to an Objective-C
// class.
NamedDecl *ND = Result.getFoundDecl();
- if (isa<ObjCInterfaceDecl>(ND)) {
+ if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(ND)) {
Diag(NameLoc, diag::err_unknown_receiver_suggest)
<< Name << Result.getLookupName()
<< FixItHint::CreateReplacement(SourceRange(NameLoc),
@@ -569,7 +580,9 @@ Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S,
Diag(ND->getLocation(), diag::note_previous_decl)
<< Corrected;
- Name = ND->getIdentifier();
+ QualType T = Context.getObjCInterfaceType(Class);
+ TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
+ ReceiverType = CreateLocInfoType(T, TSInfo).getAsOpaquePtr();
return ObjCClassMessage;
}
} else if (Result.empty() && Corrected.getAsIdentifierInfo() &&