[PATCH] Make AnnotateAttr keeps pointer to StringLiteral instead of raw string.
Jarosław Rosiek
jaroslaw.rosiek at interia.pl
Sun Aug 18 15:10:26 PDT 2013
Hi,
This is my first patch here, so please be gentle :)
This change enables usage of standard lexing/parsing/diagnosics
infrastructure during processing of annotation string. This may be
useful when someone implements a tool that processes metadata provided
in annotations and this metadata requires further parsing (in a manner
similar to current treatment of _Pragma directive).
Thanks,
Jarek
-------------- next part --------------
From 505e3d66d2236d012ad69b55700652d62ade8114 Mon Sep 17 00:00:00 2001
From: Jaroslaw Rosiek <Jaroslaw.Rosiek at sabre.com>
Date: Sun, 18 Aug 2013 20:53:12 +0200
Subject: [PATCH] Make AnnotateAttr keeps pointer to StringLiteral instead of
raw string.
This change enables usage of standard lexing/parsing/diagnosics
infrastructure during processing of annotation string.
---
include/clang/AST/Attr.h | 1 +
include/clang/Basic/Attr.td | 3 ++-
lib/CodeGen/CodeGenFunction.cpp | 4 ++--
lib/CodeGen/CodeGenModule.cpp | 2 +-
lib/Sema/SemaCodeComplete.cpp | 2 +-
lib/Sema/SemaDecl.cpp | 3 ++-
lib/Sema/SemaDeclAttr.cpp | 4 ++--
.../Checkers/DirectIvarAssignment.cpp | 4 ++--
.../Checkers/IvarInvalidationChecker.cpp | 4 ++--
tools/libclang/CIndex.cpp | 2 +-
utils/TableGen/ClangAttrEmitter.cpp | 4 ++++
11 files changed, 20 insertions(+), 13 deletions(-)
diff --git include/clang/AST/Attr.h include/clang/AST/Attr.h
index e07e84a..2fe2184 100644
--- include/clang/AST/Attr.h
+++ include/clang/AST/Attr.h
@@ -35,6 +35,7 @@ namespace clang {
class Expr;
class QualType;
class FunctionDecl;
+ class StringLiteral;
class TypeSourceInfo;
/// Attr - This represents one attribute.
diff --git include/clang/Basic/Attr.td include/clang/Basic/Attr.td
index f81098d..dd22ecb 100644
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -55,6 +55,7 @@ class FunctionArgument<string name> : Argument<name>;
class TypeArgument<string name> : Argument<name>;
class UnsignedArgument<string name> : Argument<name>;
class SourceLocArgument<string name> : Argument<name>;
+class StringLiteralArgument<string name> : Argument<name>;
class VariadicUnsignedArgument<string name> : Argument<name>;
class VariadicExprArgument<string name> : Argument<name>;
@@ -202,7 +203,7 @@ def AnalyzerNoReturn : InheritableAttr {
def Annotate : InheritableParamAttr {
let Spellings = [GNU<"annotate">];
- let Args = [StringArgument<"Annotation">];
+ let Args = [StringLiteralArgument<"AnnotationLiteral">];
}
def AsmLabel : InheritableAttr {
diff --git lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.cpp
index addc25f..d0baa79 100644
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1436,7 +1436,7 @@ void CodeGenFunction::EmitVarAnnotations(const VarDecl *D, llvm::Value *V) {
ae = D->specific_attr_end<AnnotateAttr>(); ai != ae; ++ai)
EmitAnnotationCall(CGM.getIntrinsic(llvm::Intrinsic::var_annotation),
Builder.CreateBitCast(V, CGM.Int8PtrTy, V->getName()),
- (*ai)->getAnnotation(), D->getLocation());
+ (*ai)->getAnnotationLiteral()->getString(), D->getLocation());
}
llvm::Value *CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
@@ -1454,7 +1454,7 @@ llvm::Value *CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
// itself.
if (VTy != CGM.Int8PtrTy)
V = Builder.Insert(new llvm::BitCastInst(V, CGM.Int8PtrTy));
- V = EmitAnnotationCall(F, V, (*ai)->getAnnotation(), D->getLocation());
+ V = EmitAnnotationCall(F, V, (*ai)->getAnnotationLiteral()->getString(), D->getLocation());
V = Builder.CreateBitCast(V, VTy);
}
diff --git lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.cpp
index dc0ffc1..a12e9c1 100644
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1010,7 +1010,7 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
const AnnotateAttr *AA,
SourceLocation L) {
// Get the globals for file name, annotation, and the line number.
- llvm::Constant *AnnoGV = EmitAnnotationString(AA->getAnnotation()),
+ llvm::Constant *AnnoGV = EmitAnnotationString(AA->getAnnotationLiteral()->getString()),
*UnitGV = EmitAnnotationUnit(L),
*LineNoCst = EmitAnnotationLineNo(L);
diff --git lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaCodeComplete.cpp
index b415993..8a80554 100644
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -2643,7 +2643,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
for (Decl::attr_iterator i = ND->attr_begin(); i != ND->attr_end(); ++i) {
if (AnnotateAttr *Attr = dyn_cast_or_null<AnnotateAttr>(*i)) {
- Result.AddAnnotation(Result.getAllocator().CopyString(Attr->getAnnotation()));
+ Result.AddAnnotation(Result.getAllocator().CopyString(Attr->getAnnotationLiteral()->getString()));
}
}
diff --git lib/Sema/SemaDecl.cpp lib/Sema/SemaDecl.cpp
index 9dad47f..9eac92a 100644
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1805,7 +1805,8 @@ DeclHasAttr(const Decl *D, const Attr *A) {
for (Decl::attr_iterator i = D->attr_begin(), e = D->attr_end(); i != e; ++i)
if ((*i)->getKind() == A->getKind()) {
if (Ann) {
- if (Ann->getAnnotation() == cast<AnnotateAttr>(*i)->getAnnotation())
+ if (Ann->getAnnotationLiteral()->getString() ==
+ cast<AnnotateAttr>(*i)->getAnnotationLiteral()->getString())
return true;
continue;
}
diff --git lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaDeclAttr.cpp
index a82b396..5dec03e 100644
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3389,12 +3389,12 @@ static void handleAnnotateAttr(Sema &S, Decl *D, const AttributeList &Attr) {
for (specific_attr_iterator<AnnotateAttr>
i = D->specific_attr_begin<AnnotateAttr>(),
e = D->specific_attr_end<AnnotateAttr>(); i != e; ++i) {
- if ((*i)->getAnnotation() == SE->getString())
+ if ((*i)->getAnnotationLiteral()->getString() == SE->getString())
return;
}
D->addAttr(::new (S.Context)
- AnnotateAttr(Attr.getRange(), S.Context, SE->getString(),
+ AnnotateAttr(Attr.getRange(), S.Context, SE,
Attr.getAttributeSpellingListIndex()));
}
diff --git lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
index b43dc18..5fe29fd 100644
--- lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
+++ lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp
@@ -162,7 +162,7 @@ static bool isAnnotatedToAllowDirectAssignment(const Decl *D) {
AI = D->specific_attr_begin<AnnotateAttr>(),
AE = D->specific_attr_end<AnnotateAttr>(); AI != AE; ++AI) {
const AnnotateAttr *Ann = *AI;
- if (Ann->getAnnotation() ==
+ if (Ann->getAnnotationLiteral()->getString() ==
"objc_allow_direct_instance_variable_assignment")
return true;
}
@@ -230,7 +230,7 @@ static bool AttrFilter(const ObjCMethodDecl *M) {
AE = M->specific_attr_end<AnnotateAttr>();
AI != AE; ++AI) {
const AnnotateAttr *Ann = *AI;
- if (Ann->getAnnotation() == "objc_no_direct_instance_variable_assignment")
+ if (Ann->getAnnotationLiteral()->getString() == "objc_no_direct_instance_variable_assignment")
return false;
}
return true;
diff --git lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
index cc940be..b3464cd 100644
--- lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
@@ -228,10 +228,10 @@ static bool isInvalidationMethod(const ObjCMethodDecl *M, bool LookForPartial) {
AE = M->specific_attr_end<AnnotateAttr>(); AI != AE; ++AI) {
const AnnotateAttr *Ann = *AI;
if (!LookForPartial &&
- Ann->getAnnotation() == "objc_instance_variable_invalidator")
+ Ann->getAnnotationLiteral()->getString() == "objc_instance_variable_invalidator")
return true;
if (LookForPartial &&
- Ann->getAnnotation() == "objc_instance_variable_invalidator_partial")
+ Ann->getAnnotationLiteral()->getString() == "objc_instance_variable_invalidator_partial")
return true;
}
return false;
diff --git tools/libclang/CIndex.cpp tools/libclang/CIndex.cpp
index c89a121..fe08fe5 100644
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3341,7 +3341,7 @@ CXString clang_getCursorSpelling(CXCursor C) {
if (C.kind == CXCursor_AnnotateAttr) {
const AnnotateAttr *AA = cast<AnnotateAttr>(cxcursor::getCursorAttr(C));
- return cxstring::createDup(AA->getAnnotation());
+ return cxstring::createDup(AA->getAnnotationLiteral()->getString());
}
if (C.kind == CXCursor_AsmLabelAttr) {
diff --git utils/TableGen/ClangAttrEmitter.cpp utils/TableGen/ClangAttrEmitter.cpp
index e8312c6..7c9bed4 100644
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -48,6 +48,7 @@ static std::string ReadPCHRecord(StringRef type) {
+ std::string(type, 0, type.size()-1) + ">(F, Record[Idx++])")
.Case("QualType", "getLocalType(F, Record[Idx++])")
.Case("Expr *", "ReadExpr(F)")
+ .Case("StringLiteral *", "cast_or_null<StringLiteral>(ReadExpr(F))")
.Case("IdentifierInfo *", "GetIdentifierInfo(F, Record, Idx)")
.Case("SourceLocation", "ReadSourceLocation(F, Record, Idx)")
.Default("Record[Idx++]");
@@ -60,6 +61,7 @@ static std::string WritePCHRecord(StringRef type, StringRef name) {
", Record);\n")
.Case("QualType", "AddTypeRef(" + std::string(name) + ", Record);\n")
.Case("Expr *", "AddStmt(" + std::string(name) + ");\n")
+ .Case("StringLiteral *", "AddStmt(" + std::string(name) + ");\n")
.Case("IdentifierInfo *",
"AddIdentifierRef(" + std::string(name) + ", Record);\n")
.Case("SourceLocation",
@@ -712,6 +714,8 @@ static Argument *createArgument(Record &Arg, StringRef Attr,
Ptr = new SimpleArgument(Arg, Attr, "FunctionDecl *");
else if (ArgName == "IdentifierArgument")
Ptr = new SimpleArgument(Arg, Attr, "IdentifierInfo *");
+ else if (ArgName == "StringLiteralArgument")
+ Ptr = new SimpleArgument(Arg, Attr, "StringLiteral *");
else if (ArgName == "BoolArgument") Ptr = new SimpleArgument(Arg, Attr,
"bool");
else if (ArgName == "IntArgument") Ptr = new SimpleArgument(Arg, Attr, "int");
--
1.7.9.5
More information about the cfe-commits
mailing list