summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-07-15 22:26:48 +0000
committerTed Kremenek <kremenek@apple.com>2008-07-15 22:26:48 +0000
commit8e3704d35a71e5933e49e2491669fc60fe800cd5 (patch)
tree44dda8df987e060a185a2747e38ab870fab26f7a /clang
parent3879c5f6e42b19cc545694472f85d907f051b441 (diff)
downloadbcm5719-llvm-8e3704d35a71e5933e49e2491669fc60fe800cd5.tar.gz
bcm5719-llvm-8e3704d35a71e5933e49e2491669fc60fe800cd5.zip
Added parsing/sema support for __attribute__ ((IBOutlet)), a clang-specific attribute that the static analyzer will use to recognize what ivars are IBOutlets.
llvm-svn: 53644
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/Attr.h15
-rw-r--r--clang/include/clang/Basic/DiagnosticKinds.def4
-rw-r--r--clang/include/clang/Parse/AttributeList.h1
-rw-r--r--clang/lib/Parse/AttributeList.cpp3
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp17
5 files changed, 38 insertions, 2 deletions
diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index c7da6d924bc..c659454b832 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -37,7 +37,9 @@ public:
Visibility,
FastCall,
StdCall,
- TransparentUnion
+ TransparentUnion,
+ IBOutletKind // Clang-specific. Use "Kind" suffix to not conflict with
+ // the IBOutlet macro.
};
private:
@@ -120,6 +122,17 @@ public:
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:
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def
index c0a2ea0221c..d1c4bd9080e 100644
--- a/clang/include/clang/Basic/DiagnosticKinds.def
+++ b/clang/include/clang/Basic/DiagnosticKinds.def
@@ -672,6 +672,10 @@ DIAG(err_mode_wrong_type, ERROR,
"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,
diff --git a/clang/include/clang/Parse/AttributeList.h b/clang/include/clang/Parse/AttributeList.h
index 112a495e6e3..18a26163a37 100644
--- a/clang/include/clang/Parse/AttributeList.h
+++ b/clang/include/clang/Parse/AttributeList.h
@@ -52,6 +52,7 @@ public:
AT_ext_vector_type,
AT_fastcall,
AT_format,
+ AT_IBOutlet, // Clang-specific.
AT_malloc,
AT_mode,
AT_noinline,
diff --git a/clang/lib/Parse/AttributeList.cpp b/clang/lib/Parse/AttributeList.cpp
index 8697d4ece8a..9d84a0f1890 100644
--- a/clang/lib/Parse/AttributeList.cpp
+++ b/clang/lib/Parse/AttributeList.cpp
@@ -49,7 +49,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
Str += 2;
Len -= 4;
}
-
+
switch (Len) {
case 4:
if (!memcmp(Str, "weak", 4)) return AT_weak;
@@ -76,6 +76,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
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;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index e6dac4901ed..f8217b362f2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -217,6 +217,22 @@ static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
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 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) {
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;
OpenPOWER on IntegriCloud