| 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 | |
| Douglas Gregor | 1de22a2 | 2010-07-25 18:32:30 +0000 | [diff] [blame] | 18 | Attr::~Attr() { } |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 19 | |
| Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 20 | AttrWithString::AttrWithString(attr::Kind AK, ASTContext &C, llvm::StringRef s) |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 21 | : Attr(AK) { |
| 22 | assert(!s.empty()); |
| 23 | StrLen = s.size(); |
| 24 | Str = new (C) char[StrLen]; |
| 25 | memcpy(const_cast<char*>(Str), s.data(), StrLen); |
| 26 | } |
| 27 | |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 28 | void AttrWithString::ReplaceString(ASTContext &C, llvm::StringRef newS) { |
| 29 | if (newS.size() > StrLen) { |
| 30 | C.Deallocate(const_cast<char*>(Str)); |
| Ted Kremenek | e2f769b | 2010-02-11 22:44:22 +0000 | [diff] [blame] | 31 | Str = new (C) char[newS.size()]; |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 32 | } |
| 33 | StrLen = newS.size(); |
| 34 | memcpy(const_cast<char*>(Str), newS.data(), StrLen); |
| 35 | } |
| 36 | |
| 37 | void FormatAttr::setType(ASTContext &C, llvm::StringRef type) { |
| 38 | ReplaceString(C, type); |
| 39 | } |
| 40 | |
| Ted Kremenek | 5961611 | 2010-02-11 07:31:47 +0000 | [diff] [blame] | 41 | NonNullAttr::NonNullAttr(ASTContext &C, unsigned* arg_nums, unsigned size) |
| Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 42 | : Attr(attr::NonNull), ArgNums(0), Size(0) { |
| Ted Kremenek | 5961611 | 2010-02-11 07:31:47 +0000 | [diff] [blame] | 43 | if (size == 0) |
| 44 | return; |
| 45 | assert(arg_nums); |
| 46 | ArgNums = new (C) unsigned[size]; |
| 47 | Size = size; |
| 48 | memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size); |
| 49 | } |
| 50 | |
| Ted Kremenek | dd0e490 | 2010-07-31 01:52:11 +0000 | [diff] [blame] | 51 | OwnershipAttr::OwnershipAttr(attr::Kind AK, ASTContext &C, unsigned* arg_nums, |
| 52 | unsigned size, |
| 53 | llvm::StringRef module, |
| 54 | OwnershipKind kind) : |
| 55 | AttrWithString(AK, C, module), ArgNums(0), Size(0), OKind(kind) { |
| 56 | if (size == 0) |
| 57 | return; |
| 58 | assert(arg_nums); |
| 59 | ArgNums = new (C) unsigned[size]; |
| 60 | Size = size; |
| 61 | AKind = AK; |
| 62 | OKind = kind; |
| 63 | memcpy(ArgNums, arg_nums, sizeof(*ArgNums) * size); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | void OwnershipAttr::Destroy(ASTContext &C) { |
| 68 | if (ArgNums) |
| 69 | C.Deallocate(ArgNums); |
| 70 | } |
| 71 | |
| 72 | OwnershipTakesAttr::OwnershipTakesAttr(ASTContext &C, unsigned* arg_nums, |
| 73 | unsigned size, llvm::StringRef module) : |
| 74 | OwnershipAttr(attr::OwnershipTakes, C, arg_nums, size, module, Takes) { |
| 75 | } |
| 76 | |
| 77 | OwnershipHoldsAttr::OwnershipHoldsAttr(ASTContext &C, unsigned* arg_nums, |
| 78 | unsigned size, llvm::StringRef module) : |
| 79 | OwnershipAttr(attr::OwnershipHolds, C, arg_nums, size, module, Holds) { |
| 80 | } |
| 81 | |
| 82 | OwnershipReturnsAttr::OwnershipReturnsAttr(ASTContext &C, unsigned* arg_nums, |
| 83 | unsigned size, |
| 84 | llvm::StringRef module) : |
| 85 | OwnershipAttr(attr::OwnershipReturns, C, arg_nums, size, module, Returns) { |
| 86 | } |
| 87 | |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 88 | #define DEF_SIMPLE_ATTR_CLONE(ATTR) \ |
| 89 | Attr *ATTR##Attr::clone(ASTContext &C) const { \ |
| 90 | return ::new (C) ATTR##Attr; \ |
| 91 | } |
| 92 | |
| 93 | // FIXME: Can we use variadic macro to define DEF_SIMPLE_ATTR_CLONE for |
| 94 | // "non-simple" classes? |
| 95 | |
| Daniel Dunbar | 4e9255f | 2010-05-27 02:25:39 +0000 | [diff] [blame] | 96 | DEF_SIMPLE_ATTR_CLONE(AlignMac68k) |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 97 | DEF_SIMPLE_ATTR_CLONE(AlwaysInline) |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 98 | DEF_SIMPLE_ATTR_CLONE(AnalyzerNoReturn) |
| Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 99 | DEF_SIMPLE_ATTR_CLONE(BaseCheck) |
| 100 | DEF_SIMPLE_ATTR_CLONE(CDecl) |
| 101 | DEF_SIMPLE_ATTR_CLONE(CFReturnsNotRetained) |
| 102 | DEF_SIMPLE_ATTR_CLONE(CFReturnsRetained) |
| 103 | DEF_SIMPLE_ATTR_CLONE(Const) |
| 104 | DEF_SIMPLE_ATTR_CLONE(DLLExport) |
| 105 | DEF_SIMPLE_ATTR_CLONE(DLLImport) |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 106 | DEF_SIMPLE_ATTR_CLONE(Deprecated) |
| Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 107 | DEF_SIMPLE_ATTR_CLONE(FastCall) |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 108 | DEF_SIMPLE_ATTR_CLONE(Final) |
| Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 109 | DEF_SIMPLE_ATTR_CLONE(Hiding) |
| 110 | DEF_SIMPLE_ATTR_CLONE(Malloc) |
| 111 | DEF_SIMPLE_ATTR_CLONE(NSReturnsNotRetained) |
| 112 | DEF_SIMPLE_ATTR_CLONE(NSReturnsRetained) |
| 113 | DEF_SIMPLE_ATTR_CLONE(NoDebug) |
| 114 | DEF_SIMPLE_ATTR_CLONE(NoInline) |
| Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 115 | DEF_SIMPLE_ATTR_CLONE(NoInstrumentFunction) |
| Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 116 | DEF_SIMPLE_ATTR_CLONE(NoReturn) |
| 117 | DEF_SIMPLE_ATTR_CLONE(NoThrow) |
| 118 | DEF_SIMPLE_ATTR_CLONE(ObjCException) |
| 119 | DEF_SIMPLE_ATTR_CLONE(ObjCNSObject) |
| 120 | DEF_SIMPLE_ATTR_CLONE(Override) |
| 121 | DEF_SIMPLE_ATTR_CLONE(Packed) |
| 122 | DEF_SIMPLE_ATTR_CLONE(Pure) |
| 123 | DEF_SIMPLE_ATTR_CLONE(StdCall) |
| Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 124 | DEF_SIMPLE_ATTR_CLONE(ThisCall) |
| Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 125 | DEF_SIMPLE_ATTR_CLONE(TransparentUnion) |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 126 | DEF_SIMPLE_ATTR_CLONE(Unavailable) |
| 127 | DEF_SIMPLE_ATTR_CLONE(Unused) |
| 128 | DEF_SIMPLE_ATTR_CLONE(Used) |
| Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 129 | DEF_SIMPLE_ATTR_CLONE(WarnUnusedResult) |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 130 | DEF_SIMPLE_ATTR_CLONE(Weak) |
| 131 | DEF_SIMPLE_ATTR_CLONE(WeakImport) |
| Rafael Espindola | 11e8ce7 | 2010-02-23 22:00:30 +0000 | [diff] [blame] | 132 | DEF_SIMPLE_ATTR_CLONE(WeakRef) |
| Charles Davis | 5a0164d | 2010-02-10 23:06:52 +0000 | [diff] [blame] | 133 | DEF_SIMPLE_ATTR_CLONE(X86ForceAlignArgPointer) |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 134 | |
| Daniel Dunbar | 8a2c92c | 2010-05-27 01:12:46 +0000 | [diff] [blame] | 135 | Attr* MaxFieldAlignmentAttr::clone(ASTContext &C) const { |
| 136 | return ::new (C) MaxFieldAlignmentAttr(Alignment); |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | Attr* AlignedAttr::clone(ASTContext &C) const { |
| 140 | return ::new (C) AlignedAttr(Alignment); |
| 141 | } |
| 142 | |
| 143 | Attr* AnnotateAttr::clone(ASTContext &C) const { |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 144 | return ::new (C) AnnotateAttr(C, getAnnotation()); |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | Attr *AsmLabelAttr::clone(ASTContext &C) const { |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 148 | return ::new (C) AsmLabelAttr(C, getLabel()); |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | Attr *AliasAttr::clone(ASTContext &C) const { |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 152 | return ::new (C) AliasAttr(C, getAliasee()); |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | Attr *ConstructorAttr::clone(ASTContext &C) const { |
| 156 | return ::new (C) ConstructorAttr(priority); |
| 157 | } |
| 158 | |
| 159 | Attr *DestructorAttr::clone(ASTContext &C) const { |
| 160 | return ::new (C) DestructorAttr(priority); |
| 161 | } |
| 162 | |
| 163 | Attr *IBOutletAttr::clone(ASTContext &C) const { |
| 164 | return ::new (C) IBOutletAttr; |
| 165 | } |
| 166 | |
| Ted Kremenek | 857e918 | 2010-05-19 17:38:06 +0000 | [diff] [blame] | 167 | Attr *IBOutletCollectionAttr::clone(ASTContext &C) const { |
| 168 | return ::new (C) IBOutletCollectionAttr(D); |
| 169 | } |
| 170 | |
| Ted Kremenek | efbddd2 | 2010-02-17 02:37:45 +0000 | [diff] [blame] | 171 | Attr *IBActionAttr::clone(ASTContext &C) const { |
| 172 | return ::new (C) IBActionAttr; |
| 173 | } |
| 174 | |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 175 | Attr *GNUInlineAttr::clone(ASTContext &C) const { |
| 176 | return ::new (C) GNUInlineAttr; |
| 177 | } |
| 178 | |
| 179 | Attr *SectionAttr::clone(ASTContext &C) const { |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 180 | return ::new (C) SectionAttr(C, getName()); |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | Attr *NonNullAttr::clone(ASTContext &C) const { |
| Ted Kremenek | 5961611 | 2010-02-11 07:31:47 +0000 | [diff] [blame] | 184 | return ::new (C) NonNullAttr(C, ArgNums, Size); |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| Ted Kremenek | dd0e490 | 2010-07-31 01:52:11 +0000 | [diff] [blame] | 187 | Attr *OwnershipAttr::clone(ASTContext &C) const { |
| 188 | return ::new (C) OwnershipAttr(AKind, C, ArgNums, Size, getModule(), OKind); |
| 189 | } |
| 190 | |
| 191 | Attr *OwnershipReturnsAttr::clone(ASTContext &C) const { |
| 192 | return ::new (C) OwnershipReturnsAttr(C, ArgNums, Size, getModule()); |
| 193 | } |
| 194 | |
| 195 | Attr *OwnershipTakesAttr::clone(ASTContext &C) const { |
| 196 | return ::new (C) OwnershipTakesAttr(C, ArgNums, Size, getModule()); |
| 197 | } |
| 198 | |
| 199 | Attr *OwnershipHoldsAttr::clone(ASTContext &C) const { |
| 200 | return ::new (C) OwnershipHoldsAttr(C, ArgNums, Size, getModule()); |
| 201 | } |
| 202 | |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 203 | Attr *FormatAttr::clone(ASTContext &C) const { |
| Ted Kremenek | 3d2c43e | 2010-02-11 05:28:37 +0000 | [diff] [blame] | 204 | return ::new (C) FormatAttr(C, getType(), formatIdx, firstArg); |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | Attr *FormatArgAttr::clone(ASTContext &C) const { |
| 208 | return ::new (C) FormatArgAttr(formatIdx); |
| 209 | } |
| 210 | |
| 211 | Attr *SentinelAttr::clone(ASTContext &C) const { |
| 212 | return ::new (C) SentinelAttr(sentinel, NullPos); |
| 213 | } |
| 214 | |
| 215 | Attr *VisibilityAttr::clone(ASTContext &C) const { |
| Eli Friedman | aa8b0d1 | 2010-08-05 06:57:20 +0000 | [diff] [blame^] | 216 | return ::new (C) VisibilityAttr(VisibilityType, FromPragma); |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | Attr *OverloadableAttr::clone(ASTContext &C) const { |
| 220 | return ::new (C) OverloadableAttr; |
| 221 | } |
| 222 | |
| 223 | Attr *BlocksAttr::clone(ASTContext &C) const { |
| 224 | return ::new (C) BlocksAttr(BlocksAttrType); |
| 225 | } |
| 226 | |
| 227 | Attr *CleanupAttr::clone(ASTContext &C) const { |
| 228 | return ::new (C) CleanupAttr(FD); |
| 229 | } |
| 230 | |
| 231 | Attr *RegparmAttr::clone(ASTContext &C) const { |
| 232 | return ::new (C) RegparmAttr(NumParams); |
| 233 | } |
| 234 | |
| 235 | Attr *ReqdWorkGroupSizeAttr::clone(ASTContext &C) const { |
| 236 | return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z); |
| 237 | } |
| 238 | |
| Fariborz Jahanian | 521f12d | 2010-06-18 21:44:06 +0000 | [diff] [blame] | 239 | Attr *InitPriorityAttr::clone(ASTContext &C) const { |
| 240 | return ::new (C) InitPriorityAttr(Priority); |
| 241 | } |
| 242 | |
| Anton Korobeynikov | fc5d513 | 2010-01-10 14:38:13 +0000 | [diff] [blame] | 243 | Attr *MSP430InterruptAttr::clone(ASTContext &C) const { |
| 244 | return ::new (C) MSP430InterruptAttr(Number); |
| 245 | } |