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