[cfe-commits] r61114 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Action.h include/clang/Parse/AttributeList.h lib/Parse/AttributeList.cpp lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaDeclObjC.cpp test/SemaObjC/protocol-atttribute-1.m
Fariborz Jahanian
fjahanian at apple.com
Tue Dec 16 17:07:29 PST 2008
Author: fjahanian
Date: Tue Dec 16 19:07:27 2008
New Revision: 61114
URL: http://llvm.org/viewvc/llvm-project?rev=61114&view=rev
Log:
Semantics of @protocol attributes.
Added:
cfe/trunk/test/SemaObjC/protocol-atttribute-1.m
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/AttributeList.h
cfe/trunk/lib/Parse/AttributeList.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Tue Dec 16 19:07:27 2008
@@ -45,6 +45,7 @@
Packed,
StdCall,
TransparentUnion,
+ Unavailable,
Unused,
Visibility,
Weak,
@@ -65,6 +66,10 @@
}
Kind getKind() const { return AttrKind; }
+
+ bool hasKind(Kind kind) const {
+ return AttrKind == kind;
+ }
Attr *getNext() { return Next; }
const Attr *getNext() const { return Next; }
@@ -219,6 +224,16 @@
static bool classof(const DeprecatedAttr *A) { return true; }
};
+class UnavailableAttr : public Attr {
+public:
+ UnavailableAttr() : Attr(Unavailable) {}
+
+ // Implement isa/cast/dyncast/etc.
+
+ static bool classof(const Attr *A) { return A->getKind() == Unavailable; }
+ static bool classof(const UnavailableAttr *A) { return true; }
+};
+
class UnusedAttr : public Attr {
public:
UnusedAttr() : Attr(Unused) {}
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Dec 16 19:07:27 2008
@@ -974,6 +974,8 @@
"use of undeclared '%0'")
DIAG(warn_deprecated, WARNING,
"%0 is deprecated")
+DIAG(warn_unavailable, WARNING,
+ "%0 is unavailable")
DIAG(err_redefinition, ERROR,
"redefinition of %0")
DIAG(err_static_non_static, ERROR,
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Dec 16 19:07:27 2008
@@ -1072,7 +1072,8 @@
virtual DeclTy *ActOnForwardProtocolDeclaration(
SourceLocation AtProtocolLoc,
const IdentifierLocPair*IdentList,
- unsigned NumElts) {
+ unsigned NumElts,
+ AttributeList *AttrList) {
return 0;
}
Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Tue Dec 16 19:07:27 2008
@@ -66,6 +66,7 @@
AT_pure,
AT_stdcall,
AT_transparent_union,
+ AT_unavailable,
AT_unused,
AT_vector_size,
AT_visibility,
Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Tue Dec 16 19:07:27 2008
@@ -94,6 +94,7 @@
case 11:
if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
if (!memcmp(Str, "constructor", 11)) return AT_constructor;
+ if (!memcmp(Str, "unavailable", 11)) return AT_unavailable;
break;
case 13:
if (!memcmp(Str, "address_space", 13)) return AT_address_space;
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Dec 16 19:07:27 2008
@@ -936,7 +936,8 @@
if (Tok.is(tok::semi)) { // forward declaration of one protocol.
IdentifierLocPair ProtoInfo(protocolName, nameLoc);
ConsumeToken();
- return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1);
+ return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1,
+ attrList);
}
if (Tok.is(tok::comma)) { // list of forward declarations.
@@ -964,7 +965,8 @@
return Actions.ActOnForwardProtocolDeclaration(AtLoc,
&ProtocolRefs[0],
- ProtocolRefs.size());
+ ProtocolRefs.size(),
+ attrList);
}
// Last, and definitely not least, parse a protocol declaration.
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Dec 16 19:07:27 2008
@@ -1063,7 +1063,8 @@
virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
const IdentifierLocPair *IdentList,
- unsigned NumElts);
+ unsigned NumElts,
+ AttributeList *attrList);
virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
const IdentifierLocPair *ProtocolId,
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Dec 16 19:07:27 2008
@@ -501,6 +501,16 @@
d->addAttr(new DeprecatedAttr());
}
+static void HandleUnavailableAttr(Decl *d, const AttributeList &Attr, Sema &S) {
+ // check the attribute arguments.
+ if (Attr.getNumArgs() != 0) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+ return;
+ }
+
+ d->addAttr(new UnavailableAttr());
+}
+
static void HandleVisibilityAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() != 1) {
@@ -1126,6 +1136,7 @@
case AttributeList::AT_nothrow: HandleNothrowAttr (D, Attr, S); break;
case AttributeList::AT_packed: HandlePackedAttr (D, Attr, S); break;
case AttributeList::AT_stdcall: HandleStdCallAttr (D, Attr, S); break;
+ case AttributeList::AT_unavailable: HandleUnavailableAttr(D, Attr, S); break;
case AttributeList::AT_unused: HandleUnusedAttr (D, Attr, S); break;
case AttributeList::AT_vector_size: HandleVectorSizeAttr(D, Attr, S); break;
case AttributeList::AT_visibility: HandleVisibilityAttr(D, Attr, S); break;
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=61114&r1=61113&r2=61114&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Dec 16 19:07:27 2008
@@ -207,7 +207,8 @@
PDecl->setForwardDecl(false);
ObjCProtocols[ProtocolName] = PDecl;
}
-
+ if (AttrList)
+ ProcessDeclAttributeList(PDecl, AttrList);
if (NumProtoRefs) {
/// Check then save referenced protocols.
PDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs);
@@ -233,6 +234,14 @@
<< ProtocolId[i].first;
continue;
}
+ for (const Attr *attr = PDecl->getAttrs(); attr; attr = attr->getNext()) {
+ if (attr->hasKind(Attr::Unavailable))
+ Diag(ProtocolId[i].second, diag::warn_unavailable) <<
+ PDecl->getDeclName();
+ if (attr->hasKind(Attr::Deprecated))
+ Diag(ProtocolId[i].second, diag::warn_deprecated) <<
+ PDecl->getDeclName();
+ }
// If this is a forward declaration and we are supposed to warn in this
// case, do it.
@@ -417,7 +426,8 @@
Action::DeclTy *
Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
const IdentifierLocPair *IdentList,
- unsigned NumElts) {
+ unsigned NumElts,
+ AttributeList *attrList) {
llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols;
for (unsigned i = 0; i != NumElts; ++i) {
@@ -425,7 +435,8 @@
ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident];
if (PDecl == 0) // Not already seen?
PDecl = ObjCProtocolDecl::Create(Context, IdentList[i].second, Ident);
-
+ if (attrList)
+ ProcessDeclAttributeList(PDecl, attrList);
Protocols.push_back(PDecl);
}
Added: cfe/trunk/test/SemaObjC/protocol-atttribute-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocol-atttribute-1.m?rev=61114&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/protocol-atttribute-1.m (added)
+++ cfe/trunk/test/SemaObjC/protocol-atttribute-1.m Tue Dec 16 19:07:27 2008
@@ -0,0 +1,49 @@
+// RUN: clang -fsyntax-only -verify %s
+
+__attribute ((unavailable))
+ at protocol FwProto;
+
+Class <FwProto> cFw = 0; // expected-warning {{'FwProto' is unavailable}}
+
+
+__attribute ((deprecated)) @protocol MyProto1
+ at end
+
+ at protocol Proto2 <MyProto1> // expected-warning {{'MyProto1' is deprecated}}
++method2;
+ at end
+
+
+ at interface MyClass1 <MyProto1> // expected-warning {{'MyProto1' is deprecated}}
+{
+ Class isa;
+}
+ at end
+
+ at interface Derived : MyClass1 <MyProto1> // expected-warning {{'MyProto1' is deprecated}}
+{
+ id <MyProto1> ivar; // expected-warning {{'MyProto1' is deprecated}}
+}
+ at end
+
+ at interface MyClass1 (Category) <MyProto1, Proto2> // expected-warning {{'MyProto1' is deprecated}}
+ at end
+
+
+
+Class <MyProto1> clsP1 = 0; // expected-warning {{'MyProto1' is deprecated}}
+
+ at protocol FwProto @end
+
+ at interface MyClass2 <FwProto> // expected-warning {{'FwProto' is unavailable}}
+ at end
+
+__attribute ((unavailable)) __attribute ((deprecated)) @protocol XProto;
+
+id <XProto> idX = 0; // expected-warning {{'XProto' is unavailable}} expected-warning {{'XProto' is deprecated}}
+
+int main ()
+{
+ MyClass1 <MyProto1> *p1; // expected-warning {{'MyProto1' is deprecated}}
+}
+
More information about the cfe-commits
mailing list