aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/Sema.h16
-rw-r--r--lib/Sema/SemaDeclObjC.cpp11
-rw-r--r--lib/Sema/SemaExpr.cpp4
-rw-r--r--lib/Sema/SemaExprObjC.cpp16
-rw-r--r--lib/Sema/SemaLookup.cpp40
5 files changed, 59 insertions, 28 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 8cf2af0577..b5f4e0bc9e 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -168,10 +168,6 @@ public:
/// This is only necessary for issuing pretty diagnostics.
llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
- /// ObjCImplementations - Keep track of all class @implementations
- /// so we can emit errors on duplicates.
- llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
-
/// ObjCCategoryImpls - Maintain a list of category implementations so
/// we can check for duplicates and find local method declarations.
llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
@@ -770,7 +766,11 @@ public:
/// C99 6.2.2p4-5 and C++ [basic.link]p6.
LookupRedeclarationWithLinkage,
/// Look up the name of an Objective-C protocol.
- LookupProtocolName
+ LookupObjCProtocolName,
+ /// Look up the name of an Objective-C implementation
+ LookupObjCImplementationName,
+ /// Look up the name of an Objective-C category implementation
+ LookupObjCCategoryImplName
};
/// @brief Represents the results of name lookup.
@@ -1022,7 +1022,9 @@ public:
case Sema::LookupTagName:
case Sema::LookupMemberName:
case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
- case Sema::LookupProtocolName:
+ case Sema::LookupObjCProtocolName:
+ case Sema::LookupObjCImplementationName:
+ case Sema::LookupObjCCategoryImplName:
return D->isInIdentifierNamespace(IDNS);
case Sema::LookupOperatorName:
@@ -1057,6 +1059,8 @@ public:
SourceLocation Loc = SourceLocation());
ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II);
+ ObjCImplementationDecl *LookupObjCImplementation(IdentifierInfo *II);
+ ObjCCategoryImplDecl *LookupObjCCategoryImpl(IdentifierInfo *II);
void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
QualType T1, QualType T2,
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 7badaa3130..e0cbdce7e0 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -677,18 +677,15 @@ Sema::DeclPtrTy Sema::ActOnStartClassImplementation(
ObjCImplementationDecl::Create(Context, CurContext, AtClassImplLoc,
IDecl, SDecl);
- // FIXME: PushOnScopeChains?
- CurContext->addDecl(Context, IMPDecl);
-
if (CheckObjCDeclScope(IMPDecl))
return DeclPtrTy::make(IMPDecl);
// Check that there is no duplicate implementation of this class.
- if (ObjCImplementations[ClassName])
+ if (LookupObjCImplementation(ClassName))
// FIXME: Don't leak everything!
Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName;
else // add it to the list.
- ObjCImplementations[ClassName] = IMPDecl;
+ PushOnScopeChains(IMPDecl, TUScope);
return DeclPtrTy::make(IMPDecl);
}
@@ -832,8 +829,8 @@ bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl,
}
}
// Lastly, look through the implementation (if one is in scope).
- if (ObjCImplementationDecl *ImpDecl =
- ObjCImplementations[IDecl->getIdentifier()])
+ if (ObjCImplementationDecl *ImpDecl
+ = LookupObjCImplementation(IDecl->getIdentifier()))
if (ImpDecl->getInstanceMethod(Context, PDecl->getSetterName()))
return false;
// If all fails, look at the super class.
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 8490672f4b..89f834cf5a 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1807,8 +1807,8 @@ ObjCMethodDecl *Sema::FindMethodInNestedImplementations(
const ObjCInterfaceDecl *IFace,
const Selector &Sel) {
ObjCMethodDecl *Method = 0;
- if (ObjCImplementationDecl *ImpDecl =
- Sema::ObjCImplementations[IFace->getIdentifier()])
+ if (ObjCImplementationDecl *ImpDecl
+ = LookupObjCImplementation(IFace->getIdentifier()))
Method = ImpDecl->getInstanceMethod(Context, Sel);
if (!Method && IFace->getSuperClass())
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 1df7f3dcc9..d48ba4470c 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -222,8 +222,8 @@ ObjCMethodDecl *Sema::LookupPrivateClassMethod(Selector Sel,
ObjCMethodDecl *Method = 0;
// lookup in class and all superclasses
while (ClassDecl && !Method) {
- if (ObjCImplementationDecl *ImpDecl =
- ObjCImplementations[ClassDecl->getIdentifier()])
+ if (ObjCImplementationDecl *ImpDecl
+ = LookupObjCImplementation(ClassDecl->getIdentifier()))
Method = ImpDecl->getClassMethod(Context, Sel);
// Look through local category implementations associated with the class.
@@ -255,8 +255,8 @@ ObjCMethodDecl *Sema::LookupPrivateInstanceMethod(Selector Sel,
ObjCMethodDecl *Method = 0;
while (ClassDecl && !Method) {
// If we have implementations in scope, check "private" methods.
- if (ObjCImplementationDecl *ImpDecl =
- ObjCImplementations[ClassDecl->getIdentifier()])
+ if (ObjCImplementationDecl *ImpDecl
+ = LookupObjCImplementation(ClassDecl->getIdentifier()))
Method = ImpDecl->getInstanceMethod(Context, Sel);
// Look through local category implementations associated with the class.
@@ -288,8 +288,8 @@ Action::OwningExprResult Sema::ActOnClassPropertyRefExpr(
if (!Getter)
if (ObjCMethodDecl *CurMeth = getCurMethodDecl())
if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
- if (ObjCImplementationDecl *ImpDecl =
- ObjCImplementations[ClassDecl->getIdentifier()])
+ if (ObjCImplementationDecl *ImpDecl
+ = LookupObjCImplementation(ClassDecl->getIdentifier()))
Getter = ImpDecl->getClassMethod(Context, Sel);
if (Getter) {
@@ -310,8 +310,8 @@ Action::OwningExprResult Sema::ActOnClassPropertyRefExpr(
// methods.
if (ObjCMethodDecl *CurMeth = getCurMethodDecl())
if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
- if (ObjCImplementationDecl *ImpDecl =
- ObjCImplementations[ClassDecl->getIdentifier()])
+ if (ObjCImplementationDecl *ImpDecl
+ = LookupObjCImplementation(ClassDecl->getIdentifier()))
Setter = ImpDecl->getClassMethod(Context, SetterSel);
}
// Look through local category implementations associated with the class.
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 613c30bc0c..4b5a04b450 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -294,8 +294,16 @@ getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind,
IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Member;
break;
- case Sema::LookupProtocolName:
- IDNS = Decl::IDNS_Protocol;
+ case Sema::LookupObjCProtocolName:
+ IDNS = Decl::IDNS_ObjCProtocol;
+ break;
+
+ case Sema::LookupObjCImplementationName:
+ IDNS = Decl::IDNS_ObjCImplementation;
+ break;
+
+ case Sema::LookupObjCCategoryImplName:
+ IDNS = Decl::IDNS_ObjCCategoryImpl;
break;
}
return IDNS;
@@ -836,8 +844,16 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind,
IDNS = Decl::IDNS_Ordinary;
break;
- case Sema::LookupProtocolName:
- IDNS = Decl::IDNS_Protocol;
+ case Sema::LookupObjCProtocolName:
+ IDNS = Decl::IDNS_ObjCProtocol;
+ break;
+
+ case Sema::LookupObjCImplementationName:
+ IDNS = Decl::IDNS_ObjCImplementation;
+ break;
+
+ case Sema::LookupObjCCategoryImplName:
+ IDNS = Decl::IDNS_ObjCCategoryImpl;
break;
}
@@ -1490,10 +1506,24 @@ IsAcceptableNonMemberOperatorCandidate(FunctionDecl *Fn,
/// \brief Find the protocol with the given name, if any.
ObjCProtocolDecl *Sema::LookupProtocol(IdentifierInfo *II) {
- Decl *D = LookupName(TUScope, II, LookupProtocolName).getAsDecl();
+ Decl *D = LookupName(TUScope, II, LookupObjCProtocolName).getAsDecl();
return cast_or_null<ObjCProtocolDecl>(D);
}
+/// \brief Find the Objective-C implementation with the given name, if
+/// any.
+ObjCImplementationDecl *Sema::LookupObjCImplementation(IdentifierInfo *II) {
+ Decl *D = LookupName(TUScope, II, LookupObjCImplementationName).getAsDecl();
+ return cast_or_null<ObjCImplementationDecl>(D);
+}
+
+/// \brief Find the Objective-C category implementation with the given
+/// name, if any.
+ObjCCategoryImplDecl *Sema::LookupObjCCategoryImpl(IdentifierInfo *II) {
+ Decl *D = LookupName(TUScope, II, LookupObjCCategoryImplName).getAsDecl();
+ return cast_or_null<ObjCCategoryImplDecl>(D);
+}
+
void Sema::LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
QualType T1, QualType T2,
FunctionSet &Functions) {