Attr.h revision 7e669b25144c7cfae0e51d4098016d6982504dbd
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
20namespace clang {
21
22/// Attr - This represents one attribute.
23class Attr {
24public:
25  enum Kind {
26    Aligned,
27    Packed,
28    Annotate,
29    NoReturn,
30    Deprecated
31  };
32
33private:
34  Attr *Next;
35  Kind AttrKind;
36
37protected:
38  Attr(Kind AK) : Next(0), AttrKind(AK) {}
39public:
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
62class PackedAttr : public Attr {
63public:
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
73class AlignedAttr : public Attr {
74  unsigned Alignment;
75public:
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
87class AnnotateAttr : public Attr {
88  std::string Annotation;
89public:
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
101class NoReturnAttr : public Attr {
102public:
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
111class DeprecatedAttr : public Attr {
112public:
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
124