[cfe-commits] r47451 - in /cfe/trunk: Parse/AttributeList.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/Attr.h include/clang/Basic/DiagnosticKinds.def include/clang/Parse/AttributeList.h
Nate Begeman
natebegeman at mac.com
Thu Feb 21 11:30:49 PST 2008
Author: sampo
Date: Thu Feb 21 13:30:49 2008
New Revision: 47451
URL: http://llvm.org/viewvc/llvm-project?rev=47451&view=rev
Log:
Handle __attribute__((annotate("string")))
Modified:
cfe/trunk/Parse/AttributeList.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/include/clang/Parse/AttributeList.h
Modified: cfe/trunk/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/AttributeList.cpp?rev=47451&r1=47450&r2=47451&view=diff
==============================================================================
--- cfe/trunk/Parse/AttributeList.cpp (original)
+++ cfe/trunk/Parse/AttributeList.cpp Thu Feb 21 13:30:49 2008
@@ -57,6 +57,9 @@
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;
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=47451&r1=47450&r2=47451&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Thu Feb 21 13:30:49 2008
@@ -271,6 +271,7 @@
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);
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=47451&r1=47450&r2=47451&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Feb 21 13:30:49 2008
@@ -1777,6 +1777,9 @@
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 @@
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 @@
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.
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=47451&r1=47450&r2=47451&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Thu Feb 21 13:30:49 2008
@@ -15,6 +15,7 @@
#define LLVM_CLANG_AST_ATTR_H
#include <cassert>
+#include <string>
namespace clang {
@@ -23,7 +24,8 @@
public:
enum Kind {
Aligned,
- Packed
+ Packed,
+ Annotate
};
private:
@@ -80,6 +82,20 @@
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
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=47451&r1=47450&r2=47451&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Thu Feb 21 13:30:49 2008
@@ -581,10 +581,12 @@
"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,
Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=47451&r1=47450&r2=47451&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Thu Feb 21 13:30:49 2008
@@ -47,7 +47,8 @@
AT_ocu_vector_type,
AT_address_space,
AT_aligned,
- AT_packed
+ AT_packed,
+ AT_annotate
};
IdentifierInfo *getName() const { return AttrName; }
More information about the cfe-commits
mailing list