]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Sema/AttributeList.h
Update xz to release 5.0.0
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Sema / AttributeList.h
1 //===--- AttributeList.h - Parsed attribute sets ----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the AttributeList class, which is used to collect
11 // parsed attributes.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_SEMA_ATTRLIST_H
16 #define LLVM_CLANG_SEMA_ATTRLIST_H
17
18 #include "clang/Sema/Ownership.h"
19 #include "clang/Basic/SourceLocation.h"
20 #include <cassert>
21
22 namespace clang {
23   class IdentifierInfo;
24   class Expr;
25
26 /// AttributeList - Represents GCC's __attribute__ declaration. There are
27 /// 4 forms of this construct...they are:
28 ///
29 /// 1: __attribute__(( const )). ParmName/Args/NumArgs will all be unused.
30 /// 2: __attribute__(( mode(byte) )). ParmName used, Args/NumArgs unused.
31 /// 3: __attribute__(( format(printf, 1, 2) )). ParmName/Args/NumArgs all used.
32 /// 4: __attribute__(( aligned(16) )). ParmName is unused, Args/Num used.
33 ///
34 class AttributeList {
35   IdentifierInfo *AttrName;
36   SourceLocation AttrLoc;
37   IdentifierInfo *ScopeName;
38   SourceLocation ScopeLoc;
39   IdentifierInfo *ParmName;
40   SourceLocation ParmLoc;
41   Expr **Args;
42   unsigned NumArgs;
43   AttributeList *Next;
44   bool DeclspecAttribute, CXX0XAttribute;
45   mutable bool Invalid; /// True if already diagnosed as invalid.
46   AttributeList(const AttributeList &); // DO NOT IMPLEMENT
47   void operator=(const AttributeList &); // DO NOT IMPLEMENT
48 public:
49   AttributeList(IdentifierInfo *AttrName, SourceLocation AttrLoc,
50                 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
51                 IdentifierInfo *ParmName, SourceLocation ParmLoc,
52                 Expr **args, unsigned numargs,
53                 AttributeList *Next, bool declspec = false, bool cxx0x = false);
54   ~AttributeList();
55
56   enum Kind {             // Please keep this list alphabetized.
57     AT_IBAction,          // Clang-specific.
58     AT_IBOutlet,          // Clang-specific.
59     AT_IBOutletCollection, // Clang-specific.
60     AT_address_space,
61     AT_alias,
62     AT_aligned,
63     AT_always_inline,
64     AT_analyzer_noreturn,
65     AT_annotate,
66     AT_base_check,
67     AT_blocks,
68     AT_carries_dependency,
69     AT_cdecl,
70     AT_cleanup,
71     AT_const,
72     AT_constructor,
73     AT_deprecated,
74     AT_destructor,
75     AT_dllexport,
76     AT_dllimport,
77     AT_ext_vector_type,
78     AT_fastcall,
79     AT_final,
80     AT_format,
81     AT_format_arg,
82     AT_gnu_inline,
83     AT_hiding,
84     AT_malloc,
85     AT_mode,
86     AT_nodebug,
87     AT_noinline,
88     AT_no_instrument_function,
89     AT_nonnull,
90     AT_noreturn,
91     AT_nothrow,
92     AT_nsobject,
93     AT_objc_exception,
94     AT_override,
95     AT_cf_returns_not_retained, // Clang-specific.
96     AT_cf_returns_retained,     // Clang-specific.
97     AT_ns_returns_not_retained, // Clang-specific.
98     AT_ns_returns_retained,     // Clang-specific.
99     AT_objc_gc,
100     AT_overloadable,       // Clang-specific.
101     AT_ownership_holds,    // Clang-specific.
102     AT_ownership_returns,  // Clang-specific.
103     AT_ownership_takes,    // Clang-specific.
104     AT_packed,
105     AT_pascal,
106     AT_pure,
107     AT_regparm,
108     AT_section,
109     AT_sentinel,
110     AT_stdcall,
111     AT_thiscall,
112     AT_transparent_union,
113     AT_unavailable,
114     AT_unused,
115     AT_used,
116     AT_vecreturn,     // PS3 PPU-specific.
117     AT_vector_size,
118     AT_visibility,
119     AT_warn_unused_result,
120     AT_weak,
121     AT_weakref,
122     AT_weak_import,
123     AT_reqd_wg_size,
124     AT_init_priority,
125     IgnoredAttribute,
126     UnknownAttribute
127   };
128
129   IdentifierInfo *getName() const { return AttrName; }
130   SourceLocation getLoc() const { return AttrLoc; }
131   
132   bool hasScope() const { return ScopeName; }
133   IdentifierInfo *getScopeName() const { return ScopeName; }
134   SourceLocation getScopeLoc() const { return ScopeLoc; }
135   
136   IdentifierInfo *getParameterName() const { return ParmName; }
137
138   bool isDeclspecAttribute() const { return DeclspecAttribute; }
139   bool isCXX0XAttribute() const { return CXX0XAttribute; }
140
141   bool isInvalid() const { return Invalid; }
142   void setInvalid(bool b = true) const { Invalid = b; }
143
144   Kind getKind() const { return getKind(getName()); }
145   static Kind getKind(const IdentifierInfo *Name);
146
147   AttributeList *getNext() const { return Next; }
148   void setNext(AttributeList *N) { Next = N; }
149
150   /// getNumArgs - Return the number of actual arguments to this attribute.
151   unsigned getNumArgs() const { return NumArgs; }
152
153   /// getArg - Return the specified argument.
154   Expr *getArg(unsigned Arg) const {
155     assert(Arg < NumArgs && "Arg access out of range!");
156     return Args[Arg];
157   }
158
159   class arg_iterator {
160     Expr** X;
161     unsigned Idx;
162   public:
163     arg_iterator(Expr** x, unsigned idx) : X(x), Idx(idx) {}
164
165     arg_iterator& operator++() {
166       ++Idx;
167       return *this;
168     }
169
170     bool operator==(const arg_iterator& I) const {
171       assert (X == I.X &&
172               "compared arg_iterators are for different argument lists");
173       return Idx == I.Idx;
174     }
175
176     bool operator!=(const arg_iterator& I) const {
177       return !operator==(I);
178     }
179
180     Expr* operator*() const {
181       return X[Idx];
182     }
183
184     unsigned getArgNum() const {
185       return Idx+1;
186     }
187   };
188
189   arg_iterator arg_begin() const {
190     return arg_iterator(Args, 0);
191   }
192
193   arg_iterator arg_end() const {
194     return arg_iterator(Args, NumArgs);
195   }
196 };
197
198 /// addAttributeLists - Add two AttributeLists together
199 /// The right-hand list is appended to the left-hand list, if any
200 /// A pointer to the joined list is returned.
201 /// Note: the lists are not left unmodified.
202 inline AttributeList* addAttributeLists (AttributeList *Left,
203                                          AttributeList *Right) {
204   if (!Left)
205     return Right;
206
207   AttributeList *next = Left, *prev;
208   do {
209     prev = next;
210     next = next->getNext();
211   } while (next);
212   prev->setNext(Right);
213   return Left;
214 }
215
216 /// CXX0XAttributeList - A wrapper around a C++0x attribute list.
217 /// Stores, in addition to the list proper, whether or not an actual list was
218 /// (as opposed to an empty list, which may be ill-formed in some places) and
219 /// the source range of the list.
220 struct CXX0XAttributeList { 
221   AttributeList *AttrList;
222   SourceRange Range;
223   bool HasAttr;
224   CXX0XAttributeList (AttributeList *attrList, SourceRange range, bool hasAttr)
225     : AttrList(attrList), Range(range), HasAttr (hasAttr) {
226   }
227   CXX0XAttributeList ()
228     : AttrList(0), Range(), HasAttr(false) {
229   }
230 };
231
232 }  // end namespace clang
233
234 #endif