blob: 0fab22caced87a878af645d335657dd2855e2fff [file] [log] [blame]
Anton Korobeynikov3d364fd2010-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 Korobeynikov3d364fd2010-01-10 14:38:13 +000014#include "clang/AST/Attr.h"
15#include "clang/AST/ASTContext.h"
16using namespace clang;
17
Ted Kremenek7f4945a2010-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
27AttrWithString::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
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 Kremenek9c8a6f52010-02-11 22:44:22 +000043 Str = new (C) char[newS.size()];
Ted Kremenek7f4945a2010-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 Kremenek510ee252010-02-11 07:31:47 +000053NonNullAttr::NonNullAttr(ASTContext &C, unsigned* arg_nums, unsigned size)
54 : Attr(NonNull), ArgNums(0), Size(0) {
55 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 Korobeynikov3d364fd2010-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 Dunbarfc6507e2010-05-27 02:25:39 +000077DEF_SIMPLE_ATTR_CLONE(AlignMac68k)
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +000078DEF_SIMPLE_ATTR_CLONE(AlwaysInline)
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +000079DEF_SIMPLE_ATTR_CLONE(AnalyzerNoReturn)
Ted Kremenekd9c66632010-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 Korobeynikov3d364fd2010-01-10 14:38:13 +000087DEF_SIMPLE_ATTR_CLONE(Deprecated)
Ted Kremenekd9c66632010-02-18 00:05:45 +000088DEF_SIMPLE_ATTR_CLONE(FastCall)
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +000089DEF_SIMPLE_ATTR_CLONE(Final)
Ted Kremenekd9c66632010-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)
96DEF_SIMPLE_ATTR_CLONE(NoReturn)
97DEF_SIMPLE_ATTR_CLONE(NoThrow)
98DEF_SIMPLE_ATTR_CLONE(ObjCException)
99DEF_SIMPLE_ATTR_CLONE(ObjCNSObject)
100DEF_SIMPLE_ATTR_CLONE(Override)
101DEF_SIMPLE_ATTR_CLONE(Packed)
102DEF_SIMPLE_ATTR_CLONE(Pure)
103DEF_SIMPLE_ATTR_CLONE(StdCall)
Douglas Gregora941dca2010-05-18 16:57:00 +0000104DEF_SIMPLE_ATTR_CLONE(ThisCall)
Ted Kremenekd9c66632010-02-18 00:05:45 +0000105DEF_SIMPLE_ATTR_CLONE(TransparentUnion)
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000106DEF_SIMPLE_ATTR_CLONE(Unavailable)
107DEF_SIMPLE_ATTR_CLONE(Unused)
108DEF_SIMPLE_ATTR_CLONE(Used)
Ted Kremenekd9c66632010-02-18 00:05:45 +0000109DEF_SIMPLE_ATTR_CLONE(WarnUnusedResult)
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000110DEF_SIMPLE_ATTR_CLONE(Weak)
111DEF_SIMPLE_ATTR_CLONE(WeakImport)
Rafael Espindolac18086a2010-02-23 22:00:30 +0000112DEF_SIMPLE_ATTR_CLONE(WeakRef)
Charles Davisbbc0aa52010-02-10 23:06:52 +0000113DEF_SIMPLE_ATTR_CLONE(X86ForceAlignArgPointer)
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000114
Daniel Dunbar40130442010-05-27 01:12:46 +0000115Attr* MaxFieldAlignmentAttr::clone(ASTContext &C) const {
116 return ::new (C) MaxFieldAlignmentAttr(Alignment);
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000117}
118
119Attr* AlignedAttr::clone(ASTContext &C) const {
120 return ::new (C) AlignedAttr(Alignment);
121}
122
123Attr* AnnotateAttr::clone(ASTContext &C) const {
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000124 return ::new (C) AnnotateAttr(C, getAnnotation());
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000125}
126
127Attr *AsmLabelAttr::clone(ASTContext &C) const {
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000128 return ::new (C) AsmLabelAttr(C, getLabel());
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000129}
130
131Attr *AliasAttr::clone(ASTContext &C) const {
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000132 return ::new (C) AliasAttr(C, getAliasee());
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000133}
134
135Attr *ConstructorAttr::clone(ASTContext &C) const {
136 return ::new (C) ConstructorAttr(priority);
137}
138
139Attr *DestructorAttr::clone(ASTContext &C) const {
140 return ::new (C) DestructorAttr(priority);
141}
142
143Attr *IBOutletAttr::clone(ASTContext &C) const {
144 return ::new (C) IBOutletAttr;
145}
146
Ted Kremenek26bde772010-05-19 17:38:06 +0000147Attr *IBOutletCollectionAttr::clone(ASTContext &C) const {
148 return ::new (C) IBOutletCollectionAttr(D);
149}
150
Ted Kremenek06be9682010-02-17 02:37:45 +0000151Attr *IBActionAttr::clone(ASTContext &C) const {
152 return ::new (C) IBActionAttr;
153}
154
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000155Attr *GNUInlineAttr::clone(ASTContext &C) const {
156 return ::new (C) GNUInlineAttr;
157}
158
159Attr *SectionAttr::clone(ASTContext &C) const {
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000160 return ::new (C) SectionAttr(C, getName());
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000161}
162
163Attr *NonNullAttr::clone(ASTContext &C) const {
Ted Kremenek510ee252010-02-11 07:31:47 +0000164 return ::new (C) NonNullAttr(C, ArgNums, Size);
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000165}
166
167Attr *FormatAttr::clone(ASTContext &C) const {
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000168 return ::new (C) FormatAttr(C, getType(), formatIdx, firstArg);
Anton Korobeynikov3d364fd2010-01-10 14:38:13 +0000169}
170
171Attr *FormatArgAttr::clone(ASTContext &C) const {
172 return ::new (C) FormatArgAttr(formatIdx);
173}
174
175Attr *SentinelAttr::clone(ASTContext &C) const {
176 return ::new (C) SentinelAttr(sentinel, NullPos);
177}
178
179Attr *VisibilityAttr::clone(ASTContext &C) const {
180 return ::new (C) VisibilityAttr(VisibilityType);
181}
182
183Attr *OverloadableAttr::clone(ASTContext &C) const {
184 return ::new (C) OverloadableAttr;
185}
186
187Attr *BlocksAttr::clone(ASTContext &C) const {
188 return ::new (C) BlocksAttr(BlocksAttrType);
189}
190
191Attr *CleanupAttr::clone(ASTContext &C) const {
192 return ::new (C) CleanupAttr(FD);
193}
194
195Attr *RegparmAttr::clone(ASTContext &C) const {
196 return ::new (C) RegparmAttr(NumParams);
197}
198
199Attr *ReqdWorkGroupSizeAttr::clone(ASTContext &C) const {
200 return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z);
201}
202
203Attr *MSP430InterruptAttr::clone(ASTContext &C) const {
204 return ::new (C) MSP430InterruptAttr(Number);
205}