blob: b09ba895c0195a766e88507978acff17c6f4bf3c [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
Ted Kremenek3d2c43e2010-02-11 05:28:37 +000018void 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
Sean Hunt387475d2010-06-16 23:43:53 +000027AttrWithString::AttrWithString(attr::Kind AK, ASTContext &C, llvm::StringRef s)
Ted Kremenek3d2c43e2010-02-11 05:28:37 +000028 : 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
35void AttrWithString::Destroy(ASTContext &C) {
36 C.Deallocate(const_cast<char*>(Str));
37 Attr::Destroy(C);
38}
39
40void AttrWithString::ReplaceString(ASTContext &C, llvm::StringRef newS) {
41 if (newS.size() > StrLen) {
42 C.Deallocate(const_cast<char*>(Str));
Ted Kremeneke2f769b2010-02-11 22:44:22 +000043 Str = new (C) char[newS.size()];
Ted Kremenek3d2c43e2010-02-11 05:28:37 +000044 }
45 StrLen = newS.size();
46 memcpy(const_cast<char*>(Str), newS.data(), StrLen);
47}
48
49void FormatAttr::setType(ASTContext &C, llvm::StringRef type) {
50 ReplaceString(C, type);
51}
52
Ted Kremenek59616112010-02-11 07:31:47 +000053NonNullAttr::NonNullAttr(ASTContext &C, unsigned* arg_nums, unsigned size)
Sean Hunt387475d2010-06-16 23:43:53 +000054 : Attr(attr::NonNull), ArgNums(0), Size(0) {
Ted Kremenek59616112010-02-11 07:31:47 +000055 if (size == 0)
56 return;
57 assert(arg_nums);
58 ArgNums = new (C) unsigned[size];
59 Size = size;
60 memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size);
61}
62
63void NonNullAttr::Destroy(ASTContext &C) {
64 if (ArgNums)
65 C.Deallocate(ArgNums);
66 Attr::Destroy(C);
67}
68
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000069#define DEF_SIMPLE_ATTR_CLONE(ATTR) \
70 Attr *ATTR##Attr::clone(ASTContext &C) const { \
71 return ::new (C) ATTR##Attr; \
72 }
73
74// FIXME: Can we use variadic macro to define DEF_SIMPLE_ATTR_CLONE for
75// "non-simple" classes?
76
Daniel Dunbar4e9255f2010-05-27 02:25:39 +000077DEF_SIMPLE_ATTR_CLONE(AlignMac68k)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000078DEF_SIMPLE_ATTR_CLONE(AlwaysInline)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000079DEF_SIMPLE_ATTR_CLONE(AnalyzerNoReturn)
Ted Kremenek31c780d2010-02-18 00:05:45 +000080DEF_SIMPLE_ATTR_CLONE(BaseCheck)
81DEF_SIMPLE_ATTR_CLONE(CDecl)
82DEF_SIMPLE_ATTR_CLONE(CFReturnsNotRetained)
83DEF_SIMPLE_ATTR_CLONE(CFReturnsRetained)
84DEF_SIMPLE_ATTR_CLONE(Const)
85DEF_SIMPLE_ATTR_CLONE(DLLExport)
86DEF_SIMPLE_ATTR_CLONE(DLLImport)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000087DEF_SIMPLE_ATTR_CLONE(Deprecated)
Ted Kremenek31c780d2010-02-18 00:05:45 +000088DEF_SIMPLE_ATTR_CLONE(FastCall)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000089DEF_SIMPLE_ATTR_CLONE(Final)
Ted Kremenek31c780d2010-02-18 00:05:45 +000090DEF_SIMPLE_ATTR_CLONE(Hiding)
91DEF_SIMPLE_ATTR_CLONE(Malloc)
92DEF_SIMPLE_ATTR_CLONE(NSReturnsNotRetained)
93DEF_SIMPLE_ATTR_CLONE(NSReturnsRetained)
94DEF_SIMPLE_ATTR_CLONE(NoDebug)
95DEF_SIMPLE_ATTR_CLONE(NoInline)
Chris Lattner7255a2d2010-06-22 00:03:40 +000096DEF_SIMPLE_ATTR_CLONE(NoInstrumentFunction)
Ted Kremenek31c780d2010-02-18 00:05:45 +000097DEF_SIMPLE_ATTR_CLONE(NoReturn)
98DEF_SIMPLE_ATTR_CLONE(NoThrow)
99DEF_SIMPLE_ATTR_CLONE(ObjCException)
100DEF_SIMPLE_ATTR_CLONE(ObjCNSObject)
101DEF_SIMPLE_ATTR_CLONE(Override)
102DEF_SIMPLE_ATTR_CLONE(Packed)
103DEF_SIMPLE_ATTR_CLONE(Pure)
104DEF_SIMPLE_ATTR_CLONE(StdCall)
Douglas Gregorf813a2c2010-05-18 16:57:00 +0000105DEF_SIMPLE_ATTR_CLONE(ThisCall)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000106DEF_SIMPLE_ATTR_CLONE(TransparentUnion)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000107DEF_SIMPLE_ATTR_CLONE(Unavailable)
108DEF_SIMPLE_ATTR_CLONE(Unused)
109DEF_SIMPLE_ATTR_CLONE(Used)
Ted Kremenek31c780d2010-02-18 00:05:45 +0000110DEF_SIMPLE_ATTR_CLONE(WarnUnusedResult)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000111DEF_SIMPLE_ATTR_CLONE(Weak)
112DEF_SIMPLE_ATTR_CLONE(WeakImport)
Rafael Espindola11e8ce72010-02-23 22:00:30 +0000113DEF_SIMPLE_ATTR_CLONE(WeakRef)
Charles Davis5a0164d2010-02-10 23:06:52 +0000114DEF_SIMPLE_ATTR_CLONE(X86ForceAlignArgPointer)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000115
Daniel Dunbar8a2c92c2010-05-27 01:12:46 +0000116Attr* MaxFieldAlignmentAttr::clone(ASTContext &C) const {
117 return ::new (C) MaxFieldAlignmentAttr(Alignment);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000118}
119
120Attr* AlignedAttr::clone(ASTContext &C) const {
121 return ::new (C) AlignedAttr(Alignment);
122}
123
124Attr* AnnotateAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000125 return ::new (C) AnnotateAttr(C, getAnnotation());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000126}
127
128Attr *AsmLabelAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000129 return ::new (C) AsmLabelAttr(C, getLabel());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000130}
131
132Attr *AliasAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000133 return ::new (C) AliasAttr(C, getAliasee());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000134}
135
136Attr *ConstructorAttr::clone(ASTContext &C) const {
137 return ::new (C) ConstructorAttr(priority);
138}
139
140Attr *DestructorAttr::clone(ASTContext &C) const {
141 return ::new (C) DestructorAttr(priority);
142}
143
144Attr *IBOutletAttr::clone(ASTContext &C) const {
145 return ::new (C) IBOutletAttr;
146}
147
Ted Kremenek857e9182010-05-19 17:38:06 +0000148Attr *IBOutletCollectionAttr::clone(ASTContext &C) const {
149 return ::new (C) IBOutletCollectionAttr(D);
150}
151
Ted Kremenekefbddd22010-02-17 02:37:45 +0000152Attr *IBActionAttr::clone(ASTContext &C) const {
153 return ::new (C) IBActionAttr;
154}
155
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000156Attr *GNUInlineAttr::clone(ASTContext &C) const {
157 return ::new (C) GNUInlineAttr;
158}
159
160Attr *SectionAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000161 return ::new (C) SectionAttr(C, getName());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000162}
163
164Attr *NonNullAttr::clone(ASTContext &C) const {
Ted Kremenek59616112010-02-11 07:31:47 +0000165 return ::new (C) NonNullAttr(C, ArgNums, Size);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000166}
167
168Attr *FormatAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000169 return ::new (C) FormatAttr(C, getType(), formatIdx, firstArg);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000170}
171
172Attr *FormatArgAttr::clone(ASTContext &C) const {
173 return ::new (C) FormatArgAttr(formatIdx);
174}
175
176Attr *SentinelAttr::clone(ASTContext &C) const {
177 return ::new (C) SentinelAttr(sentinel, NullPos);
178}
179
180Attr *VisibilityAttr::clone(ASTContext &C) const {
181 return ::new (C) VisibilityAttr(VisibilityType);
182}
183
184Attr *OverloadableAttr::clone(ASTContext &C) const {
185 return ::new (C) OverloadableAttr;
186}
187
188Attr *BlocksAttr::clone(ASTContext &C) const {
189 return ::new (C) BlocksAttr(BlocksAttrType);
190}
191
192Attr *CleanupAttr::clone(ASTContext &C) const {
193 return ::new (C) CleanupAttr(FD);
194}
195
196Attr *RegparmAttr::clone(ASTContext &C) const {
197 return ::new (C) RegparmAttr(NumParams);
198}
199
200Attr *ReqdWorkGroupSizeAttr::clone(ASTContext &C) const {
201 return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z);
202}
203
Fariborz Jahanian521f12d2010-06-18 21:44:06 +0000204Attr *InitPriorityAttr::clone(ASTContext &C) const {
205 return ::new (C) InitPriorityAttr(Priority);
206}
207
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000208Attr *MSP430InterruptAttr::clone(ASTContext &C) const {
209 return ::new (C) MSP430InterruptAttr(Number);
210}