1 ////////////////////////////////////////////////////////////////////////////////
2 // Note: This file is a work in progress. Please do not apply non-trivial
3 // updates unless you have talked to Sean Hunt <rideau3@gmail.com> prior.
4 // Merely adding a new attribute is a trivial update.
5 ////////////////////////////////////////////////////////////////////////////////
7 // An attribute's subject is whatever it appertains to. In this file, it is
8 // more accurately a list of things that an attribute can appertain to. All
9 // Decls and Stmts are possibly AttrSubjects (even though the syntax may not
10 // allow attributes on a given Decl or Stmt).
13 include "clang/Basic/DeclNodes.td"
14 include "clang/Basic/StmtNodes.td"
16 // A subset-subject is an AttrSubject constrained to operate only on some subset
19 // The description is used in output messages to specify what the subject
20 // represents. FIXME: Deal with translation issues.
22 // The code fragment is a boolean expression that will confirm that the subject
23 // meets the requirements; the subject will have the name S, and will have the
24 // type specified by the base. It should be a simple boolean expression.
25 class SubsetSubject<AttrSubject base, string description, code check>
27 AttrSubject Base = base;
28 string Description = description;
29 code CheckCode = check;
32 // This is the type of a variable which C++0x defines [[aligned()]] as being
33 // a possible subject.
34 def NormalVar : SubsetSubject<Var, "non-register, non-parameter variable",
35 [{S->getStorageClass() != VarDecl::Register &&
36 S->getKind() != Decl::ImplicitParam &&
37 S->getKind() != Decl::ParmVar &&
38 S->getKind() != Decl::NonTypeTemplateParm}]>;
39 def CXXVirtualMethod : SubsetSubject<CXXRecord, "virtual member function",
41 def NonBitField : SubsetSubject<Field, "non-bit field",
42 [{!S->isBitField()}]>;
44 // A single argument to an attribute
45 class Argument<string name> {
49 class BoolArgument<string name> : Argument<name>;
50 class IdentifierArgument<string name> : Argument<name>;
51 class IntArgument<string name> : Argument<name>;
52 class StringArgument<string name> : Argument<name>;
53 class ExprArgument<string name> : Argument<name>;
54 class FunctionArgument<string name> : Argument<name>;
55 class TypeArgument<string name> : Argument<name>;
56 class UnsignedArgument<string name> : Argument<name>;
57 class VariadicUnsignedArgument<string name> : Argument<name>;
59 // A version of the form major.minor[.subminor].
60 class VersionArgument<string name> : Argument<name>;
62 // This one's a doozy, so it gets its own special type
63 // It can be an unsigned integer, or a type. Either can
65 class AlignedArgument<string name> : Argument<name>;
67 // An integer argument with a default value
68 class DefaultIntArgument<string name, int default> : IntArgument<name> {
69 int Default = default;
72 // This argument is more complex, it includes the enumerator type name,
73 // a list of strings to accept, and a list of enumerators to map them to.
74 class EnumArgument<string name, string type, list<string> values,
75 list<string> enums> : Argument<name> {
77 list<string> Values = values;
78 list<string> Enums = enums;
82 // The various ways in which an attribute can be spelled in source
83 list<string> Spellings;
84 // The things to which an attribute can appertain
85 list<AttrSubject> Subjects;
86 // The arguments allowed on an attribute
87 list<Argument> Args = [];
88 // The namespaces in which the attribute appears in C++0x attributes.
89 // The attribute will not be permitted in C++0x attribute-specifiers if
90 // this is empty; the empty string can be used as a namespace.
91 list<string> Namespaces = [];
92 // Any additional text that should be included verbatim in the class.
93 code AdditionalMembers = [{}];
96 /// An inheritable attribute is inherited by later redeclarations.
97 class InheritableAttr : Attr;
99 /// An inheritable parameter attribute is inherited by later
100 /// redeclarations, even when it's written on a parameter.
101 class InheritableParamAttr : InheritableAttr;
104 // Attributes begin here
107 def Alias : InheritableAttr {
108 let Spellings = ["alias"];
109 let Args = [StringArgument<"Aliasee">];
112 def Aligned : InheritableAttr {
113 let Spellings = ["align", "aligned"];
114 let Subjects = [NonBitField, NormalVar, Tag];
115 let Args = [AlignedArgument<"Alignment">];
116 let Namespaces = ["", "std"];
119 def AlignMac68k : InheritableAttr {
123 def AlwaysInline : InheritableAttr {
124 let Spellings = ["always_inline"];
127 def AnalyzerNoReturn : InheritableAttr {
128 let Spellings = ["analyzer_noreturn"];
131 def Annotate : InheritableAttr {
132 let Spellings = ["annotate"];
133 let Args = [StringArgument<"Annotation">];
136 def AsmLabel : InheritableAttr {
138 let Args = [StringArgument<"Label">];
141 def Availability : InheritableAttr {
142 let Spellings = ["availability"];
143 let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
144 VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
145 BoolArgument<"unavailable">];
146 let AdditionalMembers =
147 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
148 return llvm::StringSwitch<llvm::StringRef>(Platform)
150 .Case("macosx", "Mac OS X")
151 .Default(llvm::StringRef());
155 def Blocks : InheritableAttr {
156 let Spellings = ["blocks"];
157 let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
160 def CarriesDependency : InheritableParamAttr {
161 let Spellings = ["carries_dependency"];
162 let Subjects = [ParmVar, Function];
163 let Namespaces = ["", "std"];
166 def CDecl : InheritableAttr {
167 let Spellings = ["cdecl", "__cdecl"];
170 def CFReturnsRetained : InheritableAttr {
171 let Spellings = ["cf_returns_retained"];
172 let Subjects = [ObjCMethod, Function];
175 def CFReturnsNotRetained : InheritableAttr {
176 let Spellings = ["cf_returns_not_retained"];
177 let Subjects = [ObjCMethod, Function];
180 def CFConsumed : InheritableParamAttr {
181 let Spellings = ["cf_consumed"];
182 let Subjects = [ParmVar];
185 def Cleanup : InheritableAttr {
186 let Spellings = ["cleanup"];
187 let Args = [FunctionArgument<"FunctionDecl">];
190 def Common : InheritableAttr {
191 let Spellings = ["common"];
194 def Const : InheritableAttr {
195 let Spellings = ["const"];
198 def Constructor : InheritableAttr {
199 let Spellings = ["constructor"];
200 let Args = [IntArgument<"Priority">];
203 def CUDAConstant : InheritableAttr {
204 let Spellings = ["constant"];
207 def CUDADevice : Attr {
208 let Spellings = ["device"];
211 def CUDAGlobal : InheritableAttr {
212 let Spellings = ["global"];
215 def CUDAHost : Attr {
216 let Spellings = ["host"];
219 def CUDALaunchBounds : InheritableAttr {
220 let Spellings = ["launch_bounds"];
221 let Args = [IntArgument<"MaxThreads">, DefaultIntArgument<"MinBlocks", 0>];
224 def CUDAShared : InheritableAttr {
225 let Spellings = ["shared"];
228 def OpenCLKernel : Attr {
229 let Spellings = ["opencl_kernel_function"];
232 def Deprecated : InheritableAttr {
233 let Spellings = ["deprecated"];
234 let Args = [StringArgument<"Message">];
237 def Destructor : InheritableAttr {
238 let Spellings = ["destructor"];
239 let Args = [IntArgument<"Priority">];
242 def DLLExport : InheritableAttr {
243 let Spellings = ["dllexport"];
246 def DLLImport : InheritableAttr {
247 let Spellings = ["dllimport"];
250 def FastCall : InheritableAttr {
251 let Spellings = ["fastcall", "__fastcall"];
254 def Final : InheritableAttr {
258 def MsStruct : InheritableAttr {
259 let Spellings = ["__ms_struct__"];
262 def Format : InheritableAttr {
263 let Spellings = ["format"];
264 let Args = [StringArgument<"Type">, IntArgument<"FormatIdx">,
265 IntArgument<"FirstArg">];
268 def FormatArg : InheritableAttr {
269 let Spellings = ["format_arg"];
270 let Args = [IntArgument<"FormatIdx">];
273 def GNUInline : InheritableAttr {
274 let Spellings = ["gnu_inline"];
277 def IBAction : InheritableAttr {
278 let Spellings = ["ibaction"];
281 def IBOutlet : InheritableAttr {
282 let Spellings = ["iboutlet"];
285 def IBOutletCollection : InheritableAttr {
286 let Spellings = ["iboutletcollection"];
287 let Args = [TypeArgument<"InterFace">];
290 def Malloc : InheritableAttr {
291 let Spellings = ["malloc"];
294 def MaxFieldAlignment : InheritableAttr {
296 let Args = [UnsignedArgument<"Alignment">];
299 def MayAlias : InheritableAttr {
300 let Spellings = ["may_alias"];
303 def MSP430Interrupt : InheritableAttr {
305 let Args = [UnsignedArgument<"Number">];
308 def MBlazeInterruptHandler : InheritableAttr {
312 def MBlazeSaveVolatiles : InheritableAttr {
316 def Naked : InheritableAttr {
317 let Spellings = ["naked"];
320 def NoCommon : InheritableAttr {
321 let Spellings = ["nocommon"];
324 def NoDebug : InheritableAttr {
325 let Spellings = ["nodebug"];
328 def NoInline : InheritableAttr {
329 let Spellings = ["noinline"];
332 def NonNull : InheritableAttr {
333 let Spellings = ["nonnull"];
334 let Args = [VariadicUnsignedArgument<"Args">];
335 let AdditionalMembers =
336 [{bool isNonNull(unsigned idx) const {
337 for (args_iterator i = args_begin(), e = args_end();
345 def NoReturn : InheritableAttr {
346 let Spellings = ["noreturn"];
347 // FIXME: Does GCC allow this on the function instead?
348 let Subjects = [Function];
349 let Namespaces = ["", "std"];
352 def NoInstrumentFunction : InheritableAttr {
353 let Spellings = ["no_instrument_function"];
354 let Subjects = [Function];
357 def NoThrow : InheritableAttr {
358 let Spellings = ["nothrow"];
361 def NSReturnsRetained : InheritableAttr {
362 let Spellings = ["ns_returns_retained"];
363 let Subjects = [ObjCMethod, Function];
366 def NSReturnsNotRetained : InheritableAttr {
367 let Spellings = ["ns_returns_not_retained"];
368 let Subjects = [ObjCMethod, Function];
371 def NSReturnsAutoreleased : InheritableAttr {
372 let Spellings = ["ns_returns_autoreleased"];
373 let Subjects = [ObjCMethod, Function];
376 def NSConsumesSelf : InheritableAttr {
377 let Spellings = ["ns_consumes_self"];
378 let Subjects = [ObjCMethod];
381 def NSConsumed : InheritableParamAttr {
382 let Spellings = ["ns_consumed"];
383 let Subjects = [ParmVar];
386 def ObjCException : InheritableAttr {
387 let Spellings = ["objc_exception"];
390 def ObjCMethodFamily : InheritableAttr {
391 let Spellings = ["objc_method_family"];
392 let Subjects = [ObjCMethod];
393 let Args = [EnumArgument<"Family", "FamilyKind",
394 ["none", "alloc", "copy", "init", "mutableCopy", "new"],
395 ["OMF_None", "OMF_alloc", "OMF_copy", "OMF_init",
396 "OMF_mutableCopy", "OMF_new"]>];
399 def ObjCNSObject : InheritableAttr {
400 let Spellings = ["NSObject"];
403 def ObjCPreciseLifetime : Attr {
404 let Spellings = ["objc_precise_lifetime"];
405 let Subjects = [Var];
408 def Overloadable : Attr {
409 let Spellings = ["overloadable"];
412 def Override : InheritableAttr {
416 def Ownership : InheritableAttr {
417 let Spellings = ["ownership_holds", "ownership_returns", "ownership_takes"];
418 let Args = [EnumArgument<"OwnKind", "OwnershipKind",
419 ["ownership_holds", "ownership_returns", "ownership_takes"],
420 ["Holds", "Returns", "Takes"]>,
421 StringArgument<"Module">, VariadicUnsignedArgument<"Args">];
424 def Packed : InheritableAttr {
425 let Spellings = ["packed"];
428 def Pcs : InheritableAttr {
429 let Spellings = ["pcs"];
430 let Args = [EnumArgument<"PCS", "PCSType",
431 ["aapcs", "aapcs-vfp"],
432 ["AAPCS", "AAPCS_VFP"]>];
435 def Pure : InheritableAttr {
436 let Spellings = ["pure"];
439 def Regparm : InheritableAttr {
440 let Spellings = ["regparm"];
441 let Args = [UnsignedArgument<"NumParams">];
444 def ReqdWorkGroupSize : InheritableAttr {
445 let Spellings = ["reqd_work_group_size"];
446 let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
447 UnsignedArgument<"ZDim">];
450 def InitPriority : InheritableAttr {
451 let Spellings = ["init_priority"];
452 let Args = [UnsignedArgument<"Priority">];
455 def Section : InheritableAttr {
456 let Spellings = ["section"];
457 let Args = [StringArgument<"Name">];
460 def Sentinel : InheritableAttr {
461 let Spellings = ["sentinel"];
462 let Args = [DefaultIntArgument<"Sentinel", 0>,
463 DefaultIntArgument<"NullPos", 0>];
466 def StdCall : InheritableAttr {
467 let Spellings = ["stdcall", "__stdcall"];
470 def ThisCall : InheritableAttr {
471 let Spellings = ["thiscall", "__thiscall"];
474 def Pascal : InheritableAttr {
475 let Spellings = ["pascal", "__pascal"];
478 def TransparentUnion : InheritableAttr {
479 let Spellings = ["transparent_union"];
482 def Unavailable : InheritableAttr {
483 let Spellings = ["unavailable"];
484 let Args = [StringArgument<"Message">];
487 def ArcWeakrefUnavailable : InheritableAttr {
488 let Spellings = ["objc_arc_weak_reference_unavailable"];
491 def Unused : InheritableAttr {
492 let Spellings = ["unused"];
495 def Used : InheritableAttr {
496 let Spellings = ["used"];
499 def Uuid : InheritableAttr {
500 let Spellings = ["uuid"];
501 let Args = [StringArgument<"Guid">];
502 let Subjects = [CXXRecord];
505 def Visibility : InheritableAttr {
506 let Spellings = ["visibility"];
507 let Args = [EnumArgument<"Visibility", "VisibilityType",
508 ["default", "hidden", "internal", "protected"],
509 ["Default", "Hidden", "Hidden", "Protected"]>];
512 def VecReturn : InheritableAttr {
513 let Spellings = ["vecreturn"];
514 let Subjects = [CXXRecord];
517 def WarnUnusedResult : InheritableAttr {
518 let Spellings = ["warn_unused_result"];
521 def Weak : InheritableAttr {
522 let Spellings = ["weak"];
525 def WeakImport : InheritableAttr {
526 let Spellings = ["weak_import"];
529 def WeakRef : InheritableAttr {
530 let Spellings = ["weakref"];
533 def X86ForceAlignArgPointer : InheritableAttr {