Implement first TD-based usage of attributes.

Currently, there are two effective changes:

 - Attr::Kind has been changed to attr::Kind, in a separate namespace
   rather than the Attr class. This is because the enumerator needs to
   be visible to parse.
 - The class definitions for the C++0x attributes other than aligned are
   generated by TableGen.

The specific classes generated by TableGen are controlled by an array in
TableGen (see the accompanying commit to the LLVM repository). I will be
expanding the amount of code generated as I develop the new attributes system
while initially keeping it confined to these attributes.

llvm-svn: 106172
This commit is contained in:
Alexis Hunt 2010-06-16 23:43:53 +00:00
parent 77a4a56251
commit 344393e9cf
11 changed files with 543 additions and 206 deletions

View File

@ -16,6 +16,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/ADT/StringRef.h"
#include "clang/Basic/AttrKinds.h"
#include <cassert>
#include <cstring>
#include <algorithm>
@ -41,75 +42,9 @@ namespace clang {
/// Attr - This represents one attribute.
class Attr {
public:
enum Kind {
Alias,
Aligned,
AlignMac68k,
AlwaysInline,
AnalyzerNoReturn, // Clang-specific.
Annotate,
AsmLabel, // Represent GCC asm label extension.
BaseCheck,
Blocks,
CDecl,
Cleanup,
Const,
Constructor,
Deprecated,
Destructor,
FastCall,
Final,
Format,
FormatArg,
GNUInline,
Hiding,
IBOutletKind, // Clang-specific. Use "Kind" suffix to not conflict w/ macro.
IBOutletCollectionKind, // Clang-specific.
IBActionKind, // Clang-specific. Use "Kind" suffix to not conflict w/ macro.
Malloc,
MaxFieldAlignment,
NoDebug,
NoInline,
NonNull,
NoReturn,
NoThrow,
ObjCException,
ObjCNSObject,
Override,
CFReturnsRetained, // Clang/Checker-specific.
CFReturnsNotRetained, // Clang/Checker-specific.
NSReturnsRetained, // Clang/Checker-specific.
NSReturnsNotRetained, // Clang/Checker-specific.
Overloadable, // Clang-specific
Packed,
Pure,
Regparm,
ReqdWorkGroupSize, // OpenCL-specific
Section,
Sentinel,
StdCall,
ThisCall,
TransparentUnion,
Unavailable,
Unused,
Used,
Visibility,
WarnUnusedResult,
Weak,
WeakImport,
WeakRef,
FIRST_TARGET_ATTRIBUTE,
DLLExport,
DLLImport,
MSP430Interrupt,
X86ForceAlignArgPointer
};
private:
Attr *Next;
Kind AttrKind;
attr::Kind AttrKind;
bool Inherited : 1;
protected:
@ -122,7 +57,7 @@ protected:
}
protected:
Attr(Kind AK) : Next(0), AttrKind(AK), Inherited(false) {}
Attr(attr::Kind AK) : Next(0), AttrKind(AK), Inherited(false) {}
virtual ~Attr() {
assert(Next == 0 && "Destroy didn't work");
}
@ -133,7 +68,7 @@ public:
/// declarations.
virtual bool isMerged() const { return true; }
Kind getKind() const { return AttrKind; }
attr::Kind getKind() const { return AttrKind; }
Attr *getNext() { return Next; }
const Attr *getNext() const { return Next; }
@ -164,12 +99,14 @@ public:
static bool classof(const Attr *) { return true; }
};
#include "clang/AST/Attrs.inc"
class AttrWithString : public Attr {
private:
const char *Str;
unsigned StrLen;
protected:
AttrWithString(Attr::Kind AK, ASTContext &C, llvm::StringRef s);
AttrWithString(attr::Kind AK, ASTContext &C, llvm::StringRef s);
llvm::StringRef getString() const { return llvm::StringRef(Str, StrLen); }
void ReplaceString(ASTContext &C, llvm::StringRef newS);
public:
@ -179,9 +116,9 @@ public:
#define DEF_SIMPLE_ATTR(ATTR) \
class ATTR##Attr : public Attr { \
public: \
ATTR##Attr() : Attr(ATTR) {} \
ATTR##Attr() : Attr(attr::ATTR) {} \
virtual Attr *clone(ASTContext &C) const; \
static bool classof(const Attr *A) { return A->getKind() == ATTR; } \
static bool classof(const Attr *A) { return A->getKind() == attr::ATTR; } \
static bool classof(const ATTR##Attr *A) { return true; } \
}
@ -194,7 +131,7 @@ class MaxFieldAlignmentAttr : public Attr {
public:
MaxFieldAlignmentAttr(unsigned alignment)
: Attr(MaxFieldAlignment), Alignment(alignment) {}
: Attr(attr::MaxFieldAlignment), Alignment(alignment) {}
/// getAlignment - The specified alignment in bits.
unsigned getAlignment() const { return Alignment; }
@ -203,7 +140,7 @@ public:
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == MaxFieldAlignment;
return A->getKind() == attr::MaxFieldAlignment;
}
static bool classof(const MaxFieldAlignmentAttr *A) { return true; }
};
@ -214,7 +151,7 @@ class AlignedAttr : public Attr {
unsigned Alignment;
public:
AlignedAttr(unsigned alignment)
: Attr(Aligned), Alignment(alignment) {}
: Attr(attr::Aligned), Alignment(alignment) {}
/// getAlignment - The specified alignment in bits.
unsigned getAlignment() const { return Alignment; }
@ -232,7 +169,7 @@ public:
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == Aligned;
return A->getKind() == attr::Aligned;
}
static bool classof(const AlignedAttr *A) { return true; }
};
@ -240,7 +177,7 @@ public:
class AnnotateAttr : public AttrWithString {
public:
AnnotateAttr(ASTContext &C, llvm::StringRef ann)
: AttrWithString(Annotate, C, ann) {}
: AttrWithString(attr::Annotate, C, ann) {}
llvm::StringRef getAnnotation() const { return getString(); }
@ -248,7 +185,7 @@ public:
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == Annotate;
return A->getKind() == attr::Annotate;
}
static bool classof(const AnnotateAttr *A) { return true; }
};
@ -256,7 +193,7 @@ public:
class AsmLabelAttr : public AttrWithString {
public:
AsmLabelAttr(ASTContext &C, llvm::StringRef L)
: AttrWithString(AsmLabel, C, L) {}
: AttrWithString(attr::AsmLabel, C, L) {}
llvm::StringRef getLabel() const { return getString(); }
@ -264,7 +201,7 @@ public:
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == AsmLabel;
return A->getKind() == attr::AsmLabel;
}
static bool classof(const AsmLabelAttr *A) { return true; }
};
@ -274,54 +211,56 @@ DEF_SIMPLE_ATTR(AlwaysInline);
class AliasAttr : public AttrWithString {
public:
AliasAttr(ASTContext &C, llvm::StringRef aliasee)
: AttrWithString(Alias, C, aliasee) {}
: AttrWithString(attr::Alias, C, aliasee) {}
llvm::StringRef getAliasee() const { return getString(); }
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Alias; }
static bool classof(const Attr *A) { return A->getKind() == attr::Alias; }
static bool classof(const AliasAttr *A) { return true; }
};
class ConstructorAttr : public Attr {
int priority;
public:
ConstructorAttr(int p) : Attr(Constructor), priority(p) {}
ConstructorAttr(int p) : Attr(attr::Constructor), priority(p) {}
int getPriority() const { return priority; }
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Constructor; }
static bool classof(const Attr *A)
{ return A->getKind() == attr::Constructor; }
static bool classof(const ConstructorAttr *A) { return true; }
};
class DestructorAttr : public Attr {
int priority;
public:
DestructorAttr(int p) : Attr(Destructor), priority(p) {}
DestructorAttr(int p) : Attr(attr::Destructor), priority(p) {}
int getPriority() const { return priority; }
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Destructor; }
static bool classof(const Attr *A)
{ return A->getKind() == attr::Destructor; }
static bool classof(const DestructorAttr *A) { return true; }
};
class IBOutletAttr : public Attr {
public:
IBOutletAttr() : Attr(IBOutletKind) {}
IBOutletAttr() : Attr(attr::IBOutlet) {}
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == IBOutletKind;
return A->getKind() == attr::IBOutlet;
}
static bool classof(const IBOutletAttr *A) { return true; }
};
@ -330,7 +269,7 @@ class IBOutletCollectionAttr : public Attr {
const ObjCInterfaceDecl *D;
public:
IBOutletCollectionAttr(const ObjCInterfaceDecl *d = 0)
: Attr(IBOutletCollectionKind), D(d) {}
: Attr(attr::IBOutletCollection), D(d) {}
const ObjCInterfaceDecl *getClass() const { return D; }
@ -338,27 +277,26 @@ public:
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == IBOutletCollectionKind;
return A->getKind() == attr::IBOutletCollection;
}
static bool classof(const IBOutletCollectionAttr *A) { return true; }
};
class IBActionAttr : public Attr {
public:
IBActionAttr() : Attr(IBActionKind) {}
IBActionAttr() : Attr(attr::IBAction) {}
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == IBActionKind;
return A->getKind() == attr::IBAction;
}
static bool classof(const IBActionAttr *A) { return true; }
};
DEF_SIMPLE_ATTR(AnalyzerNoReturn);
DEF_SIMPLE_ATTR(Deprecated);
DEF_SIMPLE_ATTR(Final);
DEF_SIMPLE_ATTR(GNUInline);
DEF_SIMPLE_ATTR(Malloc);
DEF_SIMPLE_ATTR(NoReturn);
@ -366,7 +304,7 @@ DEF_SIMPLE_ATTR(NoReturn);
class SectionAttr : public AttrWithString {
public:
SectionAttr(ASTContext &C, llvm::StringRef N)
: AttrWithString(Section, C, N) {}
: AttrWithString(attr::Section, C, N) {}
llvm::StringRef getName() const { return getString(); }
@ -374,7 +312,7 @@ public:
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == Section;
return A->getKind() == attr::Section;
}
static bool classof(const SectionAttr *A) { return true; }
};
@ -408,7 +346,7 @@ public:
virtual Attr *clone(ASTContext &C) const;
static bool classof(const Attr *A) { return A->getKind() == NonNull; }
static bool classof(const Attr *A) { return A->getKind() == attr::NonNull; }
static bool classof(const NonNullAttr *A) { return true; }
};
@ -416,7 +354,7 @@ class FormatAttr : public AttrWithString {
int formatIdx, firstArg;
public:
FormatAttr(ASTContext &C, llvm::StringRef type, int idx, int first)
: AttrWithString(Format, C, type), formatIdx(idx), firstArg(first) {}
: AttrWithString(attr::Format, C, type), formatIdx(idx), firstArg(first) {}
llvm::StringRef getType() const { return getString(); }
void setType(ASTContext &C, llvm::StringRef type);
@ -426,27 +364,27 @@ public:
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Format; }
static bool classof(const Attr *A) { return A->getKind() == attr::Format; }
static bool classof(const FormatAttr *A) { return true; }
};
class FormatArgAttr : public Attr {
int formatIdx;
public:
FormatArgAttr(int idx) : Attr(FormatArg), formatIdx(idx) {}
FormatArgAttr(int idx) : Attr(attr::FormatArg), formatIdx(idx) {}
int getFormatIdx() const { return formatIdx; }
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == FormatArg; }
static bool classof(const Attr *A) { return A->getKind() == attr::FormatArg; }
static bool classof(const FormatArgAttr *A) { return true; }
};
class SentinelAttr : public Attr {
int sentinel, NullPos;
public:
SentinelAttr(int sentinel_val, int nullPos) : Attr(Sentinel),
SentinelAttr(int sentinel_val, int nullPos) : Attr(attr::Sentinel),
sentinel(sentinel_val), NullPos(nullPos) {}
int getSentinel() const { return sentinel; }
int getNullPos() const { return NullPos; }
@ -454,7 +392,7 @@ public:
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Sentinel; }
static bool classof(const Attr *A) { return A->getKind() == attr::Sentinel; }
static bool classof(const SentinelAttr *A) { return true; }
};
@ -469,7 +407,7 @@ public:
private:
VisibilityTypes VisibilityType;
public:
VisibilityAttr(VisibilityTypes v) : Attr(Visibility),
VisibilityAttr(VisibilityTypes v) : Attr(attr::Visibility),
VisibilityType(v) {}
VisibilityTypes getVisibility() const { return VisibilityType; }
@ -477,7 +415,8 @@ public:
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Visibility; }
static bool classof(const Attr *A)
{ return A->getKind() == attr::Visibility; }
static bool classof(const VisibilityAttr *A) { return true; }
};
@ -491,13 +430,14 @@ DEF_SIMPLE_ATTR(ObjCException);
class OverloadableAttr : public Attr {
public:
OverloadableAttr() : Attr(Overloadable) { }
OverloadableAttr() : Attr(attr::Overloadable) { }
virtual bool isMerged() const { return false; }
virtual Attr *clone(ASTContext &C) const;
static bool classof(const Attr *A) { return A->getKind() == Overloadable; }
static bool classof(const Attr *A)
{ return A->getKind() == attr::Overloadable; }
static bool classof(const OverloadableAttr *) { return true; }
};
@ -509,14 +449,14 @@ public:
private:
BlocksAttrTypes BlocksAttrType;
public:
BlocksAttr(BlocksAttrTypes t) : Attr(Blocks), BlocksAttrType(t) {}
BlocksAttr(BlocksAttrTypes t) : Attr(attr::Blocks), BlocksAttrType(t) {}
BlocksAttrTypes getType() const { return BlocksAttrType; }
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Blocks; }
static bool classof(const Attr *A) { return A->getKind() == attr::Blocks; }
static bool classof(const BlocksAttr *A) { return true; }
};
@ -526,14 +466,14 @@ class CleanupAttr : public Attr {
FunctionDecl *FD;
public:
CleanupAttr(FunctionDecl *fd) : Attr(Cleanup), FD(fd) {}
CleanupAttr(FunctionDecl *fd) : Attr(attr::Cleanup), FD(fd) {}
const FunctionDecl *getFunctionDecl() const { return FD; }
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Cleanup; }
static bool classof(const Attr *A) { return A->getKind() == attr::Cleanup; }
static bool classof(const CleanupAttr *A) { return true; }
};
@ -545,14 +485,14 @@ class RegparmAttr : public Attr {
unsigned NumParams;
public:
RegparmAttr(unsigned np) : Attr(Regparm), NumParams(np) {}
RegparmAttr(unsigned np) : Attr(attr::Regparm), NumParams(np) {}
unsigned getNumParams() const { return NumParams; }
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Regparm; }
static bool classof(const Attr *A) { return A->getKind() == attr::Regparm; }
static bool classof(const RegparmAttr *A) { return true; }
};
@ -560,7 +500,7 @@ class ReqdWorkGroupSizeAttr : public Attr {
unsigned X, Y, Z;
public:
ReqdWorkGroupSizeAttr(unsigned X, unsigned Y, unsigned Z)
: Attr(ReqdWorkGroupSize), X(X), Y(Y), Z(Z) {}
: Attr(attr::ReqdWorkGroupSize), X(X), Y(Y), Z(Z) {}
unsigned getXDim() const { return X; }
unsigned getYDim() const { return Y; }
@ -570,7 +510,7 @@ public:
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == ReqdWorkGroupSize;
return A->getKind() == attr::ReqdWorkGroupSize;
}
static bool classof(const ReqdWorkGroupSizeAttr *A) { return true; }
};
@ -581,11 +521,6 @@ DEF_SIMPLE_ATTR(CFReturnsRetained);
DEF_SIMPLE_ATTR(NSReturnsNotRetained);
DEF_SIMPLE_ATTR(NSReturnsRetained);
// C++0x member checking attributes.
DEF_SIMPLE_ATTR(BaseCheck);
DEF_SIMPLE_ATTR(Hiding);
DEF_SIMPLE_ATTR(Override);
// Target-specific attributes
DEF_SIMPLE_ATTR(DLLImport);
DEF_SIMPLE_ATTR(DLLExport);
@ -594,14 +529,15 @@ class MSP430InterruptAttr : public Attr {
unsigned Number;
public:
MSP430InterruptAttr(unsigned n) : Attr(MSP430Interrupt), Number(n) {}
MSP430InterruptAttr(unsigned n) : Attr(attr::MSP430Interrupt), Number(n) {}
unsigned getNumber() const { return Number; }
virtual Attr *clone(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == MSP430Interrupt; }
static bool classof(const Attr *A)
{ return A->getKind() == attr::MSP430Interrupt; }
static bool classof(const MSP430InterruptAttr *A) { return true; }
};

View File

@ -1,17 +1,23 @@
CLANG_LEVEL := ../../..
BUILT_SOURCES = StmtNodes.inc DeclNodes.inc
TD_SRC_DIR = $(PROJ_SRC_DIR)/../Basic
BUILT_SOURCES = Attrs.inc StmtNodes.inc DeclNodes.inc
TABLEGEN_INC_FILES_COMMON = 1
include $(CLANG_LEVEL)/Makefile
INPUT_TDS = $(TD_SRC_DIR)/StmtNodes.td $(TD_SRC_DIR)/DeclNodes.td
$(ObjDir)/Attrs.inc.tmp : $(TD_SRC_DIR)/Attr.td $(TBLGEN) \
$(ObjDir)/.dir
$(Echo) "Building Clang attribute classes with tblgen"
$(Verb) $(TableGen) -gen-clang-attr-classes -o $(call SYSPATH, $@) \
-I $(PROJ_SRC_DIR)/../../ $<
$(ObjDir)/StmtNodes.inc.tmp : $(TD_SRC_DIR)/StmtNodes.td $(TBLGEN) $(ObjDir)/.dir
$(ObjDir)/StmtNodes.inc.tmp : $(TD_SRC_DIR)/StmtNodes.td $(TBLGEN) \
$(ObjDir)/.dir
$(Echo) "Building Clang statement node tables with tblgen"
$(Verb) $(TableGen) -gen-clang-stmt-nodes -o $(call SYSPATH, $@) $<
$(ObjDir)/DeclNodes.inc.tmp : $(TD_SRC_DIR)/DeclNodes.td $(TBLGEN) $(ObjDir)/.dir
$(ObjDir)/DeclNodes.inc.tmp : $(TD_SRC_DIR)/DeclNodes.td $(TBLGEN) \
$(ObjDir)/.dir
$(Echo) "Building Clang declaration node tables with tblgen"
$(Verb) $(TableGen) -gen-clang-decl-nodes -o $(call SYSPATH, $@) $<

View File

@ -0,0 +1,357 @@
////////////////////////////////////////////////////////////////////////////////
// Note: This file is a work in progress. Please update it only if you believe
// there is an obvious error; otherwise please check with Sean Hunt. He can
// be reached at rideau3@gmail.com.
////////////////////////////////////////////////////////////////////////////////
class AttrSubject;
include "clang/Basic/DeclNodes.td"
include "clang/Basic/StmtNodes.td"
// A subset-subject is an AttrSubject constrained to operate only on some subset
// of that subject.
//
// The description is used in output messages to specify what the subject
// represents. FIXME: Deal with translation issues.
//
// The code fragment is a boolean expression that will confirm that the subject
// meets the requirements; the subject will have the name S, and will have the
// type specified by the base. It should be a simple boolean expression.
class SubsetSubject<AttrSubject base, string description, code check>
: AttrSubject {
AttrSubject Base = base;
string Description = description;
code CheckCode = check;
}
def NormalVar : SubsetSubject<Var, "non-register, non-parameter variable",
[{S->getStorageClass() != VarDecl::Register &&
S->getKind() != Decl::ImplicitParam
S->getKind() != Decl::ParmVar
S->getKind() != Decl::NonTypeTemplateParm}]>;
def CXXVirtualMethod : SubsetSubject<CXXRecord, "virtual member function",
[{S->isVirtual()}]>;
def NonBitField : SubsetSubject<Field, "non-bit field",
[{!S->isBitField()}]>;
class Argument<string name> {
string Name = name;
}
class IdentifierArgument<string name> : Argument<name>;
class IntArgument<string name> : Argument<name>;
class StringArgument<string name> : Argument<name>;
class ExprArgument<string name> : Argument<name>;
class FunctionArgument<string name> : Argument<name>;
class ObjCInterfaceArgument<string name> : Argument<name>;
class UnsignedIntArgument<string name> : Argument<name>;
class UnsignedIntOrTypeArgument<string name> : Argument<name>;
class DefaultIntArgument<string name, int default> : IntArgument<name> {
int Default = default;
}
class VariadicArgument<Argument arg> : Argument<arg.Name> {
Argument VariadicArg = arg;
}
class Attr {
list<string> Spellings;
list<AttrSubject> Subjects;
list<Argument> Args = [];
list<string> Namespaces = [];
list<string> Aliases = [];
bit DoNotEmit = 1;
}
//
// Attributes begin here
//
def Alias : Attr {
let Spellings = ["alias"];
let Args = [StringArgument<"AliasName">];
}
def Aligned : Attr {
let Spellings = ["align", "aligned"];
let Subjects = [NonBitField, NormalVar, Tag];
let Args = [UnsignedIntOrTypeArgument<"Alignment">];
let Namespaces = ["", "std"];
}
def AlignMac68k : Attr {
let Spellings = [];
}
def AlwaysInline : Attr {
let Spellings = ["always_inline"];
}
def AnalyzerNoReturn : Attr {
let Spellings = ["analyzer_noreturn"];
}
def Annotate : Attr {
let Spellings = ["annotate"];
let Args = [StringArgument<"Annotation">];
}
def AsmLabel : Attr {
let Spellings = [];
let Args = [StringArgument<"Label">];
}
def BaseCheck : Attr {
let Spellings = ["base_check"];
let Subjects = [CXXRecord];
let Namespaces = ["", "std"];
let DoNotEmit = 0;
}
def Blocks : Attr {
let Spellings = ["blocks"];
let Args = [IdentifierArgument<"Type">];
}
def CarriesDependency : Attr {
let Spellings = ["carries_dependency"];
let Subjects = [ParmVar, Function];
let Namespaces = ["", "std"];
let DoNotEmit = 0;
}
def CDecl : Attr {
let Spellings = ["cdecl", "__cdecl"];
}
def CFReturnsRetained : Attr {
let Spellings = ["cf_returns_retained"];
}
def CFReturnsNotRetained : Attr {
let Spellings = ["cf_returns_not_retained"];
}
def Cleanup : Attr {
let Spellings = ["cleanup"];
let Args = [FunctionArgument<"FunctionDecl">];
}
def Const : Attr {
let Spellings = ["const"];
}
def Constructor : Attr {
let Spellings = ["constructor"];
let Args = [IntArgument<"Priority">];
}
def Deprecated : Attr {
let Spellings = ["deprecated"];
}
def Destructor : Attr {
let Spellings = ["destructor"];
let Args = [IntArgument<"Priority">];
}
def DLLExport : Attr {
let Spellings = ["dllexport"];
}
def DLLImport : Attr {
let Spellings = ["dllimport"];
}
def FastCall : Attr {
let Spellings = ["fastcall", "__fastcall"];
}
def Final : Attr {
let Spellings = ["final"];
let Subjects = [CXXRecord, CXXVirtualMethod];
let Namespaces = ["", "std"];
let DoNotEmit = 0;
}
def Format : Attr {
let Spellings = ["format"];
let Args = [StringArgument<"Type">, IntArgument<"FormatIdx">,
IntArgument<"FirstArg">];
}
def FormatArg : Attr {
let Spellings = ["format_arg"];
let Args = [IntArgument<"FormatIdx">];
}
def GNUInline : Attr {
let Spellings = ["gnu_inline"];
}
def Hiding : Attr {
let Spellings = ["hiding"];
let Subjects = [Field, CXXMethod];
let Namespaces = ["", "std"];
let DoNotEmit = 0;
}
def IBAction : Attr {
let Spellings = ["ibaction"];
}
def IBOutlet : Attr {
let Spellings = ["iboutlet"];
}
def IBOutletCollection : Attr {
let Spellings = ["iboutletcollection"];
let Args = [ObjCInterfaceArgument<"Class">];
}
def Malloc : Attr {
let Spellings = ["malloc"];
}
def MaxFieldAlignment : Attr {
let Spellings = [];
let Args = [UnsignedIntArgument<"Alignment">];
}
def MSP430Interrupt : Attr {
let Spellings = [];
let Args = [UnsignedIntArgument<"Number">];
}
def NoDebug : Attr {
let Spellings = ["nodebug"];
}
def NoInline : Attr {
let Spellings = ["noinline"];
}
def NonNull : Attr {
let Spellings = ["nonnull"];
let Args = [VariadicArgument<UnsignedIntArgument<"Args">>];
}
def NoReturn : Attr {
let Spellings = ["noreturn"];
// FIXME: Does GCC allow this on the function instead?
let Subjects = [Function];
let Namespaces = ["", "std"];
}
def NoThrow : Attr {
let Spellings = ["nothrow"];
}
def NSReturnsRetained : Attr {
let Spellings = ["ns_returns_retained"];
}
def NSReturnsNotRetained : Attr {
let Spellings = ["ns_returns_not_retained"];
}
def ObjCException : Attr {
let Spellings = ["objc_exception"];
}
def ObjCNSObject : Attr {
let Spellings = ["NSOjbect"];
}
def Override : Attr {
let Spellings = ["override"];
let Subjects = [CXXVirtualMethod];
let Namespaces = ["", "std"];
let DoNotEmit = 0;
}
def Overloadable : Attr {
let Spellings = ["overloadable"];
}
def Packed : Attr {
let Spellings = ["packed"];
}
def Pure : Attr {
let Spellings = ["pure"];
}
def Regparm : Attr {
let Spellings = ["regparm"];
let Args = [UnsignedIntArgument<"NumParams">];
}
def ReqdWorkGroupSize : Attr {
let Spellings = ["reqd_work_group_size"];
let Args = [UnsignedIntArgument<"XDim">, UnsignedIntArgument<"YDim">,
UnsignedIntArgument<"ZDim">];
}
def Section : Attr {
let Spellings = ["section"];
let Args = [StringArgument<"Name">];
}
def Sentinel : Attr {
let Spellings = ["sentinel"];
let Args = [DefaultIntArgument<"NulPos", 0>,
DefaultIntArgument<"Sentinel", 0>];
}
def StdCall : Attr {
let Spellings = ["stdcall", "__stdcall"];
}
def ThisCall : Attr {
let Spellings = ["thiscall", "__thiscall"];
}
def TransparentUnion : Attr {
let Spellings = ["transparent_union"];
}
def Unavailable : Attr {
let Spellings = ["unavailable"];
}
def Unused : Attr {
let Spellings = ["unused"];
}
def Used : Attr {
let Spellings = ["used"];
}
def Visibility : Attr {
let Spellings = ["visibility"];
let Args = [StringArgument<"Visibility">];
}
def WarnUnusedResult : Attr {
let Spellings = ["warn_unused_result"];
}
def Weak : Attr {
let Spellings = ["weak"];
}
def WeakImport : Attr {
let Spellings = ["weak_import"];
}
def WeakRef : Attr {
let Spellings = ["weakref"];
}
def X86ForceAlignArgPointer : Attr {
let Spellings = [];
}

View File

@ -0,0 +1,31 @@
//===----- Attr.h - Enum values for C Attribute Kinds ----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the attr::Kind enum
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_ATTRKINDS_H
#define LLVM_CLANG_ATTRKINDS_H
namespace clang {
namespace attr {
// Kind - This is a list of all the recognized kinds of attributes.
enum Kind {
#define ATTR(X) X,
#include "clang/Basic/AttrList.inc"
NUM_ATTRS
};
} // end namespace attr
} // end namespace clang
#endif

View File

@ -1,4 +1,6 @@
class Decl<bit abstract = 0> {
class AttrSubject;
class Decl<bit abstract = 0> : AttrSubject {
bit Abstract = abstract;
}

View File

@ -3,7 +3,7 @@ BUILT_SOURCES = DiagnosticAnalysisKinds.inc DiagnosticASTKinds.inc \
DiagnosticCommonKinds.inc DiagnosticDriverKinds.inc \
DiagnosticFrontendKinds.inc DiagnosticLexKinds.inc \
DiagnosticParseKinds.inc DiagnosticSemaKinds.inc \
DiagnosticGroups.inc
DiagnosticGroups.inc AttrList.inc
TABLEGEN_INC_FILES_COMMON = 1
@ -19,4 +19,7 @@ $(ObjDir)/DiagnosticGroups.inc.tmp : Diagnostic.td DiagnosticGroups.td $(INPUT_T
$(Echo) "Building Clang diagnostic groups with tblgen"
$(Verb) $(TableGen) -gen-clang-diag-groups -o $(call SYSPATH, $@) $<
$(ObjDir)/AttrList.inc.tmp : Attr.td $(TBLGEN) $(ObjDir)/.dir
$(Echo) "Building Clang attribute list with tblgen"
$(Verb) $(TableGen) -gen-clang-attr-list -o $(call SYSPATH, $@) \
-I $(PROJ_SRC_DIR)/../.. $<

View File

@ -1,4 +1,6 @@
class Stmt<bit abstract = 0> {
class AttrSubject;
class Stmt<bit abstract = 0> : AttrSubject {
bit Abstract = abstract;
}

View File

@ -24,7 +24,7 @@ void Attr::Destroy(ASTContext &C) {
C.Deallocate((void*)this);
}
AttrWithString::AttrWithString(Attr::Kind AK, ASTContext &C, llvm::StringRef s)
AttrWithString::AttrWithString(attr::Kind AK, ASTContext &C, llvm::StringRef s)
: Attr(AK) {
assert(!s.empty());
StrLen = s.size();
@ -51,7 +51,7 @@ void FormatAttr::setType(ASTContext &C, llvm::StringRef type) {
}
NonNullAttr::NonNullAttr(ASTContext &C, unsigned* arg_nums, unsigned size)
: Attr(NonNull), ArgNums(0), Size(0) {
: Attr(attr::NonNull), ArgNums(0), Size(0) {
if (size == 0)
return;
assert(arg_nums);

View File

@ -679,24 +679,24 @@ Attr *PCHReader::ReadAttributes() {
(void)RecCode;
#define SIMPLE_ATTR(Name) \
case Attr::Name: \
case attr::Name: \
New = ::new (*Context) Name##Attr(); \
break
#define STRING_ATTR(Name) \
case Attr::Name: \
case attr::Name: \
New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
break
#define UNSIGNED_ATTR(Name) \
case Attr::Name: \
case attr::Name: \
New = ::new (*Context) Name##Attr(Record[Idx++]); \
break
Attr *Attrs = 0;
while (Idx < Record.size()) {
Attr *New = 0;
Attr::Kind Kind = (Attr::Kind)Record[Idx++];
attr::Kind Kind = (attr::Kind)Record[Idx++];
bool IsInherited = Record[Idx++];
switch (Kind) {
@ -712,14 +712,14 @@ Attr *PCHReader::ReadAttributes() {
STRING_ATTR(AsmLabel);
SIMPLE_ATTR(BaseCheck);
case Attr::Blocks:
case attr::Blocks:
New = ::new (*Context) BlocksAttr(
(BlocksAttr::BlocksAttrTypes)Record[Idx++]);
break;
SIMPLE_ATTR(CDecl);
case Attr::Cleanup:
case attr::Cleanup:
New = ::new (*Context) CleanupAttr(
cast<FunctionDecl>(GetDecl(Record[Idx++])));
break;
@ -733,7 +733,7 @@ Attr *PCHReader::ReadAttributes() {
SIMPLE_ATTR(FastCall);
SIMPLE_ATTR(Final);
case Attr::Format: {
case attr::Format: {
std::string Type = ReadString(Record, Idx);
unsigned FormatIdx = Record[Idx++];
unsigned FirstArg = Record[Idx++];
@ -741,13 +741,13 @@ Attr *PCHReader::ReadAttributes() {
break;
}
case Attr::FormatArg: {
case attr::FormatArg: {
unsigned FormatIdx = Record[Idx++];
New = ::new (*Context) FormatArgAttr(FormatIdx);
break;
}
case Attr::Sentinel: {
case attr::Sentinel: {
int sentinel = Record[Idx++];
int nullPos = Record[Idx++];
New = ::new (*Context) SentinelAttr(sentinel, nullPos);
@ -757,15 +757,15 @@ Attr *PCHReader::ReadAttributes() {
SIMPLE_ATTR(GNUInline);
SIMPLE_ATTR(Hiding);
case Attr::IBActionKind:
case attr::IBAction:
New = ::new (*Context) IBActionAttr();
break;
case Attr::IBOutletKind:
case attr::IBOutlet:
New = ::new (*Context) IBOutletAttr();
break;
case Attr::IBOutletCollectionKind: {
case attr::IBOutletCollection: {
ObjCInterfaceDecl *D =
cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
New = ::new (*Context) IBOutletCollectionAttr(D);
@ -778,7 +778,7 @@ Attr *PCHReader::ReadAttributes() {
SIMPLE_ATTR(NoReturn);
SIMPLE_ATTR(NoThrow);
case Attr::NonNull: {
case attr::NonNull: {
unsigned Size = Record[Idx++];
llvm::SmallVector<unsigned, 16> ArgNums;
ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
@ -787,7 +787,7 @@ Attr *PCHReader::ReadAttributes() {
break;
}
case Attr::ReqdWorkGroupSize: {
case attr::ReqdWorkGroupSize: {
unsigned X = Record[Idx++];
unsigned Y = Record[Idx++];
unsigned Z = Record[Idx++];
@ -815,7 +815,7 @@ Attr *PCHReader::ReadAttributes() {
SIMPLE_ATTR(Unused);
SIMPLE_ATTR(Used);
case Attr::Visibility:
case attr::Visibility:
New = ::new (*Context) VisibilityAttr(
(VisibilityAttr::VisibilityTypes)Record[Idx++]);
break;

View File

@ -1842,66 +1842,66 @@ void PCHWriter::WriteAttributeRecord(const Attr *Attr) {
default:
assert(0 && "Does not support PCH writing for this attribute yet!");
break;
case Attr::Alias:
case attr::Alias:
AddString(cast<AliasAttr>(Attr)->getAliasee(), Record);
break;
case Attr::AlignMac68k:
case attr::AlignMac68k:
break;
case Attr::Aligned:
case attr::Aligned:
Record.push_back(cast<AlignedAttr>(Attr)->getAlignment());
break;
case Attr::AlwaysInline:
case attr::AlwaysInline:
break;
case Attr::AnalyzerNoReturn:
case attr::AnalyzerNoReturn:
break;
case Attr::Annotate:
case attr::Annotate:
AddString(cast<AnnotateAttr>(Attr)->getAnnotation(), Record);
break;
case Attr::AsmLabel:
case attr::AsmLabel:
AddString(cast<AsmLabelAttr>(Attr)->getLabel(), Record);
break;
case Attr::BaseCheck:
case attr::BaseCheck:
break;
case Attr::Blocks:
case attr::Blocks:
Record.push_back(cast<BlocksAttr>(Attr)->getType()); // FIXME: stable
break;
case Attr::CDecl:
case attr::CDecl:
break;
case Attr::Cleanup:
case attr::Cleanup:
AddDeclRef(cast<CleanupAttr>(Attr)->getFunctionDecl(), Record);
break;
case Attr::Const:
case attr::Const:
break;
case Attr::Constructor:
case attr::Constructor:
Record.push_back(cast<ConstructorAttr>(Attr)->getPriority());
break;
case Attr::DLLExport:
case Attr::DLLImport:
case Attr::Deprecated:
case attr::DLLExport:
case attr::DLLImport:
case attr::Deprecated:
break;
case Attr::Destructor:
case attr::Destructor:
Record.push_back(cast<DestructorAttr>(Attr)->getPriority());
break;
case Attr::FastCall:
case Attr::Final:
case attr::FastCall:
case attr::Final:
break;
case Attr::Format: {
case attr::Format: {
const FormatAttr *Format = cast<FormatAttr>(Attr);
AddString(Format->getType(), Record);
Record.push_back(Format->getFormatIdx());
@ -1909,93 +1909,93 @@ void PCHWriter::WriteAttributeRecord(const Attr *Attr) {
break;
}
case Attr::FormatArg: {
case attr::FormatArg: {
const FormatArgAttr *Format = cast<FormatArgAttr>(Attr);
Record.push_back(Format->getFormatIdx());
break;
}
case Attr::Sentinel : {
case attr::Sentinel : {
const SentinelAttr *Sentinel = cast<SentinelAttr>(Attr);
Record.push_back(Sentinel->getSentinel());
Record.push_back(Sentinel->getNullPos());
break;
}
case Attr::GNUInline:
case Attr::Hiding:
case Attr::IBActionKind:
case Attr::IBOutletKind:
case Attr::Malloc:
case Attr::NoDebug:
case Attr::NoInline:
case Attr::NoReturn:
case Attr::NoThrow:
case attr::GNUInline:
case attr::Hiding:
case attr::IBAction:
case attr::IBOutlet:
case attr::Malloc:
case attr::NoDebug:
case attr::NoInline:
case attr::NoReturn:
case attr::NoThrow:
break;
case Attr::IBOutletCollectionKind: {
case attr::IBOutletCollection: {
const IBOutletCollectionAttr *ICA = cast<IBOutletCollectionAttr>(Attr);
AddDeclRef(ICA->getClass(), Record);
break;
}
case Attr::NonNull: {
case attr::NonNull: {
const NonNullAttr *NonNull = cast<NonNullAttr>(Attr);
Record.push_back(NonNull->size());
Record.insert(Record.end(), NonNull->begin(), NonNull->end());
break;
}
case Attr::CFReturnsNotRetained:
case Attr::CFReturnsRetained:
case Attr::NSReturnsNotRetained:
case Attr::NSReturnsRetained:
case Attr::ObjCException:
case Attr::ObjCNSObject:
case Attr::Overloadable:
case Attr::Override:
case attr::CFReturnsNotRetained:
case attr::CFReturnsRetained:
case attr::NSReturnsNotRetained:
case attr::NSReturnsRetained:
case attr::ObjCException:
case attr::ObjCNSObject:
case attr::Overloadable:
case attr::Override:
break;
case Attr::MaxFieldAlignment:
case attr::MaxFieldAlignment:
Record.push_back(cast<MaxFieldAlignmentAttr>(Attr)->getAlignment());
break;
case Attr::Packed:
case attr::Packed:
break;
case Attr::Pure:
case attr::Pure:
break;
case Attr::Regparm:
case attr::Regparm:
Record.push_back(cast<RegparmAttr>(Attr)->getNumParams());
break;
case Attr::ReqdWorkGroupSize:
case attr::ReqdWorkGroupSize:
Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getXDim());
Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getYDim());
Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getZDim());
break;
case Attr::Section:
case attr::Section:
AddString(cast<SectionAttr>(Attr)->getName(), Record);
break;
case Attr::StdCall:
case Attr::TransparentUnion:
case Attr::Unavailable:
case Attr::Unused:
case Attr::Used:
case attr::StdCall:
case attr::TransparentUnion:
case attr::Unavailable:
case attr::Unused:
case attr::Used:
break;
case Attr::Visibility:
case attr::Visibility:
// FIXME: stable encoding
Record.push_back(cast<VisibilityAttr>(Attr)->getVisibility());
break;
case Attr::WarnUnusedResult:
case Attr::Weak:
case Attr::WeakRef:
case Attr::WeakImport:
case attr::WarnUnusedResult:
case attr::Weak:
case attr::WeakRef:
case attr::WeakImport:
break;
}
}

View File

@ -78,9 +78,9 @@ static CXCursorKind GetCursorKind(const Attr *A) {
assert(A && "Invalid arguments!");
switch (A->getKind()) {
default: break;
case Attr::IBActionKind: return CXCursor_IBActionAttr;
case Attr::IBOutletKind: return CXCursor_IBOutletAttr;
case Attr::IBOutletCollectionKind: return CXCursor_IBOutletCollectionAttr;
case attr::IBAction: return CXCursor_IBActionAttr;
case attr::IBOutlet: return CXCursor_IBOutletAttr;
case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr;
}
return CXCursor_UnexposedAttr;