1 //===--- Attr.h - Classes for representing attributes ----------*- 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 "clang/AST/AttrIterator.h" 18 #include "clang/AST/Type.h" 19 #include "clang/Basic/AttrKinds.h" 20 #include "clang/Basic/LLVM.h" 21 #include "clang/Basic/SourceLocation.h" 22 #include "clang/Basic/VersionTuple.h" 23 #include "llvm/ADT/SmallVector.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/ADT/StringSwitch.h" 26 #include "llvm/Support/ErrorHandling.h" 27 #include "llvm/Support/raw_ostream.h" 28 #include <cassert> 29 #include <cstring> 30 31 namespace clang { 32 class ASTContext; 33 class IdentifierInfo; 34 class ObjCInterfaceDecl; 35 class Expr; 36 class QualType; 37 class FunctionDecl; 38 class TypeSourceInfo; 39 40 /// Attr - This represents one attribute. 41 class Attr { 42 private: 43 SourceRange Range; 44 unsigned AttrKind : 16; 45 46 protected: 47 /// An index into the spelling list of an 48 /// attribute defined in Attr.td file. 49 unsigned SpellingListIndex : 4; 50 51 bool Inherited : 1; 52 53 bool IsPackExpansion : 1; 54 55 virtual ~Attr(); 56 new(size_t bytes)57 void* operator new(size_t bytes) throw() { 58 llvm_unreachable("Attrs cannot be allocated with regular 'new'."); 59 } delete(void * data)60 void operator delete(void* data) throw() { 61 llvm_unreachable("Attrs cannot be released with regular 'delete'."); 62 } 63 64 public: 65 // Forward so that the regular new and delete do not hide global ones. 66 void* operator new(size_t Bytes, ASTContext &C, throw()67 size_t Alignment = 16) throw() { 68 return ::operator new(Bytes, C, Alignment); 69 } delete(void * Ptr,ASTContext & C,size_t Alignment)70 void operator delete(void *Ptr, ASTContext &C, 71 size_t Alignment) throw() { 72 return ::operator delete(Ptr, C, Alignment); 73 } 74 75 protected: 76 Attr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0) Range(R)77 : Range(R), AttrKind(AK), SpellingListIndex(SpellingListIndex), 78 Inherited(false), IsPackExpansion(false) {} 79 80 public: 81 getKind()82 attr::Kind getKind() const { 83 return static_cast<attr::Kind>(AttrKind); 84 } 85 getSpellingListIndex()86 unsigned getSpellingListIndex() const { return SpellingListIndex; } 87 getLocation()88 SourceLocation getLocation() const { return Range.getBegin(); } getRange()89 SourceRange getRange() const { return Range; } setRange(SourceRange R)90 void setRange(SourceRange R) { Range = R; } 91 isInherited()92 bool isInherited() const { return Inherited; } 93 setPackExpansion(bool PE)94 void setPackExpansion(bool PE) { IsPackExpansion = PE; } isPackExpansion()95 bool isPackExpansion() const { return IsPackExpansion; } 96 97 // Clone this attribute. 98 virtual Attr *clone(ASTContext &C) const = 0; 99 isLateParsed()100 virtual bool isLateParsed() const { return false; } 101 102 // Pretty print this attribute. 103 virtual void printPretty(raw_ostream &OS, 104 const PrintingPolicy &Policy) const = 0; 105 }; 106 107 class InheritableAttr : public Attr { 108 virtual void anchor(); 109 protected: 110 InheritableAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0) Attr(AK,R,SpellingListIndex)111 : Attr(AK, R, SpellingListIndex) {} 112 113 public: setInherited(bool I)114 void setInherited(bool I) { Inherited = I; } 115 116 // Implement isa/cast/dyncast/etc. classof(const Attr * A)117 static bool classof(const Attr *A) { 118 return A->getKind() <= attr::LAST_INHERITABLE; 119 } 120 }; 121 122 class InheritableParamAttr : public InheritableAttr { 123 virtual void anchor(); 124 protected: 125 InheritableParamAttr(attr::Kind AK, SourceRange R, 126 unsigned SpellingListIndex = 0) InheritableAttr(AK,R,SpellingListIndex)127 : InheritableAttr(AK, R, SpellingListIndex) {} 128 129 public: 130 // Implement isa/cast/dyncast/etc. classof(const Attr * A)131 static bool classof(const Attr *A) { 132 return A->getKind() <= attr::LAST_INHERITABLE_PARAM; 133 } 134 }; 135 136 #include "clang/AST/Attrs.inc" 137 138 } // end namespace clang 139 140 #endif 141