Attr.h revision 51d8c52ad36129760eaa586f85176037e2cd0d0e
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 31namespace 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. 41class Attr { 42private: 43 SourceRange Range; 44 unsigned AttrKind : 16; 45 46protected: 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 virtual ~Attr(); 54 55 void* operator new(size_t bytes) throw() { 56 llvm_unreachable("Attrs cannot be allocated with regular 'new'."); 57 } 58 void operator delete(void* data) throw() { 59 llvm_unreachable("Attrs cannot be released with regular 'delete'."); 60 } 61 62public: 63 // Forward so that the regular new and delete do not hide global ones. 64 void* operator new(size_t Bytes, ASTContext &C, 65 size_t Alignment = 16) throw() { 66 return ::operator new(Bytes, C, Alignment); 67 } 68 void operator delete(void *Ptr, ASTContext &C, 69 size_t Alignment) throw() { 70 return ::operator delete(Ptr, C, Alignment); 71 } 72 73protected: 74 Attr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0) 75 : Range(R), AttrKind(AK), SpellingListIndex(SpellingListIndex), 76 Inherited(false) {} 77 78public: 79 80 attr::Kind getKind() const { 81 return static_cast<attr::Kind>(AttrKind); 82 } 83 84 unsigned getSpellingListIndex() const { return SpellingListIndex; } 85 86 SourceLocation getLocation() const { return Range.getBegin(); } 87 SourceRange getRange() const { return Range; } 88 void setRange(SourceRange R) { Range = R; } 89 90 bool isInherited() const { return Inherited; } 91 92 // Clone this attribute. 93 virtual Attr* clone(ASTContext &C) const = 0; 94 95 virtual bool isLateParsed() const { return false; } 96 97 // Pretty print this attribute. 98 virtual void printPretty(raw_ostream &OS, 99 const PrintingPolicy &Policy) const = 0; 100}; 101 102class InheritableAttr : public Attr { 103 virtual void anchor(); 104protected: 105 InheritableAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0) 106 : Attr(AK, R, SpellingListIndex) {} 107 108public: 109 void setInherited(bool I) { Inherited = I; } 110 111 // Implement isa/cast/dyncast/etc. 112 static bool classof(const Attr *A) { 113 return A->getKind() <= attr::LAST_INHERITABLE; 114 } 115}; 116 117class InheritableParamAttr : public InheritableAttr { 118 virtual void anchor(); 119protected: 120 InheritableParamAttr(attr::Kind AK, SourceRange R, 121 unsigned SpellingListIndex = 0) 122 : InheritableAttr(AK, R, SpellingListIndex) {} 123 124public: 125 // Implement isa/cast/dyncast/etc. 126 static bool classof(const Attr *A) { 127 return A->getKind() <= attr::LAST_INHERITABLE_PARAM; 128 } 129}; 130 131#include "clang/AST/Attrs.inc" 132 133} // end namespace clang 134 135#endif 136