1 //===--- AttributeList.h - Parsed attribute sets ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the AttributeList class, which is used to collect
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_SEMA_ATTRLIST_H
16 #define LLVM_CLANG_SEMA_ATTRLIST_H
18 #include "clang/Sema/Ownership.h"
19 #include "clang/Basic/SourceLocation.h"
26 /// AttributeList - Represents GCC's __attribute__ declaration. There are
27 /// 4 forms of this construct...they are:
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.
35 IdentifierInfo *AttrName;
36 SourceLocation AttrLoc;
37 IdentifierInfo *ScopeName;
38 SourceLocation ScopeLoc;
39 IdentifierInfo *ParmName;
40 SourceLocation ParmLoc;
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
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);
56 enum Kind { // Please keep this list alphabetized.
57 AT_IBAction, // Clang-specific.
58 AT_IBOutlet, // Clang-specific.
59 AT_IBOutletCollection, // Clang-specific.
68 AT_carries_dependency,
88 AT_no_instrument_function,
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.
100 AT_overloadable, // Clang-specific.
101 AT_ownership_holds, // Clang-specific.
102 AT_ownership_returns, // Clang-specific.
103 AT_ownership_takes, // Clang-specific.
112 AT_transparent_union,
116 AT_vecreturn, // PS3 PPU-specific.
119 AT_warn_unused_result,
129 IdentifierInfo *getName() const { return AttrName; }
130 SourceLocation getLoc() const { return AttrLoc; }
132 bool hasScope() const { return ScopeName; }
133 IdentifierInfo *getScopeName() const { return ScopeName; }
134 SourceLocation getScopeLoc() const { return ScopeLoc; }
136 IdentifierInfo *getParameterName() const { return ParmName; }
138 bool isDeclspecAttribute() const { return DeclspecAttribute; }
139 bool isCXX0XAttribute() const { return CXX0XAttribute; }
141 bool isInvalid() const { return Invalid; }
142 void setInvalid(bool b = true) const { Invalid = b; }
144 Kind getKind() const { return getKind(getName()); }
145 static Kind getKind(const IdentifierInfo *Name);
147 AttributeList *getNext() const { return Next; }
148 void setNext(AttributeList *N) { Next = N; }
150 /// getNumArgs - Return the number of actual arguments to this attribute.
151 unsigned getNumArgs() const { return NumArgs; }
153 /// getArg - Return the specified argument.
154 Expr *getArg(unsigned Arg) const {
155 assert(Arg < NumArgs && "Arg access out of range!");
163 arg_iterator(Expr** x, unsigned idx) : X(x), Idx(idx) {}
165 arg_iterator& operator++() {
170 bool operator==(const arg_iterator& I) const {
172 "compared arg_iterators are for different argument lists");
176 bool operator!=(const arg_iterator& I) const {
177 return !operator==(I);
180 Expr* operator*() const {
184 unsigned getArgNum() const {
189 arg_iterator arg_begin() const {
190 return arg_iterator(Args, 0);
193 arg_iterator arg_end() const {
194 return arg_iterator(Args, NumArgs);
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) {
207 AttributeList *next = Left, *prev;
210 next = next->getNext();
212 prev->setNext(Right);
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;
224 CXX0XAttributeList (AttributeList *attrList, SourceRange range, bool hasAttr)
225 : AttrList(attrList), Range(range), HasAttr (hasAttr) {
227 CXX0XAttributeList ()
228 : AttrList(0), Range(), HasAttr(false) {
232 } // end namespace clang