From 1569f95831a8c99e9f664137bf8f40e47ee3d90f Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 21 Apr 2010 20:38:13 +0000 Subject: 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 --- lib/Sema/SemaExprObjC.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'lib/Sema/SemaExprObjC.cpp') 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(ND) || isa(ND) || - isa(ND)) - return ObjCClassMessage; - - return ObjCInstanceMessage; + QualType T; + if (ObjCInterfaceDecl *Class = dyn_cast(ND)) + T = Context.getObjCInterfaceType(Class); + else if (TypeDecl *Type = dyn_cast(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(ND)) { + if (ObjCInterfaceDecl *Class = dyn_cast(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() && -- cgit v1.2.3-18-g5258