blob: 8992e4823d524dac39431204abc79be462c452ff [file] [log] [blame]
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +00001//===--- 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 Korobeynikovfc5d5132010-01-10 14:38:13 +000014#include "clang/AST/Attr.h"
15#include "clang/AST/ASTContext.h"
16using namespace clang;
17
Douglas Gregor1de22a22010-07-25 18:32:30 +000018Attr::~Attr() { }
Ted Kremenek3d2c43e2010-02-11 05:28:37 +000019
Sean Hunt387475d2010-06-16 23:43:53 +000020AttrWithString::AttrWithString(attr::Kind AK, ASTContext &C, llvm::StringRef s)
Ted Kremenek3d2c43e2010-02-11 05:28:37 +000021 : 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 Kremenek3d2c43e2010-02-11 05:28:37 +000028void AttrWithString::ReplaceString(ASTContext &C, llvm::StringRef newS) {
29 if (newS.size() > StrLen) {
30 C.Deallocate(const_cast<char*>(Str));
Ted Kremeneke2f769b2010-02-11 22:44:22 +000031 Str = new (C) char[newS.size()];
Ted Kremenek3d2c43e2010-02-11 05:28:37 +000032 }
33 StrLen = newS.size();
34 memcpy(const_cast<char*>(Str), newS.data(), StrLen);
35}
36
37void FormatAttr::setType(ASTContext &C, llvm::StringRef type) {
38 ReplaceString(C, type);
39}
40
Ted Kremenek59616112010-02-11 07:31:47 +000041NonNullAttr::NonNullAttr(ASTContext &C, unsigned* arg_nums, unsigned size)
Sean Hunt387475d2010-06-16 23:43:53 +000042 : Attr(attr::NonNull), ArgNums(0), Size(0) {
Ted Kremenek59616112010-02-11 07:31:47 +000043 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 Kremenekdd0e4902010-07-31 01:52:11 +000051OwnershipAttr::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
67void OwnershipAttr::Destroy(ASTContext &C) {
68 if (ArgNums)
69 C.Deallocate(ArgNums);
70}
71
72OwnershipTakesAttr::OwnershipTakesAttr(ASTContext &C, unsigned* arg_nums,
73 unsigned size, llvm::StringRef module) :
74 OwnershipAttr(attr::OwnershipTakes, C, arg_nums, size, module, Takes) {
75}
76
77OwnershipHoldsAttr::OwnershipHoldsAttr(ASTContext &C, unsigned* arg_nums,
78 unsigned size, llvm::StringRef module) :
79 OwnershipAttr(attr::OwnershipHolds, C, arg_nums, size, module, Holds) {
80}
81
82OwnershipReturnsAttr::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 Korobeynikovfc5d5132010-01-10 14:38:13 +000088#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 Dunbar4e9255f2010-05-27 02:25:39 +000096DEF_SIMPLE_ATTR_CLONE(AlignMac68k)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000097DEF_SIMPLE_ATTR_CLONE(AlwaysInline)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000098DEF_SIMPLE_ATTR_CLONE(AnalyzerNoReturn)
Ted Kremenek31c780d2010-02-18 00:05:45 +000099DEF_SIMPLE_ATTR_CLONE(BaseCheck)
100DEF_SIMPLE_ATTR_CLONE(CDecl)
101DEF_SIMPLE_ATTR_CLONE(CFReturnsNotRetained)
102DEF_SIMPLE_ATTR_CLONE(CFReturnsRetained)
103DEF_SIMPLE_ATTR_CLONE(Const)
104DEF_SIMPLE_ATTR_CLONE(DLLExport)
105DEF_SIMPLE_ATTR_CLONE(DLLImport)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000106DEF_SIMPLE_ATTR_CLONE(Deprecated)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000107DEF_SIMPLE_ATTR_CLONE(FastCall)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000108DEF_SIMPLE_ATTR_CLONE(Final)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000109DEF_SIMPLE_ATTR_CLONE(Hiding)
110DEF_SIMPLE_ATTR_CLONE(Malloc)
111DEF_SIMPLE_ATTR_CLONE(NSReturnsNotRetained)
112DEF_SIMPLE_ATTR_CLONE(NSReturnsRetained)
113DEF_SIMPLE_ATTR_CLONE(NoDebug)
114DEF_SIMPLE_ATTR_CLONE(NoInline)
Chris Lattner7255a2d2010-06-22 00:03:40 +0000115DEF_SIMPLE_ATTR_CLONE(NoInstrumentFunction)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000116DEF_SIMPLE_ATTR_CLONE(NoReturn)
117DEF_SIMPLE_ATTR_CLONE(NoThrow)
118DEF_SIMPLE_ATTR_CLONE(ObjCException)
119DEF_SIMPLE_ATTR_CLONE(ObjCNSObject)
120DEF_SIMPLE_ATTR_CLONE(Override)
121DEF_SIMPLE_ATTR_CLONE(Packed)
122DEF_SIMPLE_ATTR_CLONE(Pure)
123DEF_SIMPLE_ATTR_CLONE(StdCall)
Douglas Gregorf813a2c2010-05-18 16:57:00 +0000124DEF_SIMPLE_ATTR_CLONE(ThisCall)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000125DEF_SIMPLE_ATTR_CLONE(TransparentUnion)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000126DEF_SIMPLE_ATTR_CLONE(Unavailable)
127DEF_SIMPLE_ATTR_CLONE(Unused)
128DEF_SIMPLE_ATTR_CLONE(Used)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000129DEF_SIMPLE_ATTR_CLONE(WarnUnusedResult)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000130DEF_SIMPLE_ATTR_CLONE(Weak)
131DEF_SIMPLE_ATTR_CLONE(WeakImport)
Rafael Espindola11e8ce72010-02-23 22:00:30 +0000132DEF_SIMPLE_ATTR_CLONE(WeakRef)
Charles Davis5a0164d2010-02-10 23:06:52 +0000133DEF_SIMPLE_ATTR_CLONE(X86ForceAlignArgPointer)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000134
Daniel Dunbar8a2c92c2010-05-27 01:12:46 +0000135Attr* MaxFieldAlignmentAttr::clone(ASTContext &C) const {
136 return ::new (C) MaxFieldAlignmentAttr(Alignment);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000137}
138
139Attr* AlignedAttr::clone(ASTContext &C) const {
140 return ::new (C) AlignedAttr(Alignment);
141}
142
143Attr* AnnotateAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000144 return ::new (C) AnnotateAttr(C, getAnnotation());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000145}
146
147Attr *AsmLabelAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000148 return ::new (C) AsmLabelAttr(C, getLabel());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000149}
150
151Attr *AliasAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000152 return ::new (C) AliasAttr(C, getAliasee());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000153}
154
155Attr *ConstructorAttr::clone(ASTContext &C) const {
156 return ::new (C) ConstructorAttr(priority);
157}
158
159Attr *DestructorAttr::clone(ASTContext &C) const {
160 return ::new (C) DestructorAttr(priority);
161}
162
163Attr *IBOutletAttr::clone(ASTContext &C) const {
164 return ::new (C) IBOutletAttr;
165}
166
Ted Kremenek857e9182010-05-19 17:38:06 +0000167Attr *IBOutletCollectionAttr::clone(ASTContext &C) const {
168 return ::new (C) IBOutletCollectionAttr(D);
169}
170
Ted Kremenekefbddd22010-02-17 02:37:45 +0000171Attr *IBActionAttr::clone(ASTContext &C) const {
172 return ::new (C) IBActionAttr;
173}
174
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000175Attr *GNUInlineAttr::clone(ASTContext &C) const {
176 return ::new (C) GNUInlineAttr;
177}
178
179Attr *SectionAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000180 return ::new (C) SectionAttr(C, getName());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000181}
182
183Attr *NonNullAttr::clone(ASTContext &C) const {
Ted Kremenek59616112010-02-11 07:31:47 +0000184 return ::new (C) NonNullAttr(C, ArgNums, Size);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000185}
186
Ted Kremenekdd0e4902010-07-31 01:52:11 +0000187Attr *OwnershipAttr::clone(ASTContext &C) const {
188 return ::new (C) OwnershipAttr(AKind, C, ArgNums, Size, getModule(), OKind);
189}
190
191Attr *OwnershipReturnsAttr::clone(ASTContext &C) const {
192 return ::new (C) OwnershipReturnsAttr(C, ArgNums, Size, getModule());
193}
194
195Attr *OwnershipTakesAttr::clone(ASTContext &C) const {
196 return ::new (C) OwnershipTakesAttr(C, ArgNums, Size, getModule());
197}
198
199Attr *OwnershipHoldsAttr::clone(ASTContext &C) const {
200 return ::new (C) OwnershipHoldsAttr(C, ArgNums, Size, getModule());
201}
202
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000203Attr *FormatAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000204 return ::new (C) FormatAttr(C, getType(), formatIdx, firstArg);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000205}
206
207Attr *FormatArgAttr::clone(ASTContext &C) const {
208 return ::new (C) FormatArgAttr(formatIdx);
209}
210
211Attr *SentinelAttr::clone(ASTContext &C) const {
212 return ::new (C) SentinelAttr(sentinel, NullPos);
213}
214
215Attr *VisibilityAttr::clone(ASTContext &C) const {
Eli Friedmanaa8b0d12010-08-05 06:57:20 +0000216 return ::new (C) VisibilityAttr(VisibilityType, FromPragma);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000217}
218
219Attr *OverloadableAttr::clone(ASTContext &C) const {
220 return ::new (C) OverloadableAttr;
221}
222
223Attr *BlocksAttr::clone(ASTContext &C) const {
224 return ::new (C) BlocksAttr(BlocksAttrType);
225}
226
227Attr *CleanupAttr::clone(ASTContext &C) const {
228 return ::new (C) CleanupAttr(FD);
229}
230
231Attr *RegparmAttr::clone(ASTContext &C) const {
232 return ::new (C) RegparmAttr(NumParams);
233}
234
235Attr *ReqdWorkGroupSizeAttr::clone(ASTContext &C) const {
236 return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z);
237}
238
Fariborz Jahanian521f12d2010-06-18 21:44:06 +0000239Attr *InitPriorityAttr::clone(ASTContext &C) const {
240 return ::new (C) InitPriorityAttr(Priority);
241}
242
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000243Attr *MSP430InterruptAttr::clone(ASTContext &C) const {
244 return ::new (C) MSP430InterruptAttr(Number);
245}