Attr.h revision 55b0c192e1ce00513a000f4c98bed7da5cf152b8
1//===--- Attr.h - Classes for representing expressions ----------*- 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 Attr interface and subclasses. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_ATTR_H 15#define LLVM_CLANG_AST_ATTR_H 16 17#include <cassert> 18#include <cstring> 19#include <string> 20#include <algorithm> 21 22namespace clang { 23 24/// Attr - This represents one attribute. 25class Attr { 26public: 27 enum Kind { 28 Alias, 29 Aligned, 30 Annotate, 31 AsmLabel, // Represent GCC asm label extension. 32 Constructor, 33 Deprecated, 34 Destructor, 35 DLLImport, 36 DLLExport, 37 FastCall, 38 Format, 39 IBOutletKind, // Clang-specific. Use "Kind" suffix to not conflict with 40 NonNull, 41 NoReturn, 42 NoThrow, 43 Packed, 44 StdCall, 45 TransparentUnion, 46 Unused, 47 Visibility, 48 Weak 49 }; 50 51private: 52 Attr *Next; 53 Kind AttrKind; 54 55protected: 56 Attr(Kind AK) : Next(0), AttrKind(AK) {} 57public: 58 virtual ~Attr() { 59 delete Next; 60 } 61 62 Kind getKind() const { return AttrKind; } 63 64 Attr *getNext() { return Next; } 65 const Attr *getNext() const { return Next; } 66 void setNext(Attr *next) { Next = next; } 67 68 void addAttr(Attr *attr) { 69 assert((attr != 0) && "addAttr(): attr is null"); 70 71 // FIXME: This doesn't preserve the order in any way. 72 attr->Next = Next; 73 Next = attr; 74 } 75 76 // Implement isa/cast/dyncast/etc. 77 static bool classof(const Attr *) { return true; } 78}; 79 80class PackedAttr : public Attr { 81public: 82 PackedAttr() : Attr(Packed) {} 83 84 // Implement isa/cast/dyncast/etc. 85 static bool classof(const Attr *A) { 86 return A->getKind() == Packed; 87 } 88 static bool classof(const PackedAttr *A) { return true; } 89}; 90 91class AlignedAttr : public Attr { 92 unsigned Alignment; 93public: 94 AlignedAttr(unsigned alignment) : Attr(Aligned), Alignment(alignment) {} 95 96 unsigned getAlignment() const { return Alignment; } 97 98 // Implement isa/cast/dyncast/etc. 99 static bool classof(const Attr *A) { 100 return A->getKind() == Aligned; 101 } 102 static bool classof(const AlignedAttr *A) { return true; } 103}; 104 105class AnnotateAttr : public Attr { 106 std::string Annotation; 107public: 108 AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {} 109 110 const std::string& getAnnotation() const { return Annotation; } 111 112 // Implement isa/cast/dyncast/etc. 113 static bool classof(const Attr *A) { 114 return A->getKind() == Annotate; 115 } 116 static bool classof(const AnnotateAttr *A) { return true; } 117}; 118 119class AsmLabelAttr : public Attr { 120 std::string Label; 121public: 122 AsmLabelAttr(const std::string &L) : Attr(AsmLabel), Label(L) {} 123 124 const std::string& getLabel() const { return Label; } 125 126 // Implement isa/cast/dyncast/etc. 127 static bool classof(const Attr *A) { 128 return A->getKind() == AsmLabel; 129 } 130 static bool classof(const AsmLabelAttr *A) { return true; } 131}; 132 133class AliasAttr : public Attr { 134 std::string Aliasee; 135public: 136 AliasAttr(const std::string &aliasee) : Attr(Alias), Aliasee(aliasee) {} 137 138 const std::string& getAliasee() const { return Aliasee; } 139 140 // Implement isa/cast/dyncast/etc. 141 142 static bool classof(const Attr *A) { return A->getKind() == Alias; } 143 static bool classof(const AliasAttr *A) { return true; } 144}; 145 146class ConstructorAttr : public Attr { 147 int priority; 148public: 149 ConstructorAttr(int p) : Attr(Constructor), priority(p) {} 150 151 int getPriority() const { return priority; } 152 153 // Implement isa/cast/dyncast/etc. 154 static bool classof(const Attr *A) { return A->getKind() == Constructor; } 155 static bool classof(const ConstructorAttr *A) { return true; } 156}; 157 158class DestructorAttr : public Attr { 159 int priority; 160public: 161 DestructorAttr(int p) : Attr(Destructor), priority(p) {} 162 163 int getPriority() const { return priority; } 164 165 // Implement isa/cast/dyncast/etc. 166 static bool classof(const Attr *A) { return A->getKind() == Destructor; } 167 static bool classof(const DestructorAttr *A) { return true; } 168}; 169 170class IBOutletAttr : public Attr { 171public: 172 IBOutletAttr() : Attr(IBOutletKind) {} 173 174 // Implement isa/cast/dyncast/etc. 175 static bool classof(const Attr *A) { 176 return A->getKind() == IBOutletKind; 177 } 178 static bool classof(const IBOutletAttr *A) { return true; } 179}; 180 181class NoReturnAttr : public Attr { 182public: 183 NoReturnAttr() : Attr(NoReturn) {} 184 185 // Implement isa/cast/dyncast/etc. 186 187 static bool classof(const Attr *A) { return A->getKind() == NoReturn; } 188 static bool classof(const NoReturnAttr *A) { return true; } 189}; 190 191class DeprecatedAttr : public Attr { 192public: 193 DeprecatedAttr() : Attr(Deprecated) {} 194 195 // Implement isa/cast/dyncast/etc. 196 197 static bool classof(const Attr *A) { return A->getKind() == Deprecated; } 198 static bool classof(const DeprecatedAttr *A) { return true; } 199}; 200 201class UnusedAttr : public Attr { 202public: 203 UnusedAttr() : Attr(Unused) {} 204 205 // Implement isa/cast/dyncast/etc. 206 static bool classof(const Attr *A) { return A->getKind() == Unused; } 207 static bool classof(const UnusedAttr *A) { return true; } 208}; 209 210class WeakAttr : public Attr { 211public: 212 WeakAttr() : Attr(Weak) {} 213 214 // Implement isa/cast/dyncast/etc. 215 216 static bool classof(const Attr *A) { return A->getKind() == Weak; } 217 static bool classof(const WeakAttr *A) { return true; } 218}; 219 220class NoThrowAttr : public Attr { 221public: 222 NoThrowAttr() : Attr(NoThrow) {} 223 224 // Implement isa/cast/dyncast/etc. 225 226 static bool classof(const Attr *A) { return A->getKind() == NoThrow; } 227 static bool classof(const NoThrowAttr *A) { return true; } 228}; 229 230class NonNullAttr : public Attr { 231 unsigned* ArgNums; 232 unsigned Size; 233public: 234 NonNullAttr(unsigned* arg_nums = 0, unsigned size = 0) : Attr(NonNull), 235 ArgNums(0), Size(0) { 236 237 if (size) { 238 assert (arg_nums); 239 ArgNums = new unsigned[size]; 240 Size = size; 241 memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size); 242 } 243 } 244 245 virtual ~NonNullAttr() { 246 delete [] ArgNums; 247 } 248 249 bool isNonNull(unsigned arg) const { 250 return ArgNums ? std::binary_search(ArgNums, ArgNums+Size, arg) : true; 251 } 252 253 static bool classof(const Attr *A) { return A->getKind() == NonNull; } 254 static bool classof(const NonNullAttr *A) { return true; } 255}; 256 257class FormatAttr : public Attr { 258 std::string Type; 259 int formatIdx, firstArg; 260public: 261 FormatAttr(const std::string &type, int idx, int first) : Attr(Format), 262 Type(type), formatIdx(idx), firstArg(first) {} 263 264 const std::string& getType() const { return Type; } 265 int getFormatIdx() const { return formatIdx; } 266 int getFirstArg() const { return firstArg; } 267 268 // Implement isa/cast/dyncast/etc. 269 270 static bool classof(const Attr *A) { return A->getKind() == Format; } 271 static bool classof(const FormatAttr *A) { return true; } 272}; 273 274class VisibilityAttr : public Attr { 275public: 276 /// @brief An enumeration for the kinds of visibility of symbols. 277 enum VisibilityTypes { 278 DefaultVisibility = 0, 279 HiddenVisibility, 280 ProtectedVisibility 281 }; 282private: 283 VisibilityTypes VisibilityType; 284public: 285 VisibilityAttr(VisibilityTypes v) : Attr(Visibility), 286 VisibilityType(v) {} 287 288 VisibilityTypes getVisibility() const { return VisibilityType; } 289 290 // Implement isa/cast/dyncast/etc. 291 292 static bool classof(const Attr *A) { return A->getKind() == Visibility; } 293 static bool classof(const VisibilityAttr *A) { return true; } 294}; 295 296class DLLImportAttr : public Attr { 297public: 298 DLLImportAttr() : Attr(DLLImport) {} 299 300 // Implement isa/cast/dyncast/etc. 301 302 static bool classof(const Attr *A) { return A->getKind() == DLLImport; } 303 static bool classof(const DLLImportAttr *A) { return true; } 304}; 305 306class DLLExportAttr : public Attr { 307public: 308 DLLExportAttr() : Attr(DLLExport) {} 309 310 // Implement isa/cast/dyncast/etc. 311 312 static bool classof(const Attr *A) { return A->getKind() == DLLExport; } 313 static bool classof(const DLLExportAttr *A) { return true; } 314}; 315 316class FastCallAttr : public Attr { 317public: 318 FastCallAttr() : Attr(FastCall) {} 319 320 // Implement isa/cast/dyncast/etc. 321 322 static bool classof(const Attr *A) { return A->getKind() == FastCall; } 323 static bool classof(const FastCallAttr *A) { return true; } 324}; 325 326class StdCallAttr : public Attr { 327public: 328 StdCallAttr() : Attr(StdCall) {} 329 330 // Implement isa/cast/dyncast/etc. 331 332 static bool classof(const Attr *A) { return A->getKind() == StdCall; } 333 static bool classof(const StdCallAttr *A) { return true; } 334}; 335 336class TransparentUnionAttr : public Attr { 337public: 338 TransparentUnionAttr() : Attr(TransparentUnion) {} 339 340 // Implement isa/cast/dyncast/etc. 341 342 static bool classof(const Attr *A) { return A->getKind() == TransparentUnion; } 343 static bool classof(const TransparentUnionAttr *A) { return true; } 344}; 345 346} // end namespace clang 347 348#endif 349