Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 1 | //===--- AttrImpl.cpp - 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 contains out-of-line virtual methods for Attr classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 14 | #include "clang/AST/Attr.h" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | using namespace clang; |
| 17 | |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame^] | 18 | void Attr::Destroy(ASTContext &C) { |
| 19 | if (Next) { |
| 20 | Next->Destroy(C); |
| 21 | Next = 0; |
| 22 | } |
| 23 | this->~Attr(); |
| 24 | C.Deallocate((void*)this); |
| 25 | } |
| 26 | |
| 27 | AttrWithString::AttrWithString(Attr::Kind AK, ASTContext &C, llvm::StringRef s) |
| 28 | : Attr(AK) { |
| 29 | assert(!s.empty()); |
| 30 | StrLen = s.size(); |
| 31 | Str = new (C) char[StrLen]; |
| 32 | memcpy(const_cast<char*>(Str), s.data(), StrLen); |
| 33 | } |
| 34 | |
| 35 | void AttrWithString::Destroy(ASTContext &C) { |
| 36 | C.Deallocate(const_cast<char*>(Str)); |
| 37 | Attr::Destroy(C); |
| 38 | } |
| 39 | |
| 40 | void AttrWithString::ReplaceString(ASTContext &C, llvm::StringRef newS) { |
| 41 | if (newS.size() > StrLen) { |
| 42 | C.Deallocate(const_cast<char*>(Str)); |
| 43 | Str = new char[newS.size()]; |
| 44 | } |
| 45 | StrLen = newS.size(); |
| 46 | memcpy(const_cast<char*>(Str), newS.data(), StrLen); |
| 47 | } |
| 48 | |
| 49 | void FormatAttr::setType(ASTContext &C, llvm::StringRef type) { |
| 50 | ReplaceString(C, type); |
| 51 | } |
| 52 | |
Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 53 | #define DEF_SIMPLE_ATTR_CLONE(ATTR) \ |
| 54 | Attr *ATTR##Attr::clone(ASTContext &C) const { \ |
| 55 | return ::new (C) ATTR##Attr; \ |
| 56 | } |
| 57 | |
| 58 | // FIXME: Can we use variadic macro to define DEF_SIMPLE_ATTR_CLONE for |
| 59 | // "non-simple" classes? |
| 60 | |
| 61 | DEF_SIMPLE_ATTR_CLONE(Packed) |
| 62 | DEF_SIMPLE_ATTR_CLONE(AlwaysInline) |
| 63 | DEF_SIMPLE_ATTR_CLONE(Malloc) |
| 64 | DEF_SIMPLE_ATTR_CLONE(NoReturn) |
| 65 | DEF_SIMPLE_ATTR_CLONE(AnalyzerNoReturn) |
| 66 | DEF_SIMPLE_ATTR_CLONE(Deprecated) |
| 67 | DEF_SIMPLE_ATTR_CLONE(Final) |
| 68 | DEF_SIMPLE_ATTR_CLONE(Unavailable) |
| 69 | DEF_SIMPLE_ATTR_CLONE(Unused) |
| 70 | DEF_SIMPLE_ATTR_CLONE(Used) |
| 71 | DEF_SIMPLE_ATTR_CLONE(Weak) |
| 72 | DEF_SIMPLE_ATTR_CLONE(WeakImport) |
| 73 | DEF_SIMPLE_ATTR_CLONE(NoThrow) |
| 74 | DEF_SIMPLE_ATTR_CLONE(Const) |
| 75 | DEF_SIMPLE_ATTR_CLONE(Pure) |
| 76 | DEF_SIMPLE_ATTR_CLONE(FastCall) |
| 77 | DEF_SIMPLE_ATTR_CLONE(StdCall) |
| 78 | DEF_SIMPLE_ATTR_CLONE(CDecl) |
| 79 | DEF_SIMPLE_ATTR_CLONE(TransparentUnion) |
| 80 | DEF_SIMPLE_ATTR_CLONE(ObjCNSObject) |
| 81 | DEF_SIMPLE_ATTR_CLONE(ObjCException) |
| 82 | DEF_SIMPLE_ATTR_CLONE(NoDebug) |
| 83 | DEF_SIMPLE_ATTR_CLONE(WarnUnusedResult) |
| 84 | DEF_SIMPLE_ATTR_CLONE(NoInline) |
| 85 | DEF_SIMPLE_ATTR_CLONE(CFReturnsRetained) |
| 86 | DEF_SIMPLE_ATTR_CLONE(NSReturnsRetained) |
| 87 | DEF_SIMPLE_ATTR_CLONE(BaseCheck) |
| 88 | DEF_SIMPLE_ATTR_CLONE(Hiding) |
| 89 | DEF_SIMPLE_ATTR_CLONE(Override) |
| 90 | DEF_SIMPLE_ATTR_CLONE(DLLImport) |
| 91 | DEF_SIMPLE_ATTR_CLONE(DLLExport) |
Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 92 | DEF_SIMPLE_ATTR_CLONE(X86ForceAlignArgPointer) |
Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 93 | |
| 94 | Attr* PragmaPackAttr::clone(ASTContext &C) const { |
| 95 | return ::new (C) PragmaPackAttr(Alignment); |
| 96 | } |
| 97 | |
| 98 | Attr* AlignedAttr::clone(ASTContext &C) const { |
| 99 | return ::new (C) AlignedAttr(Alignment); |
| 100 | } |
| 101 | |
| 102 | Attr* AnnotateAttr::clone(ASTContext &C) const { |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame^] | 103 | return ::new (C) AnnotateAttr(C, getAnnotation()); |
Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | Attr *AsmLabelAttr::clone(ASTContext &C) const { |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame^] | 107 | return ::new (C) AsmLabelAttr(C, getLabel()); |
Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | Attr *AliasAttr::clone(ASTContext &C) const { |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame^] | 111 | return ::new (C) AliasAttr(C, getAliasee()); |
Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | Attr *ConstructorAttr::clone(ASTContext &C) const { |
| 115 | return ::new (C) ConstructorAttr(priority); |
| 116 | } |
| 117 | |
| 118 | Attr *DestructorAttr::clone(ASTContext &C) const { |
| 119 | return ::new (C) DestructorAttr(priority); |
| 120 | } |
| 121 | |
| 122 | Attr *IBOutletAttr::clone(ASTContext &C) const { |
| 123 | return ::new (C) IBOutletAttr; |
| 124 | } |
| 125 | |
| 126 | Attr *GNUInlineAttr::clone(ASTContext &C) const { |
| 127 | return ::new (C) GNUInlineAttr; |
| 128 | } |
| 129 | |
| 130 | Attr *SectionAttr::clone(ASTContext &C) const { |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame^] | 131 | return ::new (C) SectionAttr(C, getName()); |
Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | Attr *NonNullAttr::clone(ASTContext &C) const { |
| 135 | return ::new (C) NonNullAttr(ArgNums, Size); |
| 136 | } |
| 137 | |
| 138 | Attr *FormatAttr::clone(ASTContext &C) const { |
Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame^] | 139 | return ::new (C) FormatAttr(C, getType(), formatIdx, firstArg); |
Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | Attr *FormatArgAttr::clone(ASTContext &C) const { |
| 143 | return ::new (C) FormatArgAttr(formatIdx); |
| 144 | } |
| 145 | |
| 146 | Attr *SentinelAttr::clone(ASTContext &C) const { |
| 147 | return ::new (C) SentinelAttr(sentinel, NullPos); |
| 148 | } |
| 149 | |
| 150 | Attr *VisibilityAttr::clone(ASTContext &C) const { |
| 151 | return ::new (C) VisibilityAttr(VisibilityType); |
| 152 | } |
| 153 | |
| 154 | Attr *OverloadableAttr::clone(ASTContext &C) const { |
| 155 | return ::new (C) OverloadableAttr; |
| 156 | } |
| 157 | |
| 158 | Attr *BlocksAttr::clone(ASTContext &C) const { |
| 159 | return ::new (C) BlocksAttr(BlocksAttrType); |
| 160 | } |
| 161 | |
| 162 | Attr *CleanupAttr::clone(ASTContext &C) const { |
| 163 | return ::new (C) CleanupAttr(FD); |
| 164 | } |
| 165 | |
| 166 | Attr *RegparmAttr::clone(ASTContext &C) const { |
| 167 | return ::new (C) RegparmAttr(NumParams); |
| 168 | } |
| 169 | |
| 170 | Attr *ReqdWorkGroupSizeAttr::clone(ASTContext &C) const { |
| 171 | return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z); |
| 172 | } |
| 173 | |
| 174 | Attr *MSP430InterruptAttr::clone(ASTContext &C) const { |
| 175 | return ::new (C) MSP430InterruptAttr(Number); |
| 176 | } |
| 177 | |
| 178 | |