summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2013-11-23 01:01:34 +0000
committerTed Kremenek <kremenek@apple.com>2013-11-23 01:01:34 +0000
commit28eace65c09a51e24fb5651ee035e2c6c102da69 (patch)
treeab5a24003861c9eae641764eb089cff1647059d6 /clang/lib/Sema
parent0078150c43f91c82cf43c8e65f6715b984e1a80f (diff)
downloadbcm5719-llvm-28eace65c09a51e24fb5651ee035e2c6c102da69.tar.gz
bcm5719-llvm-28eace65c09a51e24fb5651ee035e2c6c102da69.zip
Add back experimental attribute objc_suppress_protocol_methods (slightly renamed).
This is still an experimental attribute, but I wanted it in tree for review. It may still get yanked. This attribute can only be applied to a class @interface, not a class extension or category. It does not change the type system rules for Objective-C, but rather the implementation checking for Objective-C classes that explicitly conform to a protocol. During protocol conformance checking, clang recursively searches up the class hierarchy for the set of methods that compose a protocol. This attribute will cause the compiler to not consider the methods contributed by a super class, its categories, and those from its ancestor classes. Thus this attribute is used to force subclasses to redeclare (and hopefully re-implement) methods if they decide to explicitly conform to a protocol where some of those methods may be provided by a super class. This attribute intentionally leaves out properties, which are associated with state. This attribute only considers methods (at least right now) that are non-property accessors. These represent methods that "do something" as dictated by the protocol. This may be further refined, and this should be considered a WIP until documentation gets written or this gets removed. llvm-svn: 195533
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp27
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp8
2 files changed, 32 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1dec334bc7e..7ae873d7f9e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2134,6 +2134,28 @@ static void handleObjCRootClassAttr(Sema &S, Decl *D,
Attr.getAttributeSpellingListIndex()));
}
+static void handleObjCSuppresProtocolAttr(Sema &S, Decl *D,
+ const AttributeList &Attr) {
+ if (!isa<ObjCInterfaceDecl>(D)) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
+ << Attr.getName() << ExpectedObjectiveCInterface;
+ return;
+ }
+
+ IdentifierLoc *Parm = (Attr.getNumArgs() == 1 && Attr.isArgIdent(0))
+ ? Attr.getArgAsIdent(0) : 0;
+
+ if (!Parm) {
+ S.Diag(D->getLocStart(), diag::err_objc_attr_not_id) << Attr.getName() << 1;
+ return;
+ }
+
+ D->addAttr(::new (S.Context)
+ ObjCSuppressProtocolAttr(Attr.getRange(), S.Context, Parm->Ident,
+ Attr.getAttributeSpellingListIndex()));
+}
+
+
static void handleObjCRequiresPropertyDefsAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
if (!isa<ObjCInterfaceDecl>(D)) {
@@ -4713,7 +4735,10 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
case AttributeList::AT_ObjCRootClass:
handleObjCRootClassAttr(S, D, Attr);
break;
- case AttributeList::AT_ObjCRequiresPropertyDefs:
+ case AttributeList::AT_ObjCSuppressProtocol:
+ handleObjCSuppresProtocolAttr(S, D, Attr);
+ break;
+ case AttributeList::AT_ObjCRequiresPropertyDefs:
handleObjCRequiresPropertyDefsAttr (S, D, Attr);
break;
case AttributeList::AT_Unused: handleUnusedAttr (S, D, Attr); break;
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 95e3b4f4669..6de4e5bb21a 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -1667,7 +1667,9 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
(!Super || !Super->lookupMethod(method->getSelector(),
true /* instance */,
false /* shallowCategory */,
- true /* followsSuper */))) {
+ true /* followsSuper */,
+ NULL /* category */,
+ PDecl /* protocol */))) {
// If a method is not implemented in the category implementation but
// has been declared in its primary class, superclass,
// or in one of their protocols, no need to issue the warning.
@@ -1703,7 +1705,9 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
(!Super || !Super->lookupMethod(method->getSelector(),
false /* class method */,
false /* shallowCategoryLookup */,
- true /* followSuper */))) {
+ true /* followSuper */,
+ NULL /* category */,
+ PDecl /* protocol */))) {
// See above comment for instance method lookups.
if (C && IDecl->lookupMethod(method->getSelector(),
false /* class */,
OpenPOWER on IntegriCloud