Attr.h revision c398f0b5efb2f8ba39cd5b0170cf697f714afbcb
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 }; 30 31private: 32 Attr *Next; 33 Kind AttrKind; 34 35protected: 36 Attr(Kind AK) : Next(0), AttrKind(AK) {} 37public: 38 virtual ~Attr() { 39 delete Next; 40 } 41 42 Kind getKind() const { return AttrKind; } 43 44 Attr *getNext() { return Next; } 45 const Attr *getNext() const { return Next; } 46 void setNext(Attr *next) { Next = next; } 47 48 void addAttr(Attr *attr) { 49 assert((attr != 0) && "addAttr(): attr is null"); 50 51 // FIXME: This doesn't preserve the order in any way. 52 attr->Next = Next; 53 Next = attr; 54 } 55 56 // Implement isa/cast/dyncast/etc. 57 static bool classof(const Attr *) { return true; } 58}; 59 60class PackedAttr : public Attr { 61public: 62 PackedAttr() : Attr(Packed) {} 63 64 // Implement isa/cast/dyncast/etc. 65 static bool classof(const Attr *A) { 66 return A->getKind() == Packed; 67 } 68 static bool classof(const PackedAttr *A) { return true; } 69}; 70 71class AlignedAttr : public Attr { 72 unsigned Alignment; 73public: 74 AlignedAttr(unsigned alignment) : Attr(Aligned), Alignment(alignment) {} 75 76 unsigned getAlignment() const { return Alignment; } 77 78 // Implement isa/cast/dyncast/etc. 79 static bool classof(const Attr *A) { 80 return A->getKind() == Aligned; 81 } 82 static bool classof(const AlignedAttr *A) { return true; } 83}; 84 85class AnnotateAttr : public Attr { 86 std::string Annotation; 87public: 88 AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {} 89 90 const std::string& getAnnotation() const { return Annotation; } 91 92 // Implement isa/cast/dyncast/etc. 93 static bool classof(const Attr *A) { 94 return A->getKind() == Annotate; 95 } 96 static bool classof(const AnnotateAttr *A) { return true; } 97}; 98 99} // end namespace clang 100 101#endif 102