]> granicus.if.org Git - clang/blob - include/clang/AST/Attr.h
Add support for attribute(deprecated), patch by Nuno Lopes!
[clang] / include / clang / AST / Attr.h
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 <cassert>
18 #include <string>
19
20 namespace clang {
21
22 /// Attr - This represents one attribute.
23 class Attr {
24 public:
25   enum Kind {
26     Aligned,
27     Packed,
28     Annotate,
29     NoReturn,
30     Deprecated
31   };
32     
33 private:
34   Attr *Next;
35   Kind AttrKind;
36   
37 protected:
38   Attr(Kind AK) : Next(0), AttrKind(AK) {}
39 public:
40   virtual ~Attr() {
41     delete Next;
42   }
43
44   Kind getKind() const { return AttrKind; }
45
46   Attr *getNext() { return Next; }
47   const Attr *getNext() const { return Next; }
48   void setNext(Attr *next) { Next = next; }
49   
50   void addAttr(Attr *attr) {
51     assert((attr != 0) && "addAttr(): attr is null");
52     
53     // FIXME: This doesn't preserve the order in any way.
54     attr->Next = Next;
55     Next = attr;
56   }
57   
58   // Implement isa/cast/dyncast/etc.
59   static bool classof(const Attr *) { return true; }
60 };
61
62 class PackedAttr : public Attr {
63 public:
64   PackedAttr() : Attr(Packed) {}
65   
66   // Implement isa/cast/dyncast/etc.
67   static bool classof(const Attr *A) {
68     return A->getKind() == Packed;
69   }
70   static bool classof(const PackedAttr *A) { return true; }
71 };
72   
73 class AlignedAttr : public Attr {
74   unsigned Alignment;
75 public:
76   AlignedAttr(unsigned alignment) : Attr(Aligned), Alignment(alignment) {}
77   
78   unsigned getAlignment() const { return Alignment; }
79   
80   // Implement isa/cast/dyncast/etc.
81   static bool classof(const Attr *A) {
82     return A->getKind() == Aligned;
83   }
84   static bool classof(const AlignedAttr *A) { return true; }
85 };
86
87 class AnnotateAttr : public Attr {
88   std::string Annotation;
89 public:
90   AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {}
91   
92   const std::string& getAnnotation() const { return Annotation; }
93   
94   // Implement isa/cast/dyncast/etc.
95   static bool classof(const Attr *A) {
96     return A->getKind() == Annotate;
97   }
98   static bool classof(const AnnotateAttr *A) { return true; }
99 };
100   
101 class NoReturnAttr : public Attr {
102 public:
103   NoReturnAttr() : Attr(NoReturn) {}
104   
105   // Implement isa/cast/dyncast/etc.
106   
107   static bool classof(const Attr *A) { return A->getKind() == NoReturn; }  
108   static bool classof(const NoReturnAttr *A) { return true; }
109 };
110
111 class DeprecatedAttr : public Attr {
112 public:
113   DeprecatedAttr() : Attr(Deprecated) {}
114
115   // Implement isa/cast/dyncast/etc.
116
117   static bool classof(const Attr *A) { return A->getKind() == Deprecated; }
118   static bool classof(const DeprecatedAttr *A) { return true; }
119 };
120
121 }  // end namespace clang
122
123 #endif