]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/clang/include/clang/AST/Attr.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / clang / include / clang / AST / Attr.h
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/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"
29 #include <cassert>
30 #include <cstring>
31
32 namespace clang {
33   class ASTContext;
34   class IdentifierInfo;
35   class ObjCInterfaceDecl;
36   class Expr;
37   class QualType;
38   class FunctionDecl;
39   class TypeSourceInfo;
40
41 /// Attr - This represents one attribute.
42 class Attr {
43 private:
44   SourceRange Range;
45   unsigned AttrKind : 16;
46
47 protected:
48   /// An index into the spelling list of an
49   /// attribute defined in Attr.td file.
50   unsigned SpellingListIndex : 4;
51
52   bool Inherited : 1;
53
54   bool IsPackExpansion : 1;
55
56   virtual ~Attr();
57
58   void* operator new(size_t bytes) throw() {
59     llvm_unreachable("Attrs cannot be allocated with regular 'new'.");
60   }
61   void operator delete(void* data) throw() {
62     llvm_unreachable("Attrs cannot be released with regular 'delete'.");
63   }
64
65 public:
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);
70   }
71   void operator delete(void *Ptr, ASTContext &C,
72                        size_t Alignment) throw() {
73     return ::operator delete(Ptr, C, Alignment);
74   }
75
76 protected:
77   Attr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
78     : Range(R), AttrKind(AK), SpellingListIndex(SpellingListIndex),
79       Inherited(false), IsPackExpansion(false) {}
80
81 public:
82
83   attr::Kind getKind() const {
84     return static_cast<attr::Kind>(AttrKind);
85   }
86   
87   unsigned getSpellingListIndex() const { return SpellingListIndex; }
88
89   SourceLocation getLocation() const { return Range.getBegin(); }
90   SourceRange getRange() const { return Range; }
91   void setRange(SourceRange R) { Range = R; }
92
93   bool isInherited() const { return Inherited; }
94
95   void setPackExpansion(bool PE) { IsPackExpansion = PE; }
96   bool isPackExpansion() const { return IsPackExpansion; }
97
98   // Clone this attribute.
99   virtual Attr *clone(ASTContext &C) const = 0;
100
101   virtual bool isLateParsed() const { return false; }
102
103   // Pretty print this attribute.
104   virtual void printPretty(raw_ostream &OS,
105                            const PrintingPolicy &Policy) const = 0;
106 };
107
108 class InheritableAttr : public Attr {
109   virtual void anchor();
110 protected:
111   InheritableAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
112     : Attr(AK, R, SpellingListIndex) {}
113
114 public:
115   void setInherited(bool I) { Inherited = I; }
116
117   // Implement isa/cast/dyncast/etc.
118   static bool classof(const Attr *A) {
119     return A->getKind() <= attr::LAST_INHERITABLE;
120   }
121 };
122
123 class InheritableParamAttr : public InheritableAttr {
124   virtual void anchor();
125 protected:
126   InheritableParamAttr(attr::Kind AK, SourceRange R,
127                        unsigned SpellingListIndex = 0)
128     : InheritableAttr(AK, R, SpellingListIndex) {}
129
130 public:
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
134     // attrs.
135     return A->getKind() <= attr::LAST_INHERITABLE_PARAM;
136   }
137 };
138
139 class MSInheritanceAttr : public InheritableAttr {
140   virtual void anchor();
141 protected:
142   MSInheritanceAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex = 0)
143     : InheritableAttr(AK, R, SpellingListIndex) {}
144
145 public:
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);
151   }
152 };
153
154 #include "clang/AST/Attrs.inc"
155
156 }  // end namespace clang
157
158 #endif