Attr.h revision 2f402708e62f89fb875442802e3d3f20fc909d33
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 AlwaysInline, 31 Annotate, 32 AsmLabel, // Represent GCC asm label extension. 33 Constructor, 34 Deprecated, 35 Destructor, 36 DLLImport, 37 DLLExport, 38 FastCall, 39 Format, 40 IBOutletKind, // Clang-specific. Use "Kind" suffix to not conflict with 41 NonNull, 42 NoReturn, 43 NoThrow, 44 ObjCGC, 45 Packed, 46 StdCall, 47 TransparentUnion, 48 Unavailable, 49 Unused, 50 Visibility, 51 Weak, 52 Blocks, 53 Const, 54 Pure 55 }; 56 57private: 58 Attr *Next; 59 Kind AttrKind; 60 bool Inherited : 1; 61 62protected: 63 Attr(Kind AK) : Next(0), AttrKind(AK), Inherited(false) {} 64public: 65 virtual ~Attr() { 66 delete Next; 67 } 68 69 Kind getKind() const { return AttrKind; } 70 71 bool hasKind(Kind kind) const { 72 return AttrKind == kind; 73 } 74 75 Attr *getNext() { return Next; } 76 const Attr *getNext() const { return Next; } 77 void setNext(Attr *next) { Next = next; } 78 79 bool isInherited() const { return Inherited; } 80 void setInherited(bool value) { Inherited = value; } 81 82 void addAttr(Attr *attr) { 83 assert((attr != 0) && "addAttr(): attr is null"); 84 85 // FIXME: This doesn't preserve the order in any way. 86 attr->Next = Next; 87 Next = attr; 88 } 89 90 // Implement isa/cast/dyncast/etc. 91 static bool classof(const Attr *) { return true; } 92}; 93 94class PackedAttr : public Attr { 95 unsigned Alignment; 96 97public: 98 PackedAttr(unsigned alignment) : Attr(Packed), Alignment(alignment) {} 99 100 /// getAlignment - The specified alignment in bits. 101 unsigned getAlignment() const { return Alignment; } 102 103 // Implement isa/cast/dyncast/etc. 104 static bool classof(const Attr *A) { 105 return A->getKind() == Packed; 106 } 107 static bool classof(const PackedAttr *A) { return true; } 108}; 109 110class AlignedAttr : public Attr { 111 unsigned Alignment; 112public: 113 AlignedAttr(unsigned alignment) : Attr(Aligned), Alignment(alignment) {} 114 115 /// getAlignment - The specified alignment in bits. 116 unsigned getAlignment() const { return Alignment; } 117 118 // Implement isa/cast/dyncast/etc. 119 static bool classof(const Attr *A) { 120 return A->getKind() == Aligned; 121 } 122 static bool classof(const AlignedAttr *A) { return true; } 123}; 124 125class AnnotateAttr : public Attr { 126 std::string Annotation; 127public: 128 AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {} 129 130 const std::string& getAnnotation() const { return Annotation; } 131 132 // Implement isa/cast/dyncast/etc. 133 static bool classof(const Attr *A) { 134 return A->getKind() == Annotate; 135 } 136 static bool classof(const AnnotateAttr *A) { return true; } 137}; 138 139class AsmLabelAttr : public Attr { 140 std::string Label; 141public: 142 AsmLabelAttr(const std::string &L) : Attr(AsmLabel), Label(L) {} 143 144 const std::string& getLabel() const { return Label; } 145 146 // Implement isa/cast/dyncast/etc. 147 static bool classof(const Attr *A) { 148 return A->getKind() == AsmLabel; 149 } 150 static bool classof(const AsmLabelAttr *A) { return true; } 151}; 152 153class AlwaysInlineAttr : public Attr { 154public: 155 AlwaysInlineAttr() : Attr(AlwaysInline) {} 156 157 // Implement isa/cast/dyncast/etc. 158 159 static bool classof(const Attr *A) { return A->getKind() == AlwaysInline; } 160 static bool classof(const AlwaysInlineAttr *A) { return true; } 161}; 162 163class AliasAttr : public Attr { 164 std::string Aliasee; 165public: 166 AliasAttr(const std::string &aliasee) : Attr(Alias), Aliasee(aliasee) {} 167 168 const std::string& getAliasee() const { return Aliasee; } 169 170 // Implement isa/cast/dyncast/etc. 171 172 static bool classof(const Attr *A) { return A->getKind() == Alias; } 173 static bool classof(const AliasAttr *A) { return true; } 174}; 175 176class ConstructorAttr : public Attr { 177 int priority; 178public: 179 ConstructorAttr(int p) : Attr(Constructor), priority(p) {} 180 181 int getPriority() const { return priority; } 182 183 // Implement isa/cast/dyncast/etc. 184 static bool classof(const Attr *A) { return A->getKind() == Constructor; } 185 static bool classof(const ConstructorAttr *A) { return true; } 186}; 187 188class DestructorAttr : public Attr { 189 int priority; 190public: 191 DestructorAttr(int p) : Attr(Destructor), priority(p) {} 192 193 int getPriority() const { return priority; } 194 195 // Implement isa/cast/dyncast/etc. 196 static bool classof(const Attr *A) { return A->getKind() == Destructor; } 197 static bool classof(const DestructorAttr *A) { return true; } 198}; 199 200class IBOutletAttr : public Attr { 201public: 202 IBOutletAttr() : Attr(IBOutletKind) {} 203 204 // Implement isa/cast/dyncast/etc. 205 static bool classof(const Attr *A) { 206 return A->getKind() == IBOutletKind; 207 } 208 static bool classof(const IBOutletAttr *A) { return true; } 209}; 210 211class NoReturnAttr : public Attr { 212public: 213 NoReturnAttr() : Attr(NoReturn) {} 214 215 // Implement isa/cast/dyncast/etc. 216 217 static bool classof(const Attr *A) { return A->getKind() == NoReturn; } 218 static bool classof(const NoReturnAttr *A) { return true; } 219}; 220 221class DeprecatedAttr : public Attr { 222public: 223 DeprecatedAttr() : Attr(Deprecated) {} 224 225 // Implement isa/cast/dyncast/etc. 226 227 static bool classof(const Attr *A) { return A->getKind() == Deprecated; } 228 static bool classof(const DeprecatedAttr *A) { return true; } 229}; 230 231class UnavailableAttr : public Attr { 232public: 233 UnavailableAttr() : Attr(Unavailable) {} 234 235 // Implement isa/cast/dyncast/etc. 236 237 static bool classof(const Attr *A) { return A->getKind() == Unavailable; } 238 static bool classof(const UnavailableAttr *A) { return true; } 239}; 240 241class UnusedAttr : public Attr { 242public: 243 UnusedAttr() : Attr(Unused) {} 244 245 // Implement isa/cast/dyncast/etc. 246 static bool classof(const Attr *A) { return A->getKind() == Unused; } 247 static bool classof(const UnusedAttr *A) { return true; } 248}; 249 250class WeakAttr : public Attr { 251public: 252 WeakAttr() : Attr(Weak) {} 253 254 // Implement isa/cast/dyncast/etc. 255 256 static bool classof(const Attr *A) { return A->getKind() == Weak; } 257 static bool classof(const WeakAttr *A) { return true; } 258}; 259 260class NoThrowAttr : public Attr { 261public: 262 NoThrowAttr() : Attr(NoThrow) {} 263 264 // Implement isa/cast/dyncast/etc. 265 266 static bool classof(const Attr *A) { return A->getKind() == NoThrow; } 267 static bool classof(const NoThrowAttr *A) { return true; } 268}; 269 270class ConstAttr : public Attr { 271public: 272 ConstAttr() : Attr(Const) {} 273 274 // Implement isa/cast/dyncast/etc. 275 276 static bool classof(const Attr *A) { return A->getKind() == Const; } 277 static bool classof(const ConstAttr *A) { return true; } 278}; 279 280class PureAttr : public Attr { 281public: 282 PureAttr() : Attr(Pure) {} 283 284 // Implement isa/cast/dyncast/etc. 285 286 static bool classof(const Attr *A) { return A->getKind() == Pure; } 287 static bool classof(const PureAttr *A) { return true; } 288}; 289 290class NonNullAttr : public Attr { 291 unsigned* ArgNums; 292 unsigned Size; 293public: 294 NonNullAttr(unsigned* arg_nums = 0, unsigned size = 0) : Attr(NonNull), 295 ArgNums(0), Size(0) { 296 297 if (size) { 298 assert (arg_nums); 299 ArgNums = new unsigned[size]; 300 Size = size; 301 memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size); 302 } 303 } 304 305 virtual ~NonNullAttr() { 306 delete [] ArgNums; 307 } 308 309 bool isNonNull(unsigned arg) const { 310 return ArgNums ? std::binary_search(ArgNums, ArgNums+Size, arg) : true; 311 } 312 313 static bool classof(const Attr *A) { return A->getKind() == NonNull; } 314 static bool classof(const NonNullAttr *A) { return true; } 315}; 316 317class FormatAttr : public Attr { 318 std::string Type; 319 int formatIdx, firstArg; 320public: 321 FormatAttr(const std::string &type, int idx, int first) : Attr(Format), 322 Type(type), formatIdx(idx), firstArg(first) {} 323 324 const std::string& getType() const { return Type; } 325 int getFormatIdx() const { return formatIdx; } 326 int getFirstArg() const { return firstArg; } 327 328 // Implement isa/cast/dyncast/etc. 329 330 static bool classof(const Attr *A) { return A->getKind() == Format; } 331 static bool classof(const FormatAttr *A) { return true; } 332}; 333 334class VisibilityAttr : public Attr { 335public: 336 /// @brief An enumeration for the kinds of visibility of symbols. 337 enum VisibilityTypes { 338 DefaultVisibility = 0, 339 HiddenVisibility, 340 ProtectedVisibility 341 }; 342private: 343 VisibilityTypes VisibilityType; 344public: 345 VisibilityAttr(VisibilityTypes v) : Attr(Visibility), 346 VisibilityType(v) {} 347 348 VisibilityTypes getVisibility() const { return VisibilityType; } 349 350 // Implement isa/cast/dyncast/etc. 351 352 static bool classof(const Attr *A) { return A->getKind() == Visibility; } 353 static bool classof(const VisibilityAttr *A) { return true; } 354}; 355 356class DLLImportAttr : public Attr { 357public: 358 DLLImportAttr() : Attr(DLLImport) {} 359 360 // Implement isa/cast/dyncast/etc. 361 362 static bool classof(const Attr *A) { return A->getKind() == DLLImport; } 363 static bool classof(const DLLImportAttr *A) { return true; } 364}; 365 366class DLLExportAttr : public Attr { 367public: 368 DLLExportAttr() : Attr(DLLExport) {} 369 370 // Implement isa/cast/dyncast/etc. 371 372 static bool classof(const Attr *A) { return A->getKind() == DLLExport; } 373 static bool classof(const DLLExportAttr *A) { return true; } 374}; 375 376class FastCallAttr : public Attr { 377public: 378 FastCallAttr() : Attr(FastCall) {} 379 380 // Implement isa/cast/dyncast/etc. 381 382 static bool classof(const Attr *A) { return A->getKind() == FastCall; } 383 static bool classof(const FastCallAttr *A) { return true; } 384}; 385 386class StdCallAttr : public Attr { 387public: 388 StdCallAttr() : Attr(StdCall) {} 389 390 // Implement isa/cast/dyncast/etc. 391 392 static bool classof(const Attr *A) { return A->getKind() == StdCall; } 393 static bool classof(const StdCallAttr *A) { return true; } 394}; 395 396class TransparentUnionAttr : public Attr { 397public: 398 TransparentUnionAttr() : Attr(TransparentUnion) {} 399 400 // Implement isa/cast/dyncast/etc. 401 402 static bool classof(const Attr *A) { return A->getKind() == TransparentUnion; } 403 static bool classof(const TransparentUnionAttr *A) { return true; } 404}; 405 406class ObjCGCAttr : public Attr { 407public: 408 enum GCAttrTypes { 409 Weak = 0, 410 Strong 411 }; 412private: 413 GCAttrTypes GCAttrType; 414public: 415 ObjCGCAttr(GCAttrTypes t) : Attr(ObjCGC), GCAttrType(t) {} 416 417 GCAttrTypes getType() const { return GCAttrType; } 418 419 // Implement isa/cast/dyncast/etc. 420 421 static bool classof(const Attr *A) { return A->getKind() == ObjCGC; } 422 static bool classof(const ObjCGCAttr *A) { return true; } 423}; 424 425class BlocksAttr : public Attr { 426public: 427 enum BlocksAttrTypes { 428 ByRef = 0 429 }; 430private: 431 BlocksAttrTypes BlocksAttrType; 432public: 433 BlocksAttr(BlocksAttrTypes t) : Attr(Blocks), BlocksAttrType(t) {} 434 435 BlocksAttrTypes getType() const { return BlocksAttrType; } 436 437 // Implement isa/cast/dyncast/etc. 438 439 static bool classof(const Attr *A) { return A->getKind() == Blocks; } 440 static bool classof(const ObjCGCAttr *A) { return true; } 441}; 442 443} // end namespace clang 444 445#endif 446