Attr.h revision 440b456709526c4277e71d2e0ff49e5d88dc7b17
1//===--- Attr.h - Classes for representing expressions ----------*- 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 "llvm/GlobalValue.h"
18#include <cassert>
19#include <string>
20
21namespace clang {
22
23/// Attr - This represents one attribute.
24class Attr {
25public:
26  enum Kind {
27    Aligned,
28    Packed,
29    Annotate,
30    NoReturn,
31    Deprecated,
32    Weak,
33    DLLImport,
34    DLLExport,
35    NoThrow,
36    Format,
37    Visibility,
38    FastCall,
39    StdCall
40  };
41
42private:
43  Attr *Next;
44  Kind AttrKind;
45
46protected:
47  Attr(Kind AK) : Next(0), AttrKind(AK) {}
48public:
49  virtual ~Attr() {
50    delete Next;
51  }
52
53  Kind getKind() const { return AttrKind; }
54
55  Attr *getNext() { return Next; }
56  const Attr *getNext() const { return Next; }
57  void setNext(Attr *next) { Next = next; }
58
59  void addAttr(Attr *attr) {
60    assert((attr != 0) && "addAttr(): attr is null");
61
62    // FIXME: This doesn't preserve the order in any way.
63    attr->Next = Next;
64    Next = attr;
65  }
66
67  // Implement isa/cast/dyncast/etc.
68  static bool classof(const Attr *) { return true; }
69};
70
71class PackedAttr : public Attr {
72public:
73  PackedAttr() : Attr(Packed) {}
74
75  // Implement isa/cast/dyncast/etc.
76  static bool classof(const Attr *A) {
77    return A->getKind() == Packed;
78  }
79  static bool classof(const PackedAttr *A) { return true; }
80};
81
82class AlignedAttr : public Attr {
83  unsigned Alignment;
84public:
85  AlignedAttr(unsigned alignment) : Attr(Aligned), Alignment(alignment) {}
86
87  unsigned getAlignment() const { return Alignment; }
88
89  // Implement isa/cast/dyncast/etc.
90  static bool classof(const Attr *A) {
91    return A->getKind() == Aligned;
92  }
93  static bool classof(const AlignedAttr *A) { return true; }
94};
95
96class AnnotateAttr : public Attr {
97  std::string Annotation;
98public:
99  AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {}
100
101  const std::string& getAnnotation() const { return Annotation; }
102
103  // Implement isa/cast/dyncast/etc.
104  static bool classof(const Attr *A) {
105    return A->getKind() == Annotate;
106  }
107  static bool classof(const AnnotateAttr *A) { return true; }
108};
109
110class NoReturnAttr : public Attr {
111public:
112  NoReturnAttr() : Attr(NoReturn) {}
113
114  // Implement isa/cast/dyncast/etc.
115
116  static bool classof(const Attr *A) { return A->getKind() == NoReturn; }
117  static bool classof(const NoReturnAttr *A) { return true; }
118};
119
120class DeprecatedAttr : public Attr {
121public:
122  DeprecatedAttr() : Attr(Deprecated) {}
123
124  // Implement isa/cast/dyncast/etc.
125
126  static bool classof(const Attr *A) { return A->getKind() == Deprecated; }
127  static bool classof(const DeprecatedAttr *A) { return true; }
128};
129
130class WeakAttr : public Attr {
131public:
132  WeakAttr() : Attr(Weak) {}
133
134  // Implement isa/cast/dyncast/etc.
135
136  static bool classof(const Attr *A) { return A->getKind() == Weak; }
137  static bool classof(const WeakAttr *A) { return true; }
138};
139
140class NoThrowAttr : public Attr {
141public:
142  NoThrowAttr() : Attr(NoThrow) {}
143
144  // Implement isa/cast/dyncast/etc.
145
146  static bool classof(const Attr *A) { return A->getKind() == NoThrow; }
147  static bool classof(const NoThrowAttr *A) { return true; }
148};
149
150class FormatAttr : public Attr {
151  std::string Type;
152  int formatIdx, firstArg;
153public:
154  FormatAttr(const std::string &type, int idx, int first) : Attr(Format),
155             Type(type), formatIdx(idx), firstArg(first) {}
156
157  const std::string& getType() const { return Type; }
158  int getFormatIdx() const { return formatIdx; }
159  int getFirstArg() const { return firstArg; }
160
161  // Implement isa/cast/dyncast/etc.
162
163  static bool classof(const Attr *A) { return A->getKind() == Format; }
164  static bool classof(const FormatAttr *A) { return true; }
165};
166
167class VisibilityAttr : public Attr {
168  llvm::GlobalValue::VisibilityTypes VisibilityType;
169public:
170  VisibilityAttr(llvm::GlobalValue::VisibilityTypes v) : Attr(Visibility),
171                 VisibilityType(v) {}
172
173  llvm::GlobalValue::VisibilityTypes getVisibility() const { return VisibilityType; }
174
175  // Implement isa/cast/dyncast/etc.
176
177  static bool classof(const Attr *A) { return A->getKind() == Visibility; }
178  static bool classof(const VisibilityAttr *A) { return true; }
179};
180
181class DLLImportAttr : public Attr {
182public:
183  DLLImportAttr() : Attr(DLLImport) {}
184
185  // Implement isa/cast/dyncast/etc.
186
187  static bool classof(const Attr *A) { return A->getKind() == DLLImport; }
188  static bool classof(const DLLImportAttr *A) { return true; }
189};
190
191class DLLExportAttr : public Attr {
192public:
193  DLLExportAttr() : Attr(DLLExport) {}
194
195  // Implement isa/cast/dyncast/etc.
196
197  static bool classof(const Attr *A) { return A->getKind() == DLLExport; }
198  static bool classof(const DLLExportAttr *A) { return true; }
199};
200
201class FastCallAttr : public Attr {
202public:
203  FastCallAttr() : Attr(FastCall) {}
204
205  // Implement isa/cast/dyncast/etc.
206
207  static bool classof(const Attr *A) { return A->getKind() == FastCall; }
208  static bool classof(const FastCallAttr *A) { return true; }
209};
210
211class StdCallAttr : public Attr {
212public:
213  StdCallAttr() : Attr(StdCall) {}
214
215  // Implement isa/cast/dyncast/etc.
216
217  static bool classof(const Attr *A) { return A->getKind() == StdCall; }
218  static bool classof(const StdCallAttr *A) { return true; }
219};
220
221}  // end namespace clang
222
223#endif
224