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/Decl.h"
19 #include "clang/AST/Type.h"
20 #include "clang/Basic/AttrKinds.h"
21 #include "clang/Basic/LLVM.h"
22 #include "clang/Basic/SourceLocation.h"
23 #include "clang/Basic/VersionTuple.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/ADT/StringSwitch.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/raw_ostream.h"
35 class ObjCInterfaceDecl;
41 /// Attr - This represents one attribute.
45 unsigned AttrKind : 16;
48 /// An index into the spelling list of an
49 /// attribute defined in Attr.td file.
50 unsigned SpellingListIndex : 4;
54 bool IsPackExpansion : 1;
58 void* operator new(size_t bytes) throw() {
59 llvm_unreachable("Attrs cannot be allocated with regular 'new'.");
61 void operator delete(void* data) throw() {
62 llvm_unreachable("Attrs cannot be released with regular 'delete'.");
66 // Forward so that the regular new and delete do not hide global ones.
67 void* operator new(size_t Bytes, ASTContext &C,
68 size_t Alignment = 16) throw() {
69 return ::operator new(Bytes, C, Alignment);
71 void operator delete(void *Ptr, ASTContext &C,
72 size_t Alignment) throw() {
73 return ::operator delete(Ptr, C, Alignment);
77 Attr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
78 : Range(R), AttrKind(AK), SpellingListIndex(SpellingListIndex),
79 Inherited(false), IsPackExpansion(false) {}
83 attr::Kind getKind() const {
84 return static_cast<attr::Kind>(AttrKind);
87 unsigned getSpellingListIndex() const { return SpellingListIndex; }
89 SourceLocation getLocation() const { return Range.getBegin(); }
90 SourceRange getRange() const { return Range; }
91 void setRange(SourceRange R) { Range = R; }
93 bool isInherited() const { return Inherited; }
95 void setPackExpansion(bool PE) { IsPackExpansion = PE; }
96 bool isPackExpansion() const { return IsPackExpansion; }
98 // Clone this attribute.
99 virtual Attr *clone(ASTContext &C) const = 0;
101 virtual bool isLateParsed() const { return false; }
103 // Pretty print this attribute.
104 virtual void printPretty(raw_ostream &OS,
105 const PrintingPolicy &Policy) const = 0;
108 class InheritableAttr : public Attr {
109 virtual void anchor();
111 InheritableAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
112 : Attr(AK, R, SpellingListIndex) {}
115 void setInherited(bool I) { Inherited = I; }
117 // Implement isa/cast/dyncast/etc.
118 static bool classof(const Attr *A) {
119 return A->getKind() <= attr::LAST_INHERITABLE;
123 class InheritableParamAttr : public InheritableAttr {
124 virtual void anchor();
126 InheritableParamAttr(attr::Kind AK, SourceRange R,
127 unsigned SpellingListIndex = 0)
128 : InheritableAttr(AK, R, SpellingListIndex) {}
131 // Implement isa/cast/dyncast/etc.
132 static bool classof(const Attr *A) {
133 // Relies on relative order of enum emission with respect to MS inheritance
135 return A->getKind() <= attr::LAST_INHERITABLE_PARAM;
139 class MSInheritanceAttr : public InheritableAttr {
140 virtual void anchor();
142 MSInheritanceAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
143 : InheritableAttr(AK, R, SpellingListIndex) {}
146 // Implement isa/cast/dyncast/etc.
147 static bool classof(const Attr *A) {
148 // Relies on relative order of enum emission with respect to param attrs.
149 return (A->getKind() <= attr::LAST_MS_INHERITANCE &&
150 A->getKind() > attr::LAST_INHERITABLE_PARAM);
154 #include "clang/AST/Attrs.inc"
156 } // end namespace clang