aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2008-02-21 19:30:49 +0000
committerNate Begeman <natebegeman@mac.com>2008-02-21 19:30:49 +0000
commitc398f0b5efb2f8ba39cd5b0170cf697f714afbcb (patch)
tree2382099d4fd985cfdfd36957d56f9e8e5bd57b65
parentc3055ab39ac3535ffd581d33e21b72133099a6eb (diff)
Handle __attribute__((annotate("string")))
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47451 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Parse/AttributeList.cpp3
-rw-r--r--Sema/Sema.h1
-rw-r--r--Sema/SemaDecl.cpp28
-rw-r--r--include/clang/AST/Attr.h18
-rw-r--r--include/clang/Basic/DiagnosticKinds.def6
-rw-r--r--include/clang/Parse/AttributeList.h3
6 files changed, 52 insertions, 7 deletions
diff --git a/Parse/AttributeList.cpp b/Parse/AttributeList.cpp
index faa50eb32d..63d07b399b 100644
--- a/Parse/AttributeList.cpp
+++ b/Parse/AttributeList.cpp
@@ -57,6 +57,9 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
case 7:
if (!memcmp(Str, "aligned", 7)) return AT_aligned;
break;
+ case 8:
+ if (!memcmp(Str, "annotate", 8)) return AT_annotate;
+ break;
case 11:
if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
break;
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 70f76cc2fe..95bc3b7fcc 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -271,6 +271,7 @@ private:
void HandleAlignedAttribute(Decl *d, AttributeList *rawAttr);
void HandlePackedAttribute(Decl *d, AttributeList *rawAttr);
+ void HandleAnnotateAttribute(Decl *d, AttributeList *rawAttr);
void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
bool &IncompleteImpl);
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index e0a42a282d..9b33138fbb 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1777,6 +1777,9 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
case AttributeList::AT_packed:
HandlePackedAttribute(New, Attr);
break;
+ case AttributeList::AT_annotate:
+ HandleAnnotateAttribute(New, Attr);
+ break;
default:
// FIXME: add other attributes...
break;
@@ -1890,9 +1893,8 @@ QualType Sema::HandleVectorTypeAttribute(QualType curType,
sizeExpr->getSourceRange());
return QualType();
}
- // Since OpenCU requires 3 element vectors (OpenCU 5.1.2), we don't restrict
- // the number of elements to be a power of two (unlike GCC).
- // Instantiate the vector type, the number of elements is > 0.
+ // Instantiate the vector type, the number of elements is > 0, and not
+ // required to be a power of 2, unlike GCC.
return Context.getVectorType(curType, vectorSize/typeSize);
}
@@ -1919,7 +1921,27 @@ void Sema::HandlePackedAttribute(Decl *d, AttributeList *rawAttr) {
Diag(rawAttr->getLoc(), diag::warn_attribute_ignored,
rawAttr->getName()->getName());
}
+
+void Sema::HandleAnnotateAttribute(Decl *d, AttributeList *rawAttr) {
+ // check the attribute arguments.
+ if (rawAttr->getNumArgs() != 1) {
+ Diag(rawAttr->getLoc(), diag::err_attribute_wrong_number_arguments,
+ std::string("1"));
+ return;
+ }
+ Expr *argExpr = static_cast<Expr *>(rawAttr->getArg(0));
+ StringLiteral *SE = dyn_cast<StringLiteral>(argExpr);
+ // Make sure that there is a string literal as the annotation's single
+ // argument.
+ if (!SE) {
+ Diag(rawAttr->getLoc(), diag::err_attribute_annotate_no_string);
+ return;
+ }
+ d->addAttr(new AnnotateAttr(std::string(SE->getStrData(),
+ SE->getByteLength())));
+}
+
void Sema::HandleAlignedAttribute(Decl *d, AttributeList *rawAttr)
{
// check the attribute arguments.
diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h
index 96281a97c8..fea0b404df 100644
--- a/include/clang/AST/Attr.h
+++ b/include/clang/AST/Attr.h
@@ -15,6 +15,7 @@
#define LLVM_CLANG_AST_ATTR_H
#include <cassert>
+#include <string>
namespace clang {
@@ -23,7 +24,8 @@ class Attr {
public:
enum Kind {
Aligned,
- Packed
+ Packed,
+ Annotate
};
private:
@@ -80,6 +82,20 @@ public:
static bool classof(const AlignedAttr *A) { return true; }
};
+class AnnotateAttr : public Attr {
+ std::string Annotation;
+public:
+ AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {}
+
+ const std::string& getAnnotation() const { return Annotation; }
+
+ // Implement isa/cast/dyncast/etc.
+ static bool classof(const Attr *A) {
+ return A->getKind() == Annotate;
+ }
+ static bool classof(const AnnotateAttr *A) { return true; }
+};
+
} // end namespace clang
#endif
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index 882ca92e51..902ecc217e 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -581,10 +581,12 @@ DIAG(err_attribute_address_space_not_int, ERROR,
"address space attribute requires an integer constant")
DIAG(err_attribute_address_multiple_qualifiers, ERROR,
"multiple address spaces specified for type")
+DIAG(err_attribute_annotate_no_string, ERROR,
+ "argument to annotate attribute was not a string literal")
DIAG(warn_attribute_ignored, WARNING,
- "'%0' attribute ignored")
+ "'%0' attribute ignored")
DIAG(warn_attribute_ignored_for_field_of_type, WARNING,
- "'%0' attribute ignored for field of type '%1'")
+ "'%0' attribute ignored for field of type '%1'")
// Function Parameter Semantic Analysis.
DIAG(err_param_with_void_type, ERROR,
diff --git a/include/clang/Parse/AttributeList.h b/include/clang/Parse/AttributeList.h
index 137d7c6d88..d627f10b86 100644
--- a/include/clang/Parse/AttributeList.h
+++ b/include/clang/Parse/AttributeList.h
@@ -47,7 +47,8 @@ public:
AT_ocu_vector_type,
AT_address_space,
AT_aligned,
- AT_packed
+ AT_packed,
+ AT_annotate
};
IdentifierInfo *getName() const { return AttrName; }