]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Basic/Attr.td
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / include / clang / Basic / Attr.td
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 ////////////////////////////////////////////////////////////////////////////////
6
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).
11 class AttrSubject;
12
13 include "clang/Basic/DeclNodes.td"
14 include "clang/Basic/StmtNodes.td"
15
16 // A subset-subject is an AttrSubject constrained to operate only on some subset
17 // of that subject.
18 //
19 // The description is used in output messages to specify what the subject
20 // represents. FIXME: Deal with translation issues.
21 //
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>
26     : AttrSubject {
27   AttrSubject Base = base;
28   string Description = description;
29   code CheckCode = check;
30 }
31
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",
40                                      [{S->isVirtual()}]>;
41 def NonBitField : SubsetSubject<Field, "non-bit field",
42                                 [{!S->isBitField()}]>;
43
44 // A single argument to an attribute
45 class Argument<string name> {
46   string Name = name;
47 }
48
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>;
58
59 // A version of the form major.minor[.subminor].
60 class VersionArgument<string name> : Argument<name>;
61
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
64 // be dependent.
65 class AlignedArgument<string name> : Argument<name>;
66
67 // An integer argument with a default value
68 class DefaultIntArgument<string name, int default> : IntArgument<name> {
69   int Default = default;
70 }
71
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> {
76   string Type = type;
77   list<string> Values = values;
78   list<string> Enums = enums;
79 }
80
81 class Attr {
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 = [{}];
94 }
95
96 /// An inheritable attribute is inherited by later redeclarations.
97 class InheritableAttr : Attr;
98
99 /// An inheritable parameter attribute is inherited by later
100 /// redeclarations, even when it's written on a parameter.
101 class InheritableParamAttr : InheritableAttr;
102
103 //
104 // Attributes begin here
105 //
106
107 def Alias : InheritableAttr {
108   let Spellings = ["alias"];
109   let Args = [StringArgument<"Aliasee">];
110 }
111
112 def Aligned : InheritableAttr {
113   let Spellings = ["align", "aligned"];
114   let Subjects = [NonBitField, NormalVar, Tag];
115   let Args = [AlignedArgument<"Alignment">];
116   let Namespaces = ["", "std"];
117 }
118
119 def AlignMac68k : InheritableAttr {
120   let Spellings = [];
121 }
122
123 def AlwaysInline : InheritableAttr {
124   let Spellings = ["always_inline"];
125 }
126
127 def AnalyzerNoReturn : InheritableAttr {
128   let Spellings = ["analyzer_noreturn"];
129 }
130
131 def Annotate : InheritableAttr {
132   let Spellings = ["annotate"];
133   let Args = [StringArgument<"Annotation">];
134 }
135
136 def AsmLabel : InheritableAttr {
137   let Spellings = [];
138   let Args = [StringArgument<"Label">];
139 }
140
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)
149              .Case("ios", "iOS")
150              .Case("macosx", "Mac OS X")
151              .Default(llvm::StringRef());
152 } }];
153 }
154
155 def Blocks : InheritableAttr {
156   let Spellings = ["blocks"];
157   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
158 }
159
160 def CarriesDependency : InheritableParamAttr {
161   let Spellings = ["carries_dependency"];
162   let Subjects = [ParmVar, Function];
163   let Namespaces = ["", "std"];
164 }
165
166 def CDecl : InheritableAttr {
167   let Spellings = ["cdecl", "__cdecl"];
168 }
169
170 def CFReturnsRetained : InheritableAttr {
171   let Spellings = ["cf_returns_retained"];
172   let Subjects = [ObjCMethod, Function];
173 }
174
175 def CFReturnsNotRetained : InheritableAttr {
176   let Spellings = ["cf_returns_not_retained"];
177   let Subjects = [ObjCMethod, Function];
178 }
179
180 def CFConsumed : InheritableParamAttr {
181   let Spellings = ["cf_consumed"];
182   let Subjects = [ParmVar];
183 }
184
185 def Cleanup : InheritableAttr {
186   let Spellings = ["cleanup"];
187   let Args = [FunctionArgument<"FunctionDecl">];
188 }
189
190 def Common : InheritableAttr {
191   let Spellings = ["common"];
192 }
193
194 def Const : InheritableAttr {
195   let Spellings = ["const"];
196 }
197
198 def Constructor : InheritableAttr {
199   let Spellings = ["constructor"];
200   let Args = [IntArgument<"Priority">];
201 }
202
203 def CUDAConstant : InheritableAttr {
204   let Spellings = ["constant"];
205 }
206
207 def CUDADevice : Attr {
208   let Spellings = ["device"];
209 }
210
211 def CUDAGlobal : InheritableAttr {
212   let Spellings = ["global"];
213 }
214
215 def CUDAHost : Attr {
216   let Spellings = ["host"];
217 }
218
219 def CUDALaunchBounds : InheritableAttr {
220   let Spellings = ["launch_bounds"];
221   let Args = [IntArgument<"MaxThreads">, DefaultIntArgument<"MinBlocks", 0>];
222 }
223
224 def CUDAShared : InheritableAttr {
225   let Spellings = ["shared"];
226 }
227
228 def OpenCLKernel : Attr {
229   let Spellings = ["opencl_kernel_function"];
230 }
231
232 def Deprecated : InheritableAttr {
233   let Spellings = ["deprecated"];
234   let Args = [StringArgument<"Message">];
235 }
236
237 def Destructor : InheritableAttr {
238   let Spellings = ["destructor"];
239   let Args = [IntArgument<"Priority">];
240 }
241
242 def DLLExport : InheritableAttr {
243   let Spellings = ["dllexport"];
244 }
245
246 def DLLImport : InheritableAttr {
247   let Spellings = ["dllimport"];
248 }
249
250 def FastCall : InheritableAttr {
251   let Spellings = ["fastcall", "__fastcall"];
252 }
253
254 def Final : InheritableAttr { 
255   let Spellings = [];
256 }
257
258 def MsStruct : InheritableAttr {
259   let Spellings = ["__ms_struct__"];
260 }
261
262 def Format : InheritableAttr {
263   let Spellings = ["format"];
264   let Args = [StringArgument<"Type">, IntArgument<"FormatIdx">,
265               IntArgument<"FirstArg">];
266 }
267
268 def FormatArg : InheritableAttr {
269   let Spellings = ["format_arg"];
270   let Args = [IntArgument<"FormatIdx">];
271 }
272
273 def GNUInline : InheritableAttr {
274   let Spellings = ["gnu_inline"];
275 }
276
277 def IBAction : InheritableAttr {
278   let Spellings = ["ibaction"];
279 }
280
281 def IBOutlet : InheritableAttr {
282   let Spellings = ["iboutlet"];
283 }
284
285 def IBOutletCollection : InheritableAttr {
286   let Spellings = ["iboutletcollection"];
287   let Args = [TypeArgument<"InterFace">];
288 }
289
290 def Malloc : InheritableAttr {
291   let Spellings = ["malloc"];
292 }
293
294 def MaxFieldAlignment : InheritableAttr {
295   let Spellings = [];
296   let Args = [UnsignedArgument<"Alignment">];
297 }
298
299 def MayAlias : InheritableAttr {
300   let Spellings = ["may_alias"];
301 }
302
303 def MSP430Interrupt : InheritableAttr {
304   let Spellings = [];
305   let Args = [UnsignedArgument<"Number">];
306 }
307
308 def MBlazeInterruptHandler : InheritableAttr {
309   let Spellings = [];
310 }
311
312 def MBlazeSaveVolatiles : InheritableAttr {
313   let Spellings = [];
314 }
315
316 def Naked : InheritableAttr {
317   let Spellings = ["naked"];
318 }
319
320 def NoCommon : InheritableAttr {
321   let Spellings = ["nocommon"];
322 }
323
324 def NoDebug : InheritableAttr {
325   let Spellings = ["nodebug"];
326 }
327
328 def NoInline : InheritableAttr {
329   let Spellings = ["noinline"];
330 }
331
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();
338          i != e; ++i)
339       if (*i == idx)
340         return true;
341     return false;
342   } }];
343 }
344
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"];
350 }
351
352 def NoInstrumentFunction : InheritableAttr {
353   let Spellings = ["no_instrument_function"];
354   let Subjects = [Function];
355 }
356
357 def NoThrow : InheritableAttr {
358   let Spellings = ["nothrow"];
359 }
360
361 def NSReturnsRetained : InheritableAttr {
362   let Spellings = ["ns_returns_retained"];
363   let Subjects = [ObjCMethod, Function];
364 }
365
366 def NSReturnsNotRetained : InheritableAttr {
367   let Spellings = ["ns_returns_not_retained"];
368   let Subjects = [ObjCMethod, Function];
369 }
370
371 def NSReturnsAutoreleased : InheritableAttr {
372   let Spellings = ["ns_returns_autoreleased"];
373   let Subjects = [ObjCMethod, Function];
374 }
375
376 def NSConsumesSelf : InheritableAttr {
377   let Spellings = ["ns_consumes_self"];
378   let Subjects = [ObjCMethod];
379 }
380
381 def NSConsumed : InheritableParamAttr {
382   let Spellings = ["ns_consumed"];
383   let Subjects = [ParmVar];
384 }
385
386 def ObjCException : InheritableAttr {
387   let Spellings = ["objc_exception"];
388 }
389
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"]>];
397 }
398
399 def ObjCNSObject : InheritableAttr {
400   let Spellings = ["NSObject"];
401 }
402
403 def ObjCPreciseLifetime : Attr {
404   let Spellings = ["objc_precise_lifetime"];
405   let Subjects = [Var];
406 }
407
408 def Overloadable : Attr {
409   let Spellings = ["overloadable"];
410 }
411
412 def Override : InheritableAttr { 
413   let Spellings = [];
414 }
415
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">];
422 }
423
424 def Packed : InheritableAttr {
425   let Spellings = ["packed"];
426 }
427
428 def Pcs : InheritableAttr {
429   let Spellings = ["pcs"];
430   let Args = [EnumArgument<"PCS", "PCSType",
431                            ["aapcs", "aapcs-vfp"],
432                            ["AAPCS", "AAPCS_VFP"]>];
433 }
434
435 def Pure : InheritableAttr {
436   let Spellings = ["pure"];
437 }
438
439 def Regparm : InheritableAttr {
440   let Spellings = ["regparm"];
441   let Args = [UnsignedArgument<"NumParams">];
442 }
443
444 def ReqdWorkGroupSize : InheritableAttr {
445   let Spellings = ["reqd_work_group_size"];
446   let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
447               UnsignedArgument<"ZDim">];
448 }
449
450 def InitPriority : InheritableAttr {
451   let Spellings = ["init_priority"];
452   let Args = [UnsignedArgument<"Priority">];
453 }
454
455 def Section : InheritableAttr {
456   let Spellings = ["section"];
457   let Args = [StringArgument<"Name">];
458 }
459
460 def Sentinel : InheritableAttr {
461   let Spellings = ["sentinel"];
462   let Args = [DefaultIntArgument<"Sentinel", 0>,
463               DefaultIntArgument<"NullPos", 0>];
464 }
465
466 def StdCall : InheritableAttr {
467   let Spellings = ["stdcall", "__stdcall"];
468 }
469
470 def ThisCall : InheritableAttr {
471   let Spellings = ["thiscall", "__thiscall"];
472 }
473
474 def Pascal : InheritableAttr {
475   let Spellings = ["pascal", "__pascal"];
476 }
477
478 def TransparentUnion : InheritableAttr {
479   let Spellings = ["transparent_union"];
480 }
481
482 def Unavailable : InheritableAttr {
483   let Spellings = ["unavailable"];
484   let Args = [StringArgument<"Message">];
485 }
486
487 def ArcWeakrefUnavailable : InheritableAttr {
488   let Spellings = ["objc_arc_weak_reference_unavailable"];
489 }
490
491 def Unused : InheritableAttr {
492   let Spellings = ["unused"];
493 }
494
495 def Used : InheritableAttr {
496   let Spellings = ["used"];
497 }
498
499 def Uuid : InheritableAttr {
500   let Spellings = ["uuid"];
501   let Args = [StringArgument<"Guid">];
502   let Subjects = [CXXRecord];
503 }
504
505 def Visibility : InheritableAttr {
506   let Spellings = ["visibility"];
507   let Args = [EnumArgument<"Visibility", "VisibilityType",
508                            ["default", "hidden", "internal", "protected"],
509                            ["Default", "Hidden", "Hidden", "Protected"]>];
510 }
511
512 def VecReturn : InheritableAttr {
513   let Spellings = ["vecreturn"];
514   let Subjects = [CXXRecord];
515 }
516
517 def WarnUnusedResult : InheritableAttr {
518   let Spellings = ["warn_unused_result"];
519 }
520
521 def Weak : InheritableAttr {
522   let Spellings = ["weak"];
523 }
524
525 def WeakImport : InheritableAttr {
526   let Spellings = ["weak_import"];
527 }
528
529 def WeakRef : InheritableAttr {
530   let Spellings = ["weakref"];
531 }
532
533 def X86ForceAlignArgPointer : InheritableAttr {
534   let Spellings = [];
535 }