[cfe-commits] r53644 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/Basic/DiagnosticKinds.def include/clang/Parse/AttributeList.h lib/Parse/AttributeList.cpp lib/Sema/SemaDeclAttr.cpp
Ted Kremenek
kremenek at apple.com
Tue Jul 15 15:26:48 PDT 2008
Author: kremenek
Date: Tue Jul 15 17:26:48 2008
New Revision: 53644
URL: http://llvm.org/viewvc/llvm-project?rev=53644&view=rev
Log:
Added parsing/sema support for __attribute__ ((IBOutlet)), a clang-specific attribute that the static analyzer will use to recognize what ivars are IBOutlets.
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/include/clang/Parse/AttributeList.h
cfe/trunk/lib/Parse/AttributeList.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=53644&r1=53643&r2=53644&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Tue Jul 15 17:26:48 2008
@@ -37,7 +37,9 @@
Visibility,
FastCall,
StdCall,
- TransparentUnion
+ TransparentUnion,
+ IBOutletKind // Clang-specific. Use "Kind" suffix to not conflict with
+ // the IBOutlet macro.
};
private:
@@ -120,6 +122,17 @@
static bool classof(const Attr *A) { return A->getKind() == Alias; }
static bool classof(const AliasAttr *A) { return true; }
};
+
+class IBOutletAttr : public Attr {
+public:
+ IBOutletAttr() : Attr(IBOutletKind) {}
+
+ // Implement isa/cast/dyncast/etc.
+ static bool classof(const Attr *A) {
+ return A->getKind() == IBOutletKind;
+ }
+ static bool classof(const IBOutletAttr *A) { return true; }
+};
class NoReturnAttr : public Attr {
public:
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=53644&r1=53643&r2=53644&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Jul 15 17:26:48 2008
@@ -672,6 +672,10 @@
"type of machine mode does not match type of base type")
DIAG(err_attr_wrong_decl, ERROR,
"'%0' attribute invalid on this declaration, requires typedef or value")
+
+// Clang-Specific Attributes
+DIAG(err_attribute_iboutlet_non_ivar, ERROR,
+ "'IBOutlet' attribute can only be applied to instance variables")
// Function Parameter Semantic Analysis.
DIAG(err_param_with_void_type, ERROR,
Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=53644&r1=53643&r2=53644&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Tue Jul 15 17:26:48 2008
@@ -52,6 +52,7 @@
AT_ext_vector_type,
AT_fastcall,
AT_format,
+ AT_IBOutlet, // Clang-specific.
AT_malloc,
AT_mode,
AT_noinline,
Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=53644&r1=53643&r2=53644&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Tue Jul 15 17:26:48 2008
@@ -49,7 +49,7 @@
Str += 2;
Len -= 4;
}
-
+
switch (Len) {
case 4:
if (!memcmp(Str, "weak", 4)) return AT_weak;
@@ -76,6 +76,7 @@
if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
if (!memcmp(Str, "noinline", 8)) return AT_noinline;
if (!memcmp(Str, "fastcall", 8)) return AT_fastcall;
+ if (!memcmp(Str, "IBOutlet", 8)) return AT_IBOutlet;
break;
case 9:
if (!memcmp(Str, "dllimport", 9)) return AT_dllimport;
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=53644&r1=53643&r2=53644&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Jul 15 17:26:48 2008
@@ -217,6 +217,22 @@
Attr.getName()->getName());
}
+static void HandleIBOutletAttr(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,
+ std::string("0"));
+ return;
+ }
+
+ // The IBOutlet attribute only applies to instance variables of Objective-C
+ // classes.
+ if (ObjCIvarDecl *ID = dyn_cast<ObjCIvarDecl>(d))
+ ID->addAttr(new IBOutletAttr());
+ else
+ S.Diag(Attr.getLoc(), diag::err_attribute_iboutlet_non_ivar);
+}
+
static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() != 1) {
@@ -746,6 +762,7 @@
case AttributeList::AT_annotate: HandleAnnotateAttr (D, Attr, S); break;
case AttributeList::AT_noreturn: HandleNoReturnAttr (D, Attr, S); break;
case AttributeList::AT_format: HandleFormatAttr (D, Attr, S); break;
+ case AttributeList::AT_IBOutlet: HandleIBOutletAttr (D, Attr, S); break;
case AttributeList::AT_transparent_union:
HandleTransparentUnionAttr(D, Attr, S);
break;
More information about the cfe-commits
mailing list