1 //===--- Attr.h - Classes for representing attributes ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Attr interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_ATTR_H
15 #define LLVM_CLANG_AST_ATTR_H
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"
34 class ObjCInterfaceDecl;
40 /// Attr - This represents one attribute.
44 unsigned AttrKind : 16;
47 /// An index into the spelling list of an
48 /// attribute defined in Attr.td file.
49 unsigned SpellingListIndex : 4;
53 bool IsPackExpansion : 1;
57 void* operator new(size_t bytes) throw() {
58 llvm_unreachable("Attrs cannot be allocated with regular 'new'.");
60 void operator delete(void* data) throw() {
61 llvm_unreachable("Attrs cannot be released with regular 'delete'.");
65 // Forward so that the regular new and delete do not hide global ones.
66 void* operator new(size_t Bytes, ASTContext &C,
67 size_t Alignment = 16) throw() {
68 return ::operator new(Bytes, C, Alignment);
70 void operator delete(void *Ptr, ASTContext &C,
71 size_t Alignment) throw() {
72 return ::operator delete(Ptr, C, Alignment);
76 Attr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
77 : Range(R), AttrKind(AK), SpellingListIndex(SpellingListIndex),
78 Inherited(false), IsPackExpansion(false) {}
82 attr::Kind getKind() const {
83 return static_cast<attr::Kind>(AttrKind);
86 unsigned getSpellingListIndex() const { return SpellingListIndex; }
88 SourceLocation getLocation() const { return Range.getBegin(); }
89 SourceRange getRange() const { return Range; }
90 void setRange(SourceRange R) { Range = R; }
92 bool isInherited() const { return Inherited; }
94 void setPackExpansion(bool PE) { IsPackExpansion = PE; }
95 bool isPackExpansion() const { return IsPackExpansion; }
97 // Clone this attribute.
98 virtual Attr *clone(ASTContext &C) const = 0;
100 virtual bool isLateParsed() const { return false; }
102 // Pretty print this attribute.
103 virtual void printPretty(raw_ostream &OS,
104 const PrintingPolicy &Policy) const = 0;
107 class InheritableAttr : public Attr {
108 virtual void anchor();
110 InheritableAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
111 : Attr(AK, R, SpellingListIndex) {}
114 void setInherited(bool I) { Inherited = I; }
116 // Implement isa/cast/dyncast/etc.
117 static bool classof(const Attr *A) {
118 return A->getKind() <= attr::LAST_INHERITABLE;
122 class InheritableParamAttr : public InheritableAttr {
123 virtual void anchor();
125 InheritableParamAttr(attr::Kind AK, SourceRange R,
126 unsigned SpellingListIndex = 0)
127 : InheritableAttr(AK, R, SpellingListIndex) {}
130 // Implement isa/cast/dyncast/etc.
131 static bool classof(const Attr *A) {
132 // Relies on relative order of enum emission with respect to MS inheritance
134 return A->getKind() <= attr::LAST_INHERITABLE_PARAM;
138 class MSInheritanceAttr : public InheritableAttr {
139 virtual void anchor();
141 MSInheritanceAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
142 : InheritableAttr(AK, R, SpellingListIndex) {}
145 // Implement isa/cast/dyncast/etc.
146 static bool classof(const Attr *A) {
147 // Relies on relative order of enum emission with respect to param attrs.
148 return (A->getKind() <= attr::LAST_MS_INHERITABLE &&
149 A->getKind() > attr::LAST_INHERITABLE_PARAM);
153 #include "clang/AST/Attrs.inc"
155 } // end namespace clang