blob: 7277bbce24bb44b2722cca8f8011e7384407c1cb [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
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000051#define DEF_SIMPLE_ATTR_CLONE(ATTR) \
52 Attr *ATTR##Attr::clone(ASTContext &C) const { \
53 return ::new (C) ATTR##Attr; \
54 }
55
56// FIXME: Can we use variadic macro to define DEF_SIMPLE_ATTR_CLONE for
57// "non-simple" classes?
58
Daniel Dunbar4e9255f2010-05-27 02:25:39 +000059DEF_SIMPLE_ATTR_CLONE(AlignMac68k)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000060DEF_SIMPLE_ATTR_CLONE(AlwaysInline)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000061DEF_SIMPLE_ATTR_CLONE(AnalyzerNoReturn)
Ted Kremenek31c780d2010-02-18 00:05:45 +000062DEF_SIMPLE_ATTR_CLONE(BaseCheck)
63DEF_SIMPLE_ATTR_CLONE(CDecl)
64DEF_SIMPLE_ATTR_CLONE(CFReturnsNotRetained)
65DEF_SIMPLE_ATTR_CLONE(CFReturnsRetained)
66DEF_SIMPLE_ATTR_CLONE(Const)
67DEF_SIMPLE_ATTR_CLONE(DLLExport)
68DEF_SIMPLE_ATTR_CLONE(DLLImport)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000069DEF_SIMPLE_ATTR_CLONE(Deprecated)
Ted Kremenek31c780d2010-02-18 00:05:45 +000070DEF_SIMPLE_ATTR_CLONE(FastCall)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000071DEF_SIMPLE_ATTR_CLONE(Final)
Ted Kremenek31c780d2010-02-18 00:05:45 +000072DEF_SIMPLE_ATTR_CLONE(Hiding)
73DEF_SIMPLE_ATTR_CLONE(Malloc)
74DEF_SIMPLE_ATTR_CLONE(NSReturnsNotRetained)
75DEF_SIMPLE_ATTR_CLONE(NSReturnsRetained)
76DEF_SIMPLE_ATTR_CLONE(NoDebug)
77DEF_SIMPLE_ATTR_CLONE(NoInline)
Chris Lattner7255a2d2010-06-22 00:03:40 +000078DEF_SIMPLE_ATTR_CLONE(NoInstrumentFunction)
Ted Kremenek31c780d2010-02-18 00:05:45 +000079DEF_SIMPLE_ATTR_CLONE(NoReturn)
80DEF_SIMPLE_ATTR_CLONE(NoThrow)
81DEF_SIMPLE_ATTR_CLONE(ObjCException)
82DEF_SIMPLE_ATTR_CLONE(ObjCNSObject)
83DEF_SIMPLE_ATTR_CLONE(Override)
84DEF_SIMPLE_ATTR_CLONE(Packed)
85DEF_SIMPLE_ATTR_CLONE(Pure)
86DEF_SIMPLE_ATTR_CLONE(StdCall)
Douglas Gregorf813a2c2010-05-18 16:57:00 +000087DEF_SIMPLE_ATTR_CLONE(ThisCall)
Ted Kremenek31c780d2010-02-18 00:05:45 +000088DEF_SIMPLE_ATTR_CLONE(TransparentUnion)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000089DEF_SIMPLE_ATTR_CLONE(Unavailable)
90DEF_SIMPLE_ATTR_CLONE(Unused)
91DEF_SIMPLE_ATTR_CLONE(Used)
Ted Kremenek31c780d2010-02-18 00:05:45 +000092DEF_SIMPLE_ATTR_CLONE(WarnUnusedResult)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000093DEF_SIMPLE_ATTR_CLONE(Weak)
94DEF_SIMPLE_ATTR_CLONE(WeakImport)
Rafael Espindola11e8ce72010-02-23 22:00:30 +000095DEF_SIMPLE_ATTR_CLONE(WeakRef)
Charles Davis5a0164d2010-02-10 23:06:52 +000096DEF_SIMPLE_ATTR_CLONE(X86ForceAlignArgPointer)
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +000097
Daniel Dunbar8a2c92c2010-05-27 01:12:46 +000098Attr* MaxFieldAlignmentAttr::clone(ASTContext &C) const {
99 return ::new (C) MaxFieldAlignmentAttr(Alignment);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000100}
101
102Attr* AlignedAttr::clone(ASTContext &C) const {
103 return ::new (C) AlignedAttr(Alignment);
104}
105
106Attr* AnnotateAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000107 return ::new (C) AnnotateAttr(C, getAnnotation());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000108}
109
110Attr *AsmLabelAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000111 return ::new (C) AsmLabelAttr(C, getLabel());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000112}
113
114Attr *AliasAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000115 return ::new (C) AliasAttr(C, getAliasee());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000116}
117
118Attr *ConstructorAttr::clone(ASTContext &C) const {
119 return ::new (C) ConstructorAttr(priority);
120}
121
122Attr *DestructorAttr::clone(ASTContext &C) const {
123 return ::new (C) DestructorAttr(priority);
124}
125
126Attr *IBOutletAttr::clone(ASTContext &C) const {
127 return ::new (C) IBOutletAttr;
128}
129
Ted Kremenek857e9182010-05-19 17:38:06 +0000130Attr *IBOutletCollectionAttr::clone(ASTContext &C) const {
131 return ::new (C) IBOutletCollectionAttr(D);
132}
133
Ted Kremenekefbddd22010-02-17 02:37:45 +0000134Attr *IBActionAttr::clone(ASTContext &C) const {
135 return ::new (C) IBActionAttr;
136}
137
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000138Attr *GNUInlineAttr::clone(ASTContext &C) const {
139 return ::new (C) GNUInlineAttr;
140}
141
142Attr *SectionAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000143 return ::new (C) SectionAttr(C, getName());
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000144}
145
146Attr *NonNullAttr::clone(ASTContext &C) const {
Ted Kremenek59616112010-02-11 07:31:47 +0000147 return ::new (C) NonNullAttr(C, ArgNums, Size);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000148}
149
150Attr *FormatAttr::clone(ASTContext &C) const {
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000151 return ::new (C) FormatAttr(C, getType(), formatIdx, firstArg);
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000152}
153
154Attr *FormatArgAttr::clone(ASTContext &C) const {
155 return ::new (C) FormatArgAttr(formatIdx);
156}
157
158Attr *SentinelAttr::clone(ASTContext &C) const {
159 return ::new (C) SentinelAttr(sentinel, NullPos);
160}
161
162Attr *VisibilityAttr::clone(ASTContext &C) const {
163 return ::new (C) VisibilityAttr(VisibilityType);
164}
165
166Attr *OverloadableAttr::clone(ASTContext &C) const {
167 return ::new (C) OverloadableAttr;
168}
169
170Attr *BlocksAttr::clone(ASTContext &C) const {
171 return ::new (C) BlocksAttr(BlocksAttrType);
172}
173
174Attr *CleanupAttr::clone(ASTContext &C) const {
175 return ::new (C) CleanupAttr(FD);
176}
177
178Attr *RegparmAttr::clone(ASTContext &C) const {
179 return ::new (C) RegparmAttr(NumParams);
180}
181
182Attr *ReqdWorkGroupSizeAttr::clone(ASTContext &C) const {
183 return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z);
184}
185
Fariborz Jahanian521f12d2010-06-18 21:44:06 +0000186Attr *InitPriorityAttr::clone(ASTContext &C) const {
187 return ::new (C) InitPriorityAttr(Priority);
188}
189
Anton Korobeynikovfc5d5132010-01-10 14:38:13 +0000190Attr *MSP430InterruptAttr::clone(ASTContext &C) const {
191 return ::new (C) MSP430InterruptAttr(Number);
192}