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