summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclObjC.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-12-27 03:58:08 +0000
committerNico Weber <nicolasweber@gmx.de>2014-12-27 03:58:08 +0000
commit2e0c8f79d97b974a680087d12a7dc5e1dc705c20 (patch)
tree39a5eec66a84c82be84d24b102a61991a5b226a5 /clang/lib/Sema/SemaDeclObjC.cpp
parentc33b2fd0add3d1a77b19874c6a1dd91f5a59f8a3 (diff)
downloadbcm5719-llvm-2e0c8f79d97b974a680087d12a7dc5e1dc705c20.tar.gz
bcm5719-llvm-2e0c8f79d97b974a680087d12a7dc5e1dc705c20.zip
Address review feedback on r221933.
Remove ObjCMethodList::Count, instead store a "has more than one decl" bit in the low bit of the ObjCMethodDecl pointer, using a PointerIntPair. Most of this patch is replacing ".Method" with ".getMethod()". No intended behavior change. llvm-svn: 224876
Diffstat (limited to 'clang/lib/Sema/SemaDeclObjC.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp118
1 files changed, 62 insertions, 56 deletions
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index eccf2e1d2ae..90835be722b 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -2004,13 +2004,12 @@ void Sema::ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
IncompleteImpl, InsMap, ClsMap, CDecl,
ExplicitImplProtocols);
DiagnoseUnimplementedProperties(S, IMPDecl, CDecl,
- /* SynthesizeProperties */ false);
+ /*SynthesizeProperties=*/false);
}
} else
llvm_unreachable("invalid ObjCContainerDecl type.");
}
-/// ActOnForwardClassDeclaration -
Sema::DeclGroupPtrTy
Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
IdentifierInfo **IdentList,
@@ -2037,10 +2036,11 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
} else {
// a forward class declaration matching a typedef name of a class refers
// to the underlying class. Just ignore the forward class with a warning
- // as this will force the intended behavior which is to lookup the typedef
- // name.
+ // as this will force the intended behavior which is to lookup the
+ // typedef name.
if (isa<ObjCObjectType>(TDD->getUnderlyingType())) {
- Diag(AtClassLoc, diag::warn_forward_class_redefinition) << IdentList[i];
+ Diag(AtClassLoc, diag::warn_forward_class_redefinition)
+ << IdentList[i];
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
continue;
}
@@ -2217,22 +2217,22 @@ bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *left,
return true;
}
-void Sema::addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method) {
+void Sema::addMethodToGlobalList(ObjCMethodList *List,
+ ObjCMethodDecl *Method) {
// Record at the head of the list whether there were 0, 1, or >= 2 methods
// inside categories.
- if (ObjCCategoryDecl *
- CD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext()))
+ if (ObjCCategoryDecl *CD =
+ dyn_cast<ObjCCategoryDecl>(Method->getDeclContext()))
if (!CD->IsClassExtension() && List->getBits() < 2)
- List->setBits(List->getBits()+1);
+ List->setBits(List->getBits() + 1);
// If the list is empty, make it a singleton list.
- if (List->Method == nullptr) {
- List->Method = Method;
+ if (List->getMethod() == nullptr) {
+ List->setMethod(Method);
List->setNext(nullptr);
- List->Count = Method->isDefined() ? 0 : 1;
return;
}
-
+
// We've seen a method with this name, see if we have already seen this type
// signature.
ObjCMethodList *Previous = List;
@@ -2241,37 +2241,42 @@ void Sema::addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method) {
if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty())
continue;
- if (!MatchTwoMethodDeclarations(Method, List->Method))
+ if (!MatchTwoMethodDeclarations(Method, List->getMethod()))
continue;
-
- ObjCMethodDecl *PrevObjCMethod = List->Method;
+
+ ObjCMethodDecl *PrevObjCMethod = List->getMethod();
// Propagate the 'defined' bit.
if (Method->isDefined())
PrevObjCMethod->setDefined(true);
- else
- ++List->Count;
-
+ else if (!PrevObjCMethod->isDefined()) {
+ // Objective-C doesn't allow an @interface for a class after its
+ // @implementation. So if Method is not defined and there already is
+ // an entry for this type signature, Method has to be for a different
+ // class than PrevObjCMethod.
+ List->setHasMoreThanOneDecl(true);
+ }
+
// If a method is deprecated, push it in the global pool.
// This is used for better diagnostics.
if (Method->isDeprecated()) {
if (!PrevObjCMethod->isDeprecated())
- List->Method = Method;
+ List->setMethod(Method);
}
- // If new method is unavailable, push it into global pool
+ // If the new method is unavailable, push it into global pool
// unless previous one is deprecated.
if (Method->isUnavailable()) {
if (PrevObjCMethod->getAvailability() < AR_Deprecated)
- List->Method = Method;
+ List->setMethod(Method);
}
-
+
return;
}
-
+
// We have a new signature for an existing method - add it.
// This is extremely rare. Only 1% of Cocoa selectors are "overloaded".
ObjCMethodList *Mem = BumpAlloc.Allocate<ObjCMethodList>();
- Previous->setNext(new (Mem) ObjCMethodList(Method, 0, nullptr));
+ Previous->setNext(new (Mem) ObjCMethodList(Method));
}
/// \brief Read the contents of the method pool for a given selector from
@@ -2294,7 +2299,7 @@ void Sema::AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl,
if (Pos == MethodPool.end())
Pos = MethodPool.insert(std::make_pair(Method->getSelector(),
GlobalMethods())).first;
-
+
Method->setDefined(impl);
ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
@@ -2320,9 +2325,8 @@ static bool isAcceptableMethodMismatch(ObjCMethodDecl *chosen,
return (chosen->getReturnType()->isIntegerType());
}
-bool Sema::CollectMultipleMethodsInGlobalPool(Selector Sel,
- SmallVectorImpl<ObjCMethodDecl*>& Methods,
- bool instance) {
+bool Sema::CollectMultipleMethodsInGlobalPool(
+ Selector Sel, SmallVectorImpl<ObjCMethodDecl *> &Methods, bool instance) {
if (ExternalSource)
ReadMethodPool(Sel);
@@ -2332,19 +2336,19 @@ bool Sema::CollectMultipleMethodsInGlobalPool(Selector Sel,
// Gather the non-hidden methods.
ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
for (ObjCMethodList *M = &MethList; M; M = M->getNext())
- if (M->Method && !M->Method->isHidden())
- Methods.push_back(M->Method);
- return (Methods.size() > 1);
+ if (M->getMethod() && !M->getMethod()->isHidden())
+ Methods.push_back(M->getMethod());
+ return Methods.size() > 1;
}
-bool Sema::AreMultipleMethodsInGlobalPool(Selector Sel,
- bool instance) {
+bool Sema::AreMultipleMethodsInGlobalPool(Selector Sel, bool instance) {
GlobalMethodPool::iterator Pos = MethodPool.find(Sel);
- // Test for no method in the pool which should not trigger any warning by caller.
+ // Test for no method in the pool which should not trigger any warning by
+ // caller.
if (Pos == MethodPool.end())
return true;
ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
- return MethList.Count > 1;
+ return MethList.hasMoreThanOneDecl();
}
ObjCMethodDecl *Sema::LookupMethodInGlobalPool(Selector Sel, SourceRange R,
@@ -2361,12 +2365,12 @@ ObjCMethodDecl *Sema::LookupMethodInGlobalPool(Selector Sel, SourceRange R,
ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
SmallVector<ObjCMethodDecl *, 4> Methods;
for (ObjCMethodList *M = &MethList; M; M = M->getNext()) {
- if (M->Method && !M->Method->isHidden()) {
+ if (M->getMethod() && !M->getMethod()->isHidden()) {
// If we're not supposed to warn about mismatches, we're done.
if (!warn)
- return M->Method;
+ return M->getMethod();
- Methods.push_back(M->Method);
+ Methods.push_back(M->getMethod());
}
}
@@ -2438,13 +2442,13 @@ ObjCMethodDecl *Sema::LookupImplementedMethodInGlobalPool(Selector Sel) {
GlobalMethods &Methods = Pos->second;
for (const ObjCMethodList *Method = &Methods.first; Method;
Method = Method->getNext())
- if (Method->Method && Method->Method->isDefined())
- return Method->Method;
+ if (Method->getMethod() && Method->getMethod()->isDefined())
+ return Method->getMethod();
for (const ObjCMethodList *Method = &Methods.second; Method;
Method = Method->getNext())
- if (Method->Method && Method->Method->isDefined())
- return Method->Method;
+ if (Method->getMethod() && Method->getMethod()->isDefined())
+ return Method->getMethod();
return nullptr;
}
@@ -2507,25 +2511,27 @@ Sema::SelectorsForTypoCorrection(Selector Sel,
e = MethodPool.end(); b != e; b++) {
// instance methods
for (ObjCMethodList *M = &b->second.first; M; M=M->getNext())
- if (M->Method &&
- (M->Method->getSelector().getNumArgs() == NumArgs) &&
- (M->Method->getSelector() != Sel)) {
+ if (M->getMethod() &&
+ (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
+ (M->getMethod()->getSelector() != Sel)) {
if (ObjectIsId)
- Methods.push_back(M->Method);
+ Methods.push_back(M->getMethod());
else if (!ObjectIsClass &&
- HelperIsMethodInObjCType(*this, M->Method->getSelector(), ObjectType))
- Methods.push_back(M->Method);
+ HelperIsMethodInObjCType(*this, M->getMethod()->getSelector(),
+ ObjectType))
+ Methods.push_back(M->getMethod());
}
// class methods
for (ObjCMethodList *M = &b->second.second; M; M=M->getNext())
- if (M->Method &&
- (M->Method->getSelector().getNumArgs() == NumArgs) &&
- (M->Method->getSelector() != Sel)) {
+ if (M->getMethod() &&
+ (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
+ (M->getMethod()->getSelector() != Sel)) {
if (ObjectIsClass)
- Methods.push_back(M->Method);
+ Methods.push_back(M->getMethod());
else if (!ObjectIsId &&
- HelperIsMethodInObjCType(*this, M->Method->getSelector(), ObjectType))
- Methods.push_back(M->Method);
+ HelperIsMethodInObjCType(*this, M->getMethod()->getSelector(),
+ ObjectType))
+ Methods.push_back(M->getMethod());
}
}
@@ -2855,7 +2861,7 @@ public:
}
ObjCMethodList &list =
method->isInstanceMethod() ? it->second.first : it->second.second;
- if (!list.Method) return;
+ if (!list.getMethod()) return;
ObjCContainerDecl *container
= cast<ObjCContainerDecl>(method->getDeclContext());
OpenPOWER on IntegriCloud