File: | build-llvm/tools/clang/include/clang/AST/Attrs.inc |
Warning: | line 2305, column 5 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- Decl.cpp - Declaration AST Node Implementation ---------------------===// | |||
2 | // | |||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||
4 | // See https://llvm.org/LICENSE.txt for license information. | |||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||
6 | // | |||
7 | //===----------------------------------------------------------------------===// | |||
8 | // | |||
9 | // This file implements the Decl subclasses. | |||
10 | // | |||
11 | //===----------------------------------------------------------------------===// | |||
12 | ||||
13 | #include "clang/AST/Decl.h" | |||
14 | #include "Linkage.h" | |||
15 | #include "clang/AST/ASTContext.h" | |||
16 | #include "clang/AST/ASTDiagnostic.h" | |||
17 | #include "clang/AST/ASTLambda.h" | |||
18 | #include "clang/AST/ASTMutationListener.h" | |||
19 | #include "clang/AST/CanonicalType.h" | |||
20 | #include "clang/AST/DeclBase.h" | |||
21 | #include "clang/AST/DeclCXX.h" | |||
22 | #include "clang/AST/DeclObjC.h" | |||
23 | #include "clang/AST/DeclOpenMP.h" | |||
24 | #include "clang/AST/DeclTemplate.h" | |||
25 | #include "clang/AST/DeclarationName.h" | |||
26 | #include "clang/AST/Expr.h" | |||
27 | #include "clang/AST/ExprCXX.h" | |||
28 | #include "clang/AST/ExternalASTSource.h" | |||
29 | #include "clang/AST/ODRHash.h" | |||
30 | #include "clang/AST/PrettyDeclStackTrace.h" | |||
31 | #include "clang/AST/PrettyPrinter.h" | |||
32 | #include "clang/AST/Redeclarable.h" | |||
33 | #include "clang/AST/Stmt.h" | |||
34 | #include "clang/AST/TemplateBase.h" | |||
35 | #include "clang/AST/Type.h" | |||
36 | #include "clang/AST/TypeLoc.h" | |||
37 | #include "clang/Basic/Builtins.h" | |||
38 | #include "clang/Basic/IdentifierTable.h" | |||
39 | #include "clang/Basic/LLVM.h" | |||
40 | #include "clang/Basic/LangOptions.h" | |||
41 | #include "clang/Basic/Linkage.h" | |||
42 | #include "clang/Basic/Module.h" | |||
43 | #include "clang/Basic/PartialDiagnostic.h" | |||
44 | #include "clang/Basic/SanitizerBlacklist.h" | |||
45 | #include "clang/Basic/Sanitizers.h" | |||
46 | #include "clang/Basic/SourceLocation.h" | |||
47 | #include "clang/Basic/SourceManager.h" | |||
48 | #include "clang/Basic/Specifiers.h" | |||
49 | #include "clang/Basic/TargetCXXABI.h" | |||
50 | #include "clang/Basic/TargetInfo.h" | |||
51 | #include "clang/Basic/Visibility.h" | |||
52 | #include "llvm/ADT/APSInt.h" | |||
53 | #include "llvm/ADT/ArrayRef.h" | |||
54 | #include "llvm/ADT/None.h" | |||
55 | #include "llvm/ADT/Optional.h" | |||
56 | #include "llvm/ADT/STLExtras.h" | |||
57 | #include "llvm/ADT/SmallVector.h" | |||
58 | #include "llvm/ADT/StringSwitch.h" | |||
59 | #include "llvm/ADT/StringRef.h" | |||
60 | #include "llvm/ADT/Triple.h" | |||
61 | #include "llvm/Support/Casting.h" | |||
62 | #include "llvm/Support/ErrorHandling.h" | |||
63 | #include "llvm/Support/raw_ostream.h" | |||
64 | #include <algorithm> | |||
65 | #include <cassert> | |||
66 | #include <cstddef> | |||
67 | #include <cstring> | |||
68 | #include <memory> | |||
69 | #include <string> | |||
70 | #include <tuple> | |||
71 | #include <type_traits> | |||
72 | ||||
73 | using namespace clang; | |||
74 | ||||
75 | Decl *clang::getPrimaryMergedDecl(Decl *D) { | |||
76 | return D->getASTContext().getPrimaryMergedDecl(D); | |||
77 | } | |||
78 | ||||
79 | void PrettyDeclStackTraceEntry::print(raw_ostream &OS) const { | |||
80 | SourceLocation Loc = this->Loc; | |||
81 | if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation(); | |||
82 | if (Loc.isValid()) { | |||
83 | Loc.print(OS, Context.getSourceManager()); | |||
84 | OS << ": "; | |||
85 | } | |||
86 | OS << Message; | |||
87 | ||||
88 | if (auto *ND = dyn_cast_or_null<NamedDecl>(TheDecl)) { | |||
89 | OS << " '"; | |||
90 | ND->getNameForDiagnostic(OS, Context.getPrintingPolicy(), true); | |||
91 | OS << "'"; | |||
92 | } | |||
93 | ||||
94 | OS << '\n'; | |||
95 | } | |||
96 | ||||
97 | // Defined here so that it can be inlined into its direct callers. | |||
98 | bool Decl::isOutOfLine() const { | |||
99 | return !getLexicalDeclContext()->Equals(getDeclContext()); | |||
100 | } | |||
101 | ||||
102 | TranslationUnitDecl::TranslationUnitDecl(ASTContext &ctx) | |||
103 | : Decl(TranslationUnit, nullptr, SourceLocation()), | |||
104 | DeclContext(TranslationUnit), Ctx(ctx) {} | |||
105 | ||||
106 | //===----------------------------------------------------------------------===// | |||
107 | // NamedDecl Implementation | |||
108 | //===----------------------------------------------------------------------===// | |||
109 | ||||
110 | // Visibility rules aren't rigorously externally specified, but here | |||
111 | // are the basic principles behind what we implement: | |||
112 | // | |||
113 | // 1. An explicit visibility attribute is generally a direct expression | |||
114 | // of the user's intent and should be honored. Only the innermost | |||
115 | // visibility attribute applies. If no visibility attribute applies, | |||
116 | // global visibility settings are considered. | |||
117 | // | |||
118 | // 2. There is one caveat to the above: on or in a template pattern, | |||
119 | // an explicit visibility attribute is just a default rule, and | |||
120 | // visibility can be decreased by the visibility of template | |||
121 | // arguments. But this, too, has an exception: an attribute on an | |||
122 | // explicit specialization or instantiation causes all the visibility | |||
123 | // restrictions of the template arguments to be ignored. | |||
124 | // | |||
125 | // 3. A variable that does not otherwise have explicit visibility can | |||
126 | // be restricted by the visibility of its type. | |||
127 | // | |||
128 | // 4. A visibility restriction is explicit if it comes from an | |||
129 | // attribute (or something like it), not a global visibility setting. | |||
130 | // When emitting a reference to an external symbol, visibility | |||
131 | // restrictions are ignored unless they are explicit. | |||
132 | // | |||
133 | // 5. When computing the visibility of a non-type, including a | |||
134 | // non-type member of a class, only non-type visibility restrictions | |||
135 | // are considered: the 'visibility' attribute, global value-visibility | |||
136 | // settings, and a few special cases like __private_extern. | |||
137 | // | |||
138 | // 6. When computing the visibility of a type, including a type member | |||
139 | // of a class, only type visibility restrictions are considered: | |||
140 | // the 'type_visibility' attribute and global type-visibility settings. | |||
141 | // However, a 'visibility' attribute counts as a 'type_visibility' | |||
142 | // attribute on any declaration that only has the former. | |||
143 | // | |||
144 | // The visibility of a "secondary" entity, like a template argument, | |||
145 | // is computed using the kind of that entity, not the kind of the | |||
146 | // primary entity for which we are computing visibility. For example, | |||
147 | // the visibility of a specialization of either of these templates: | |||
148 | // template <class T, bool (&compare)(T, X)> bool has_match(list<T>, X); | |||
149 | // template <class T, bool (&compare)(T, X)> class matcher; | |||
150 | // is restricted according to the type visibility of the argument 'T', | |||
151 | // the type visibility of 'bool(&)(T,X)', and the value visibility of | |||
152 | // the argument function 'compare'. That 'has_match' is a value | |||
153 | // and 'matcher' is a type only matters when looking for attributes | |||
154 | // and settings from the immediate context. | |||
155 | ||||
156 | /// Does this computation kind permit us to consider additional | |||
157 | /// visibility settings from attributes and the like? | |||
158 | static bool hasExplicitVisibilityAlready(LVComputationKind computation) { | |||
159 | return computation.IgnoreExplicitVisibility; | |||
160 | } | |||
161 | ||||
162 | /// Given an LVComputationKind, return one of the same type/value sort | |||
163 | /// that records that it already has explicit visibility. | |||
164 | static LVComputationKind | |||
165 | withExplicitVisibilityAlready(LVComputationKind Kind) { | |||
166 | Kind.IgnoreExplicitVisibility = true; | |||
167 | return Kind; | |||
168 | } | |||
169 | ||||
170 | static Optional<Visibility> getExplicitVisibility(const NamedDecl *D, | |||
171 | LVComputationKind kind) { | |||
172 | assert(!kind.IgnoreExplicitVisibility &&((!kind.IgnoreExplicitVisibility && "asking for explicit visibility when we shouldn't be" ) ? static_cast<void> (0) : __assert_fail ("!kind.IgnoreExplicitVisibility && \"asking for explicit visibility when we shouldn't be\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 173, __PRETTY_FUNCTION__)) | |||
173 | "asking for explicit visibility when we shouldn't be")((!kind.IgnoreExplicitVisibility && "asking for explicit visibility when we shouldn't be" ) ? static_cast<void> (0) : __assert_fail ("!kind.IgnoreExplicitVisibility && \"asking for explicit visibility when we shouldn't be\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 173, __PRETTY_FUNCTION__)); | |||
174 | return D->getExplicitVisibility(kind.getExplicitVisibilityKind()); | |||
175 | } | |||
176 | ||||
177 | /// Is the given declaration a "type" or a "value" for the purposes of | |||
178 | /// visibility computation? | |||
179 | static bool usesTypeVisibility(const NamedDecl *D) { | |||
180 | return isa<TypeDecl>(D) || | |||
181 | isa<ClassTemplateDecl>(D) || | |||
182 | isa<ObjCInterfaceDecl>(D); | |||
183 | } | |||
184 | ||||
185 | /// Does the given declaration have member specialization information, | |||
186 | /// and if so, is it an explicit specialization? | |||
187 | template <class T> static typename | |||
188 | std::enable_if<!std::is_base_of<RedeclarableTemplateDecl, T>::value, bool>::type | |||
189 | isExplicitMemberSpecialization(const T *D) { | |||
190 | if (const MemberSpecializationInfo *member = | |||
191 | D->getMemberSpecializationInfo()) { | |||
192 | return member->isExplicitSpecialization(); | |||
193 | } | |||
194 | return false; | |||
195 | } | |||
196 | ||||
197 | /// For templates, this question is easier: a member template can't be | |||
198 | /// explicitly instantiated, so there's a single bit indicating whether | |||
199 | /// or not this is an explicit member specialization. | |||
200 | static bool isExplicitMemberSpecialization(const RedeclarableTemplateDecl *D) { | |||
201 | return D->isMemberSpecialization(); | |||
202 | } | |||
203 | ||||
204 | /// Given a visibility attribute, return the explicit visibility | |||
205 | /// associated with it. | |||
206 | template <class T> | |||
207 | static Visibility getVisibilityFromAttr(const T *attr) { | |||
208 | switch (attr->getVisibility()) { | |||
209 | case T::Default: | |||
210 | return DefaultVisibility; | |||
211 | case T::Hidden: | |||
212 | return HiddenVisibility; | |||
213 | case T::Protected: | |||
214 | return ProtectedVisibility; | |||
215 | } | |||
216 | llvm_unreachable("bad visibility kind")::llvm::llvm_unreachable_internal("bad visibility kind", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 216); | |||
217 | } | |||
218 | ||||
219 | /// Return the explicit visibility of the given declaration. | |||
220 | static Optional<Visibility> getVisibilityOf(const NamedDecl *D, | |||
221 | NamedDecl::ExplicitVisibilityKind kind) { | |||
222 | // If we're ultimately computing the visibility of a type, look for | |||
223 | // a 'type_visibility' attribute before looking for 'visibility'. | |||
224 | if (kind == NamedDecl::VisibilityForType) { | |||
225 | if (const auto *A = D->getAttr<TypeVisibilityAttr>()) { | |||
226 | return getVisibilityFromAttr(A); | |||
227 | } | |||
228 | } | |||
229 | ||||
230 | // If this declaration has an explicit visibility attribute, use it. | |||
231 | if (const auto *A = D->getAttr<VisibilityAttr>()) { | |||
232 | return getVisibilityFromAttr(A); | |||
233 | } | |||
234 | ||||
235 | return None; | |||
236 | } | |||
237 | ||||
238 | LinkageInfo LinkageComputer::getLVForType(const Type &T, | |||
239 | LVComputationKind computation) { | |||
240 | if (computation.IgnoreAllVisibility) | |||
241 | return LinkageInfo(T.getLinkage(), DefaultVisibility, true); | |||
242 | return getTypeLinkageAndVisibility(&T); | |||
243 | } | |||
244 | ||||
245 | /// Get the most restrictive linkage for the types in the given | |||
246 | /// template parameter list. For visibility purposes, template | |||
247 | /// parameters are part of the signature of a template. | |||
248 | LinkageInfo LinkageComputer::getLVForTemplateParameterList( | |||
249 | const TemplateParameterList *Params, LVComputationKind computation) { | |||
250 | LinkageInfo LV; | |||
251 | for (const NamedDecl *P : *Params) { | |||
252 | // Template type parameters are the most common and never | |||
253 | // contribute to visibility, pack or not. | |||
254 | if (isa<TemplateTypeParmDecl>(P)) | |||
255 | continue; | |||
256 | ||||
257 | // Non-type template parameters can be restricted by the value type, e.g. | |||
258 | // template <enum X> class A { ... }; | |||
259 | // We have to be careful here, though, because we can be dealing with | |||
260 | // dependent types. | |||
261 | if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) { | |||
262 | // Handle the non-pack case first. | |||
263 | if (!NTTP->isExpandedParameterPack()) { | |||
264 | if (!NTTP->getType()->isDependentType()) { | |||
265 | LV.merge(getLVForType(*NTTP->getType(), computation)); | |||
266 | } | |||
267 | continue; | |||
268 | } | |||
269 | ||||
270 | // Look at all the types in an expanded pack. | |||
271 | for (unsigned i = 0, n = NTTP->getNumExpansionTypes(); i != n; ++i) { | |||
272 | QualType type = NTTP->getExpansionType(i); | |||
273 | if (!type->isDependentType()) | |||
274 | LV.merge(getTypeLinkageAndVisibility(type)); | |||
275 | } | |||
276 | continue; | |||
277 | } | |||
278 | ||||
279 | // Template template parameters can be restricted by their | |||
280 | // template parameters, recursively. | |||
281 | const auto *TTP = cast<TemplateTemplateParmDecl>(P); | |||
282 | ||||
283 | // Handle the non-pack case first. | |||
284 | if (!TTP->isExpandedParameterPack()) { | |||
285 | LV.merge(getLVForTemplateParameterList(TTP->getTemplateParameters(), | |||
286 | computation)); | |||
287 | continue; | |||
288 | } | |||
289 | ||||
290 | // Look at all expansions in an expanded pack. | |||
291 | for (unsigned i = 0, n = TTP->getNumExpansionTemplateParameters(); | |||
292 | i != n; ++i) { | |||
293 | LV.merge(getLVForTemplateParameterList( | |||
294 | TTP->getExpansionTemplateParameters(i), computation)); | |||
295 | } | |||
296 | } | |||
297 | ||||
298 | return LV; | |||
299 | } | |||
300 | ||||
301 | static const Decl *getOutermostFuncOrBlockContext(const Decl *D) { | |||
302 | const Decl *Ret = nullptr; | |||
303 | const DeclContext *DC = D->getDeclContext(); | |||
304 | while (DC->getDeclKind() != Decl::TranslationUnit) { | |||
305 | if (isa<FunctionDecl>(DC) || isa<BlockDecl>(DC)) | |||
306 | Ret = cast<Decl>(DC); | |||
307 | DC = DC->getParent(); | |||
308 | } | |||
309 | return Ret; | |||
310 | } | |||
311 | ||||
312 | /// Get the most restrictive linkage for the types and | |||
313 | /// declarations in the given template argument list. | |||
314 | /// | |||
315 | /// Note that we don't take an LVComputationKind because we always | |||
316 | /// want to honor the visibility of template arguments in the same way. | |||
317 | LinkageInfo | |||
318 | LinkageComputer::getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args, | |||
319 | LVComputationKind computation) { | |||
320 | LinkageInfo LV; | |||
321 | ||||
322 | for (const TemplateArgument &Arg : Args) { | |||
323 | switch (Arg.getKind()) { | |||
324 | case TemplateArgument::Null: | |||
325 | case TemplateArgument::Integral: | |||
326 | case TemplateArgument::Expression: | |||
327 | continue; | |||
328 | ||||
329 | case TemplateArgument::Type: | |||
330 | LV.merge(getLVForType(*Arg.getAsType(), computation)); | |||
331 | continue; | |||
332 | ||||
333 | case TemplateArgument::Declaration: { | |||
334 | const NamedDecl *ND = Arg.getAsDecl(); | |||
335 | assert(!usesTypeVisibility(ND))((!usesTypeVisibility(ND)) ? static_cast<void> (0) : __assert_fail ("!usesTypeVisibility(ND)", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 335, __PRETTY_FUNCTION__)); | |||
336 | LV.merge(getLVForDecl(ND, computation)); | |||
337 | continue; | |||
338 | } | |||
339 | ||||
340 | case TemplateArgument::NullPtr: | |||
341 | LV.merge(getTypeLinkageAndVisibility(Arg.getNullPtrType())); | |||
342 | continue; | |||
343 | ||||
344 | case TemplateArgument::Template: | |||
345 | case TemplateArgument::TemplateExpansion: | |||
346 | if (TemplateDecl *Template = | |||
347 | Arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl()) | |||
348 | LV.merge(getLVForDecl(Template, computation)); | |||
349 | continue; | |||
350 | ||||
351 | case TemplateArgument::Pack: | |||
352 | LV.merge(getLVForTemplateArgumentList(Arg.getPackAsArray(), computation)); | |||
353 | continue; | |||
354 | } | |||
355 | llvm_unreachable("bad template argument kind")::llvm::llvm_unreachable_internal("bad template argument kind" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 355); | |||
356 | } | |||
357 | ||||
358 | return LV; | |||
359 | } | |||
360 | ||||
361 | LinkageInfo | |||
362 | LinkageComputer::getLVForTemplateArgumentList(const TemplateArgumentList &TArgs, | |||
363 | LVComputationKind computation) { | |||
364 | return getLVForTemplateArgumentList(TArgs.asArray(), computation); | |||
365 | } | |||
366 | ||||
367 | static bool shouldConsiderTemplateVisibility(const FunctionDecl *fn, | |||
368 | const FunctionTemplateSpecializationInfo *specInfo) { | |||
369 | // Include visibility from the template parameters and arguments | |||
370 | // only if this is not an explicit instantiation or specialization | |||
371 | // with direct explicit visibility. (Implicit instantiations won't | |||
372 | // have a direct attribute.) | |||
373 | if (!specInfo->isExplicitInstantiationOrSpecialization()) | |||
374 | return true; | |||
375 | ||||
376 | return !fn->hasAttr<VisibilityAttr>(); | |||
377 | } | |||
378 | ||||
379 | /// Merge in template-related linkage and visibility for the given | |||
380 | /// function template specialization. | |||
381 | /// | |||
382 | /// We don't need a computation kind here because we can assume | |||
383 | /// LVForValue. | |||
384 | /// | |||
385 | /// \param[out] LV the computation to use for the parent | |||
386 | void LinkageComputer::mergeTemplateLV( | |||
387 | LinkageInfo &LV, const FunctionDecl *fn, | |||
388 | const FunctionTemplateSpecializationInfo *specInfo, | |||
389 | LVComputationKind computation) { | |||
390 | bool considerVisibility = | |||
391 | shouldConsiderTemplateVisibility(fn, specInfo); | |||
392 | ||||
393 | // Merge information from the template parameters. | |||
394 | FunctionTemplateDecl *temp = specInfo->getTemplate(); | |||
395 | LinkageInfo tempLV = | |||
396 | getLVForTemplateParameterList(temp->getTemplateParameters(), computation); | |||
397 | LV.mergeMaybeWithVisibility(tempLV, considerVisibility); | |||
398 | ||||
399 | // Merge information from the template arguments. | |||
400 | const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments; | |||
401 | LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation); | |||
402 | LV.mergeMaybeWithVisibility(argsLV, considerVisibility); | |||
403 | } | |||
404 | ||||
405 | /// Does the given declaration have a direct visibility attribute | |||
406 | /// that would match the given rules? | |||
407 | static bool hasDirectVisibilityAttribute(const NamedDecl *D, | |||
408 | LVComputationKind computation) { | |||
409 | if (computation.IgnoreAllVisibility) | |||
410 | return false; | |||
411 | ||||
412 | return (computation.isTypeVisibility() && D->hasAttr<TypeVisibilityAttr>()) || | |||
413 | D->hasAttr<VisibilityAttr>(); | |||
414 | } | |||
415 | ||||
416 | /// Should we consider visibility associated with the template | |||
417 | /// arguments and parameters of the given class template specialization? | |||
418 | static bool shouldConsiderTemplateVisibility( | |||
419 | const ClassTemplateSpecializationDecl *spec, | |||
420 | LVComputationKind computation) { | |||
421 | // Include visibility from the template parameters and arguments | |||
422 | // only if this is not an explicit instantiation or specialization | |||
423 | // with direct explicit visibility (and note that implicit | |||
424 | // instantiations won't have a direct attribute). | |||
425 | // | |||
426 | // Furthermore, we want to ignore template parameters and arguments | |||
427 | // for an explicit specialization when computing the visibility of a | |||
428 | // member thereof with explicit visibility. | |||
429 | // | |||
430 | // This is a bit complex; let's unpack it. | |||
431 | // | |||
432 | // An explicit class specialization is an independent, top-level | |||
433 | // declaration. As such, if it or any of its members has an | |||
434 | // explicit visibility attribute, that must directly express the | |||
435 | // user's intent, and we should honor it. The same logic applies to | |||
436 | // an explicit instantiation of a member of such a thing. | |||
437 | ||||
438 | // Fast path: if this is not an explicit instantiation or | |||
439 | // specialization, we always want to consider template-related | |||
440 | // visibility restrictions. | |||
441 | if (!spec->isExplicitInstantiationOrSpecialization()) | |||
442 | return true; | |||
443 | ||||
444 | // This is the 'member thereof' check. | |||
445 | if (spec->isExplicitSpecialization() && | |||
446 | hasExplicitVisibilityAlready(computation)) | |||
447 | return false; | |||
448 | ||||
449 | return !hasDirectVisibilityAttribute(spec, computation); | |||
450 | } | |||
451 | ||||
452 | /// Merge in template-related linkage and visibility for the given | |||
453 | /// class template specialization. | |||
454 | void LinkageComputer::mergeTemplateLV( | |||
455 | LinkageInfo &LV, const ClassTemplateSpecializationDecl *spec, | |||
456 | LVComputationKind computation) { | |||
457 | bool considerVisibility = shouldConsiderTemplateVisibility(spec, computation); | |||
458 | ||||
459 | // Merge information from the template parameters, but ignore | |||
460 | // visibility if we're only considering template arguments. | |||
461 | ||||
462 | ClassTemplateDecl *temp = spec->getSpecializedTemplate(); | |||
463 | LinkageInfo tempLV = | |||
464 | getLVForTemplateParameterList(temp->getTemplateParameters(), computation); | |||
465 | LV.mergeMaybeWithVisibility(tempLV, | |||
466 | considerVisibility && !hasExplicitVisibilityAlready(computation)); | |||
467 | ||||
468 | // Merge information from the template arguments. We ignore | |||
469 | // template-argument visibility if we've got an explicit | |||
470 | // instantiation with a visibility attribute. | |||
471 | const TemplateArgumentList &templateArgs = spec->getTemplateArgs(); | |||
472 | LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation); | |||
473 | if (considerVisibility) | |||
474 | LV.mergeVisibility(argsLV); | |||
475 | LV.mergeExternalVisibility(argsLV); | |||
476 | } | |||
477 | ||||
478 | /// Should we consider visibility associated with the template | |||
479 | /// arguments and parameters of the given variable template | |||
480 | /// specialization? As usual, follow class template specialization | |||
481 | /// logic up to initialization. | |||
482 | static bool shouldConsiderTemplateVisibility( | |||
483 | const VarTemplateSpecializationDecl *spec, | |||
484 | LVComputationKind computation) { | |||
485 | // Include visibility from the template parameters and arguments | |||
486 | // only if this is not an explicit instantiation or specialization | |||
487 | // with direct explicit visibility (and note that implicit | |||
488 | // instantiations won't have a direct attribute). | |||
489 | if (!spec->isExplicitInstantiationOrSpecialization()) | |||
490 | return true; | |||
491 | ||||
492 | // An explicit variable specialization is an independent, top-level | |||
493 | // declaration. As such, if it has an explicit visibility attribute, | |||
494 | // that must directly express the user's intent, and we should honor | |||
495 | // it. | |||
496 | if (spec->isExplicitSpecialization() && | |||
497 | hasExplicitVisibilityAlready(computation)) | |||
498 | return false; | |||
499 | ||||
500 | return !hasDirectVisibilityAttribute(spec, computation); | |||
501 | } | |||
502 | ||||
503 | /// Merge in template-related linkage and visibility for the given | |||
504 | /// variable template specialization. As usual, follow class template | |||
505 | /// specialization logic up to initialization. | |||
506 | void LinkageComputer::mergeTemplateLV(LinkageInfo &LV, | |||
507 | const VarTemplateSpecializationDecl *spec, | |||
508 | LVComputationKind computation) { | |||
509 | bool considerVisibility = shouldConsiderTemplateVisibility(spec, computation); | |||
510 | ||||
511 | // Merge information from the template parameters, but ignore | |||
512 | // visibility if we're only considering template arguments. | |||
513 | ||||
514 | VarTemplateDecl *temp = spec->getSpecializedTemplate(); | |||
515 | LinkageInfo tempLV = | |||
516 | getLVForTemplateParameterList(temp->getTemplateParameters(), computation); | |||
517 | LV.mergeMaybeWithVisibility(tempLV, | |||
518 | considerVisibility && !hasExplicitVisibilityAlready(computation)); | |||
519 | ||||
520 | // Merge information from the template arguments. We ignore | |||
521 | // template-argument visibility if we've got an explicit | |||
522 | // instantiation with a visibility attribute. | |||
523 | const TemplateArgumentList &templateArgs = spec->getTemplateArgs(); | |||
524 | LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation); | |||
525 | if (considerVisibility) | |||
526 | LV.mergeVisibility(argsLV); | |||
527 | LV.mergeExternalVisibility(argsLV); | |||
528 | } | |||
529 | ||||
530 | static bool useInlineVisibilityHidden(const NamedDecl *D) { | |||
531 | // FIXME: we should warn if -fvisibility-inlines-hidden is used with c. | |||
532 | const LangOptions &Opts = D->getASTContext().getLangOpts(); | |||
533 | if (!Opts.CPlusPlus || !Opts.InlineVisibilityHidden) | |||
534 | return false; | |||
535 | ||||
536 | const auto *FD = dyn_cast<FunctionDecl>(D); | |||
537 | if (!FD) | |||
538 | return false; | |||
539 | ||||
540 | TemplateSpecializationKind TSK = TSK_Undeclared; | |||
541 | if (FunctionTemplateSpecializationInfo *spec | |||
542 | = FD->getTemplateSpecializationInfo()) { | |||
543 | TSK = spec->getTemplateSpecializationKind(); | |||
544 | } else if (MemberSpecializationInfo *MSI = | |||
545 | FD->getMemberSpecializationInfo()) { | |||
546 | TSK = MSI->getTemplateSpecializationKind(); | |||
547 | } | |||
548 | ||||
549 | const FunctionDecl *Def = nullptr; | |||
550 | // InlineVisibilityHidden only applies to definitions, and | |||
551 | // isInlined() only gives meaningful answers on definitions | |||
552 | // anyway. | |||
553 | return TSK != TSK_ExplicitInstantiationDeclaration && | |||
554 | TSK != TSK_ExplicitInstantiationDefinition && | |||
555 | FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr<GNUInlineAttr>(); | |||
556 | } | |||
557 | ||||
558 | template <typename T> static bool isFirstInExternCContext(T *D) { | |||
559 | const T *First = D->getFirstDecl(); | |||
560 | return First->isInExternCContext(); | |||
561 | } | |||
562 | ||||
563 | static bool isSingleLineLanguageLinkage(const Decl &D) { | |||
564 | if (const auto *SD = dyn_cast<LinkageSpecDecl>(D.getDeclContext())) | |||
565 | if (!SD->hasBraces()) | |||
566 | return true; | |||
567 | return false; | |||
568 | } | |||
569 | ||||
570 | /// Determine whether D is declared in the purview of a named module. | |||
571 | static bool isInModulePurview(const NamedDecl *D) { | |||
572 | if (auto *M = D->getOwningModule()) | |||
573 | return M->isModulePurview(); | |||
574 | return false; | |||
575 | } | |||
576 | ||||
577 | static bool isExportedFromModuleInterfaceUnit(const NamedDecl *D) { | |||
578 | // FIXME: Handle isModulePrivate. | |||
579 | switch (D->getModuleOwnershipKind()) { | |||
580 | case Decl::ModuleOwnershipKind::Unowned: | |||
581 | case Decl::ModuleOwnershipKind::ModulePrivate: | |||
582 | return false; | |||
583 | case Decl::ModuleOwnershipKind::Visible: | |||
584 | case Decl::ModuleOwnershipKind::VisibleWhenImported: | |||
585 | return isInModulePurview(D); | |||
586 | } | |||
587 | llvm_unreachable("unexpected module ownership kind")::llvm::llvm_unreachable_internal("unexpected module ownership kind" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 587); | |||
588 | } | |||
589 | ||||
590 | static LinkageInfo getInternalLinkageFor(const NamedDecl *D) { | |||
591 | // Internal linkage declarations within a module interface unit are modeled | |||
592 | // as "module-internal linkage", which means that they have internal linkage | |||
593 | // formally but can be indirectly accessed from outside the module via inline | |||
594 | // functions and templates defined within the module. | |||
595 | if (isInModulePurview(D)) | |||
596 | return LinkageInfo(ModuleInternalLinkage, DefaultVisibility, false); | |||
597 | ||||
598 | return LinkageInfo::internal(); | |||
599 | } | |||
600 | ||||
601 | static LinkageInfo getExternalLinkageFor(const NamedDecl *D) { | |||
602 | // C++ Modules TS [basic.link]/6.8: | |||
603 | // - A name declared at namespace scope that does not have internal linkage | |||
604 | // by the previous rules and that is introduced by a non-exported | |||
605 | // declaration has module linkage. | |||
606 | if (isInModulePurview(D) && !isExportedFromModuleInterfaceUnit( | |||
607 | cast<NamedDecl>(D->getCanonicalDecl()))) | |||
608 | return LinkageInfo(ModuleLinkage, DefaultVisibility, false); | |||
609 | ||||
610 | return LinkageInfo::external(); | |||
611 | } | |||
612 | ||||
613 | static StorageClass getStorageClass(const Decl *D) { | |||
614 | if (auto *TD = dyn_cast<TemplateDecl>(D)) | |||
615 | D = TD->getTemplatedDecl(); | |||
616 | if (D) { | |||
617 | if (auto *VD = dyn_cast<VarDecl>(D)) | |||
618 | return VD->getStorageClass(); | |||
619 | if (auto *FD = dyn_cast<FunctionDecl>(D)) | |||
620 | return FD->getStorageClass(); | |||
621 | } | |||
622 | return SC_None; | |||
623 | } | |||
624 | ||||
625 | LinkageInfo | |||
626 | LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, | |||
627 | LVComputationKind computation, | |||
628 | bool IgnoreVarTypeLinkage) { | |||
629 | assert(D->getDeclContext()->getRedeclContext()->isFileContext() &&((D->getDeclContext()->getRedeclContext()->isFileContext () && "Not a name having namespace scope") ? static_cast <void> (0) : __assert_fail ("D->getDeclContext()->getRedeclContext()->isFileContext() && \"Not a name having namespace scope\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 630, __PRETTY_FUNCTION__)) | |||
630 | "Not a name having namespace scope")((D->getDeclContext()->getRedeclContext()->isFileContext () && "Not a name having namespace scope") ? static_cast <void> (0) : __assert_fail ("D->getDeclContext()->getRedeclContext()->isFileContext() && \"Not a name having namespace scope\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 630, __PRETTY_FUNCTION__)); | |||
631 | ASTContext &Context = D->getASTContext(); | |||
632 | ||||
633 | // C++ [basic.link]p3: | |||
634 | // A name having namespace scope (3.3.6) has internal linkage if it | |||
635 | // is the name of | |||
636 | ||||
637 | if (getStorageClass(D->getCanonicalDecl()) == SC_Static) { | |||
638 | // - a variable, variable template, function, or function template | |||
639 | // that is explicitly declared static; or | |||
640 | // (This bullet corresponds to C99 6.2.2p3.) | |||
641 | return getInternalLinkageFor(D); | |||
642 | } | |||
643 | ||||
644 | if (const auto *Var = dyn_cast<VarDecl>(D)) { | |||
645 | // - a non-template variable of non-volatile const-qualified type, unless | |||
646 | // - it is explicitly declared extern, or | |||
647 | // - it is inline or exported, or | |||
648 | // - it was previously declared and the prior declaration did not have | |||
649 | // internal linkage | |||
650 | // (There is no equivalent in C99.) | |||
651 | if (Context.getLangOpts().CPlusPlus && | |||
652 | Var->getType().isConstQualified() && | |||
653 | !Var->getType().isVolatileQualified() && | |||
654 | !Var->isInline() && | |||
655 | !isExportedFromModuleInterfaceUnit(Var) && | |||
656 | !isa<VarTemplateSpecializationDecl>(Var) && | |||
657 | !Var->getDescribedVarTemplate()) { | |||
658 | const VarDecl *PrevVar = Var->getPreviousDecl(); | |||
659 | if (PrevVar) | |||
660 | return getLVForDecl(PrevVar, computation); | |||
661 | ||||
662 | if (Var->getStorageClass() != SC_Extern && | |||
663 | Var->getStorageClass() != SC_PrivateExtern && | |||
664 | !isSingleLineLanguageLinkage(*Var)) | |||
665 | return getInternalLinkageFor(Var); | |||
666 | } | |||
667 | ||||
668 | for (const VarDecl *PrevVar = Var->getPreviousDecl(); PrevVar; | |||
669 | PrevVar = PrevVar->getPreviousDecl()) { | |||
670 | if (PrevVar->getStorageClass() == SC_PrivateExtern && | |||
671 | Var->getStorageClass() == SC_None) | |||
672 | return getDeclLinkageAndVisibility(PrevVar); | |||
673 | // Explicitly declared static. | |||
674 | if (PrevVar->getStorageClass() == SC_Static) | |||
675 | return getInternalLinkageFor(Var); | |||
676 | } | |||
677 | } else if (const auto *IFD = dyn_cast<IndirectFieldDecl>(D)) { | |||
678 | // - a data member of an anonymous union. | |||
679 | const VarDecl *VD = IFD->getVarDecl(); | |||
680 | assert(VD && "Expected a VarDecl in this IndirectFieldDecl!")((VD && "Expected a VarDecl in this IndirectFieldDecl!" ) ? static_cast<void> (0) : __assert_fail ("VD && \"Expected a VarDecl in this IndirectFieldDecl!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 680, __PRETTY_FUNCTION__)); | |||
681 | return getLVForNamespaceScopeDecl(VD, computation, IgnoreVarTypeLinkage); | |||
682 | } | |||
683 | assert(!isa<FieldDecl>(D) && "Didn't expect a FieldDecl!")((!isa<FieldDecl>(D) && "Didn't expect a FieldDecl!" ) ? static_cast<void> (0) : __assert_fail ("!isa<FieldDecl>(D) && \"Didn't expect a FieldDecl!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 683, __PRETTY_FUNCTION__)); | |||
684 | ||||
685 | // FIXME: This gives internal linkage to names that should have no linkage | |||
686 | // (those not covered by [basic.link]p6). | |||
687 | if (D->isInAnonymousNamespace()) { | |||
688 | const auto *Var = dyn_cast<VarDecl>(D); | |||
689 | const auto *Func = dyn_cast<FunctionDecl>(D); | |||
690 | // FIXME: The check for extern "C" here is not justified by the standard | |||
691 | // wording, but we retain it from the pre-DR1113 model to avoid breaking | |||
692 | // code. | |||
693 | // | |||
694 | // C++11 [basic.link]p4: | |||
695 | // An unnamed namespace or a namespace declared directly or indirectly | |||
696 | // within an unnamed namespace has internal linkage. | |||
697 | if ((!Var || !isFirstInExternCContext(Var)) && | |||
698 | (!Func || !isFirstInExternCContext(Func))) | |||
699 | return getInternalLinkageFor(D); | |||
700 | } | |||
701 | ||||
702 | // Set up the defaults. | |||
703 | ||||
704 | // C99 6.2.2p5: | |||
705 | // If the declaration of an identifier for an object has file | |||
706 | // scope and no storage-class specifier, its linkage is | |||
707 | // external. | |||
708 | LinkageInfo LV = getExternalLinkageFor(D); | |||
709 | ||||
710 | if (!hasExplicitVisibilityAlready(computation)) { | |||
711 | if (Optional<Visibility> Vis = getExplicitVisibility(D, computation)) { | |||
712 | LV.mergeVisibility(*Vis, true); | |||
713 | } else { | |||
714 | // If we're declared in a namespace with a visibility attribute, | |||
715 | // use that namespace's visibility, and it still counts as explicit. | |||
716 | for (const DeclContext *DC = D->getDeclContext(); | |||
717 | !isa<TranslationUnitDecl>(DC); | |||
718 | DC = DC->getParent()) { | |||
719 | const auto *ND = dyn_cast<NamespaceDecl>(DC); | |||
720 | if (!ND) continue; | |||
721 | if (Optional<Visibility> Vis = getExplicitVisibility(ND, computation)) { | |||
722 | LV.mergeVisibility(*Vis, true); | |||
723 | break; | |||
724 | } | |||
725 | } | |||
726 | } | |||
727 | ||||
728 | // Add in global settings if the above didn't give us direct visibility. | |||
729 | if (!LV.isVisibilityExplicit()) { | |||
730 | // Use global type/value visibility as appropriate. | |||
731 | Visibility globalVisibility = | |||
732 | computation.isValueVisibility() | |||
733 | ? Context.getLangOpts().getValueVisibilityMode() | |||
734 | : Context.getLangOpts().getTypeVisibilityMode(); | |||
735 | LV.mergeVisibility(globalVisibility, /*explicit*/ false); | |||
736 | ||||
737 | // If we're paying attention to global visibility, apply | |||
738 | // -finline-visibility-hidden if this is an inline method. | |||
739 | if (useInlineVisibilityHidden(D)) | |||
740 | LV.mergeVisibility(HiddenVisibility, /*visibilityExplicit=*/false); | |||
741 | } | |||
742 | } | |||
743 | ||||
744 | // C++ [basic.link]p4: | |||
745 | ||||
746 | // A name having namespace scope that has not been given internal linkage | |||
747 | // above and that is the name of | |||
748 | // [...bullets...] | |||
749 | // has its linkage determined as follows: | |||
750 | // - if the enclosing namespace has internal linkage, the name has | |||
751 | // internal linkage; [handled above] | |||
752 | // - otherwise, if the declaration of the name is attached to a named | |||
753 | // module and is not exported, the name has module linkage; | |||
754 | // - otherwise, the name has external linkage. | |||
755 | // LV is currently set up to handle the last two bullets. | |||
756 | // | |||
757 | // The bullets are: | |||
758 | ||||
759 | // - a variable; or | |||
760 | if (const auto *Var = dyn_cast<VarDecl>(D)) { | |||
761 | // GCC applies the following optimization to variables and static | |||
762 | // data members, but not to functions: | |||
763 | // | |||
764 | // Modify the variable's LV by the LV of its type unless this is | |||
765 | // C or extern "C". This follows from [basic.link]p9: | |||
766 | // A type without linkage shall not be used as the type of a | |||
767 | // variable or function with external linkage unless | |||
768 | // - the entity has C language linkage, or | |||
769 | // - the entity is declared within an unnamed namespace, or | |||
770 | // - the entity is not used or is defined in the same | |||
771 | // translation unit. | |||
772 | // and [basic.link]p10: | |||
773 | // ...the types specified by all declarations referring to a | |||
774 | // given variable or function shall be identical... | |||
775 | // C does not have an equivalent rule. | |||
776 | // | |||
777 | // Ignore this if we've got an explicit attribute; the user | |||
778 | // probably knows what they're doing. | |||
779 | // | |||
780 | // Note that we don't want to make the variable non-external | |||
781 | // because of this, but unique-external linkage suits us. | |||
782 | if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Var) && | |||
783 | !IgnoreVarTypeLinkage) { | |||
784 | LinkageInfo TypeLV = getLVForType(*Var->getType(), computation); | |||
785 | if (!isExternallyVisible(TypeLV.getLinkage())) | |||
786 | return LinkageInfo::uniqueExternal(); | |||
787 | if (!LV.isVisibilityExplicit()) | |||
788 | LV.mergeVisibility(TypeLV); | |||
789 | } | |||
790 | ||||
791 | if (Var->getStorageClass() == SC_PrivateExtern) | |||
792 | LV.mergeVisibility(HiddenVisibility, true); | |||
793 | ||||
794 | // Note that Sema::MergeVarDecl already takes care of implementing | |||
795 | // C99 6.2.2p4 and propagating the visibility attribute, so we don't have | |||
796 | // to do it here. | |||
797 | ||||
798 | // As per function and class template specializations (below), | |||
799 | // consider LV for the template and template arguments. We're at file | |||
800 | // scope, so we do not need to worry about nested specializations. | |||
801 | if (const auto *spec = dyn_cast<VarTemplateSpecializationDecl>(Var)) { | |||
802 | mergeTemplateLV(LV, spec, computation); | |||
803 | } | |||
804 | ||||
805 | // - a function; or | |||
806 | } else if (const auto *Function = dyn_cast<FunctionDecl>(D)) { | |||
807 | // In theory, we can modify the function's LV by the LV of its | |||
808 | // type unless it has C linkage (see comment above about variables | |||
809 | // for justification). In practice, GCC doesn't do this, so it's | |||
810 | // just too painful to make work. | |||
811 | ||||
812 | if (Function->getStorageClass() == SC_PrivateExtern) | |||
813 | LV.mergeVisibility(HiddenVisibility, true); | |||
814 | ||||
815 | // Note that Sema::MergeCompatibleFunctionDecls already takes care of | |||
816 | // merging storage classes and visibility attributes, so we don't have to | |||
817 | // look at previous decls in here. | |||
818 | ||||
819 | // In C++, then if the type of the function uses a type with | |||
820 | // unique-external linkage, it's not legally usable from outside | |||
821 | // this translation unit. However, we should use the C linkage | |||
822 | // rules instead for extern "C" declarations. | |||
823 | if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Function)) { | |||
824 | // Only look at the type-as-written. Otherwise, deducing the return type | |||
825 | // of a function could change its linkage. | |||
826 | QualType TypeAsWritten = Function->getType(); | |||
827 | if (TypeSourceInfo *TSI = Function->getTypeSourceInfo()) | |||
828 | TypeAsWritten = TSI->getType(); | |||
829 | if (!isExternallyVisible(TypeAsWritten->getLinkage())) | |||
830 | return LinkageInfo::uniqueExternal(); | |||
831 | } | |||
832 | ||||
833 | // Consider LV from the template and the template arguments. | |||
834 | // We're at file scope, so we do not need to worry about nested | |||
835 | // specializations. | |||
836 | if (FunctionTemplateSpecializationInfo *specInfo | |||
837 | = Function->getTemplateSpecializationInfo()) { | |||
838 | mergeTemplateLV(LV, Function, specInfo, computation); | |||
839 | } | |||
840 | ||||
841 | // - a named class (Clause 9), or an unnamed class defined in a | |||
842 | // typedef declaration in which the class has the typedef name | |||
843 | // for linkage purposes (7.1.3); or | |||
844 | // - a named enumeration (7.2), or an unnamed enumeration | |||
845 | // defined in a typedef declaration in which the enumeration | |||
846 | // has the typedef name for linkage purposes (7.1.3); or | |||
847 | } else if (const auto *Tag = dyn_cast<TagDecl>(D)) { | |||
848 | // Unnamed tags have no linkage. | |||
849 | if (!Tag->hasNameForLinkage()) | |||
850 | return LinkageInfo::none(); | |||
851 | ||||
852 | // If this is a class template specialization, consider the | |||
853 | // linkage of the template and template arguments. We're at file | |||
854 | // scope, so we do not need to worry about nested specializations. | |||
855 | if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(Tag)) { | |||
856 | mergeTemplateLV(LV, spec, computation); | |||
857 | } | |||
858 | ||||
859 | // FIXME: This is not part of the C++ standard any more. | |||
860 | // - an enumerator belonging to an enumeration with external linkage; or | |||
861 | } else if (isa<EnumConstantDecl>(D)) { | |||
862 | LinkageInfo EnumLV = getLVForDecl(cast<NamedDecl>(D->getDeclContext()), | |||
863 | computation); | |||
864 | if (!isExternalFormalLinkage(EnumLV.getLinkage())) | |||
865 | return LinkageInfo::none(); | |||
866 | LV.merge(EnumLV); | |||
867 | ||||
868 | // - a template | |||
869 | } else if (const auto *temp = dyn_cast<TemplateDecl>(D)) { | |||
870 | bool considerVisibility = !hasExplicitVisibilityAlready(computation); | |||
871 | LinkageInfo tempLV = | |||
872 | getLVForTemplateParameterList(temp->getTemplateParameters(), computation); | |||
873 | LV.mergeMaybeWithVisibility(tempLV, considerVisibility); | |||
874 | ||||
875 | // An unnamed namespace or a namespace declared directly or indirectly | |||
876 | // within an unnamed namespace has internal linkage. All other namespaces | |||
877 | // have external linkage. | |||
878 | // | |||
879 | // We handled names in anonymous namespaces above. | |||
880 | } else if (isa<NamespaceDecl>(D)) { | |||
881 | return LV; | |||
882 | ||||
883 | // By extension, we assign external linkage to Objective-C | |||
884 | // interfaces. | |||
885 | } else if (isa<ObjCInterfaceDecl>(D)) { | |||
886 | // fallout | |||
887 | ||||
888 | } else if (auto *TD = dyn_cast<TypedefNameDecl>(D)) { | |||
889 | // A typedef declaration has linkage if it gives a type a name for | |||
890 | // linkage purposes. | |||
891 | if (!TD->getAnonDeclWithTypedefName(/*AnyRedecl*/true)) | |||
892 | return LinkageInfo::none(); | |||
893 | ||||
894 | // Everything not covered here has no linkage. | |||
895 | } else { | |||
896 | return LinkageInfo::none(); | |||
897 | } | |||
898 | ||||
899 | // If we ended up with non-externally-visible linkage, visibility should | |||
900 | // always be default. | |||
901 | if (!isExternallyVisible(LV.getLinkage())) | |||
902 | return LinkageInfo(LV.getLinkage(), DefaultVisibility, false); | |||
903 | ||||
904 | return LV; | |||
905 | } | |||
906 | ||||
907 | LinkageInfo | |||
908 | LinkageComputer::getLVForClassMember(const NamedDecl *D, | |||
909 | LVComputationKind computation, | |||
910 | bool IgnoreVarTypeLinkage) { | |||
911 | // Only certain class members have linkage. Note that fields don't | |||
912 | // really have linkage, but it's convenient to say they do for the | |||
913 | // purposes of calculating linkage of pointer-to-data-member | |||
914 | // template arguments. | |||
915 | // | |||
916 | // Templates also don't officially have linkage, but since we ignore | |||
917 | // the C++ standard and look at template arguments when determining | |||
918 | // linkage and visibility of a template specialization, we might hit | |||
919 | // a template template argument that way. If we do, we need to | |||
920 | // consider its linkage. | |||
921 | if (!(isa<CXXMethodDecl>(D) || | |||
922 | isa<VarDecl>(D) || | |||
923 | isa<FieldDecl>(D) || | |||
924 | isa<IndirectFieldDecl>(D) || | |||
925 | isa<TagDecl>(D) || | |||
926 | isa<TemplateDecl>(D))) | |||
927 | return LinkageInfo::none(); | |||
928 | ||||
929 | LinkageInfo LV; | |||
930 | ||||
931 | // If we have an explicit visibility attribute, merge that in. | |||
932 | if (!hasExplicitVisibilityAlready(computation)) { | |||
933 | if (Optional<Visibility> Vis = getExplicitVisibility(D, computation)) | |||
934 | LV.mergeVisibility(*Vis, true); | |||
935 | // If we're paying attention to global visibility, apply | |||
936 | // -finline-visibility-hidden if this is an inline method. | |||
937 | // | |||
938 | // Note that we do this before merging information about | |||
939 | // the class visibility. | |||
940 | if (!LV.isVisibilityExplicit() && useInlineVisibilityHidden(D)) | |||
941 | LV.mergeVisibility(HiddenVisibility, /*visibilityExplicit=*/false); | |||
942 | } | |||
943 | ||||
944 | // If this class member has an explicit visibility attribute, the only | |||
945 | // thing that can change its visibility is the template arguments, so | |||
946 | // only look for them when processing the class. | |||
947 | LVComputationKind classComputation = computation; | |||
948 | if (LV.isVisibilityExplicit()) | |||
949 | classComputation = withExplicitVisibilityAlready(computation); | |||
950 | ||||
951 | LinkageInfo classLV = | |||
952 | getLVForDecl(cast<RecordDecl>(D->getDeclContext()), classComputation); | |||
953 | // The member has the same linkage as the class. If that's not externally | |||
954 | // visible, we don't need to compute anything about the linkage. | |||
955 | // FIXME: If we're only computing linkage, can we bail out here? | |||
956 | if (!isExternallyVisible(classLV.getLinkage())) | |||
957 | return classLV; | |||
958 | ||||
959 | ||||
960 | // Otherwise, don't merge in classLV yet, because in certain cases | |||
961 | // we need to completely ignore the visibility from it. | |||
962 | ||||
963 | // Specifically, if this decl exists and has an explicit attribute. | |||
964 | const NamedDecl *explicitSpecSuppressor = nullptr; | |||
965 | ||||
966 | if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) { | |||
967 | // Only look at the type-as-written. Otherwise, deducing the return type | |||
968 | // of a function could change its linkage. | |||
969 | QualType TypeAsWritten = MD->getType(); | |||
970 | if (TypeSourceInfo *TSI = MD->getTypeSourceInfo()) | |||
971 | TypeAsWritten = TSI->getType(); | |||
972 | if (!isExternallyVisible(TypeAsWritten->getLinkage())) | |||
973 | return LinkageInfo::uniqueExternal(); | |||
974 | ||||
975 | // If this is a method template specialization, use the linkage for | |||
976 | // the template parameters and arguments. | |||
977 | if (FunctionTemplateSpecializationInfo *spec | |||
978 | = MD->getTemplateSpecializationInfo()) { | |||
979 | mergeTemplateLV(LV, MD, spec, computation); | |||
980 | if (spec->isExplicitSpecialization()) { | |||
981 | explicitSpecSuppressor = MD; | |||
982 | } else if (isExplicitMemberSpecialization(spec->getTemplate())) { | |||
983 | explicitSpecSuppressor = spec->getTemplate()->getTemplatedDecl(); | |||
984 | } | |||
985 | } else if (isExplicitMemberSpecialization(MD)) { | |||
986 | explicitSpecSuppressor = MD; | |||
987 | } | |||
988 | ||||
989 | } else if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) { | |||
990 | if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(RD)) { | |||
991 | mergeTemplateLV(LV, spec, computation); | |||
992 | if (spec->isExplicitSpecialization()) { | |||
993 | explicitSpecSuppressor = spec; | |||
994 | } else { | |||
995 | const ClassTemplateDecl *temp = spec->getSpecializedTemplate(); | |||
996 | if (isExplicitMemberSpecialization(temp)) { | |||
997 | explicitSpecSuppressor = temp->getTemplatedDecl(); | |||
998 | } | |||
999 | } | |||
1000 | } else if (isExplicitMemberSpecialization(RD)) { | |||
1001 | explicitSpecSuppressor = RD; | |||
1002 | } | |||
1003 | ||||
1004 | // Static data members. | |||
1005 | } else if (const auto *VD = dyn_cast<VarDecl>(D)) { | |||
1006 | if (const auto *spec = dyn_cast<VarTemplateSpecializationDecl>(VD)) | |||
1007 | mergeTemplateLV(LV, spec, computation); | |||
1008 | ||||
1009 | // Modify the variable's linkage by its type, but ignore the | |||
1010 | // type's visibility unless it's a definition. | |||
1011 | if (!IgnoreVarTypeLinkage) { | |||
1012 | LinkageInfo typeLV = getLVForType(*VD->getType(), computation); | |||
1013 | // FIXME: If the type's linkage is not externally visible, we can | |||
1014 | // give this static data member UniqueExternalLinkage. | |||
1015 | if (!LV.isVisibilityExplicit() && !classLV.isVisibilityExplicit()) | |||
1016 | LV.mergeVisibility(typeLV); | |||
1017 | LV.mergeExternalVisibility(typeLV); | |||
1018 | } | |||
1019 | ||||
1020 | if (isExplicitMemberSpecialization(VD)) { | |||
1021 | explicitSpecSuppressor = VD; | |||
1022 | } | |||
1023 | ||||
1024 | // Template members. | |||
1025 | } else if (const auto *temp = dyn_cast<TemplateDecl>(D)) { | |||
1026 | bool considerVisibility = | |||
1027 | (!LV.isVisibilityExplicit() && | |||
1028 | !classLV.isVisibilityExplicit() && | |||
1029 | !hasExplicitVisibilityAlready(computation)); | |||
1030 | LinkageInfo tempLV = | |||
1031 | getLVForTemplateParameterList(temp->getTemplateParameters(), computation); | |||
1032 | LV.mergeMaybeWithVisibility(tempLV, considerVisibility); | |||
1033 | ||||
1034 | if (const auto *redeclTemp = dyn_cast<RedeclarableTemplateDecl>(temp)) { | |||
1035 | if (isExplicitMemberSpecialization(redeclTemp)) { | |||
1036 | explicitSpecSuppressor = temp->getTemplatedDecl(); | |||
1037 | } | |||
1038 | } | |||
1039 | } | |||
1040 | ||||
1041 | // We should never be looking for an attribute directly on a template. | |||
1042 | assert(!explicitSpecSuppressor || !isa<TemplateDecl>(explicitSpecSuppressor))((!explicitSpecSuppressor || !isa<TemplateDecl>(explicitSpecSuppressor )) ? static_cast<void> (0) : __assert_fail ("!explicitSpecSuppressor || !isa<TemplateDecl>(explicitSpecSuppressor)" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1042, __PRETTY_FUNCTION__)); | |||
1043 | ||||
1044 | // If this member is an explicit member specialization, and it has | |||
1045 | // an explicit attribute, ignore visibility from the parent. | |||
1046 | bool considerClassVisibility = true; | |||
1047 | if (explicitSpecSuppressor && | |||
1048 | // optimization: hasDVA() is true only with explicit visibility. | |||
1049 | LV.isVisibilityExplicit() && | |||
1050 | classLV.getVisibility() != DefaultVisibility && | |||
1051 | hasDirectVisibilityAttribute(explicitSpecSuppressor, computation)) { | |||
1052 | considerClassVisibility = false; | |||
1053 | } | |||
1054 | ||||
1055 | // Finally, merge in information from the class. | |||
1056 | LV.mergeMaybeWithVisibility(classLV, considerClassVisibility); | |||
1057 | return LV; | |||
1058 | } | |||
1059 | ||||
1060 | void NamedDecl::anchor() {} | |||
1061 | ||||
1062 | bool NamedDecl::isLinkageValid() const { | |||
1063 | if (!hasCachedLinkage()) | |||
1064 | return true; | |||
1065 | ||||
1066 | Linkage L = LinkageComputer{} | |||
1067 | .computeLVForDecl(this, LVComputationKind::forLinkageOnly()) | |||
1068 | .getLinkage(); | |||
1069 | return L == getCachedLinkage(); | |||
1070 | } | |||
1071 | ||||
1072 | ObjCStringFormatFamily NamedDecl::getObjCFStringFormattingFamily() const { | |||
1073 | StringRef name = getName(); | |||
1074 | if (name.empty()) return SFF_None; | |||
1075 | ||||
1076 | if (name.front() == 'C') | |||
1077 | if (name == "CFStringCreateWithFormat" || | |||
1078 | name == "CFStringCreateWithFormatAndArguments" || | |||
1079 | name == "CFStringAppendFormat" || | |||
1080 | name == "CFStringAppendFormatAndArguments") | |||
1081 | return SFF_CFString; | |||
1082 | return SFF_None; | |||
1083 | } | |||
1084 | ||||
1085 | Linkage NamedDecl::getLinkageInternal() const { | |||
1086 | // We don't care about visibility here, so ask for the cheapest | |||
1087 | // possible visibility analysis. | |||
1088 | return LinkageComputer{} | |||
1089 | .getLVForDecl(this, LVComputationKind::forLinkageOnly()) | |||
1090 | .getLinkage(); | |||
1091 | } | |||
1092 | ||||
1093 | LinkageInfo NamedDecl::getLinkageAndVisibility() const { | |||
1094 | return LinkageComputer{}.getDeclLinkageAndVisibility(this); | |||
1095 | } | |||
1096 | ||||
1097 | static Optional<Visibility> | |||
1098 | getExplicitVisibilityAux(const NamedDecl *ND, | |||
1099 | NamedDecl::ExplicitVisibilityKind kind, | |||
1100 | bool IsMostRecent) { | |||
1101 | assert(!IsMostRecent || ND == ND->getMostRecentDecl())((!IsMostRecent || ND == ND->getMostRecentDecl()) ? static_cast <void> (0) : __assert_fail ("!IsMostRecent || ND == ND->getMostRecentDecl()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1101, __PRETTY_FUNCTION__)); | |||
1102 | ||||
1103 | // Check the declaration itself first. | |||
1104 | if (Optional<Visibility> V = getVisibilityOf(ND, kind)) | |||
1105 | return V; | |||
1106 | ||||
1107 | // If this is a member class of a specialization of a class template | |||
1108 | // and the corresponding decl has explicit visibility, use that. | |||
1109 | if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) { | |||
1110 | CXXRecordDecl *InstantiatedFrom = RD->getInstantiatedFromMemberClass(); | |||
1111 | if (InstantiatedFrom) | |||
1112 | return getVisibilityOf(InstantiatedFrom, kind); | |||
1113 | } | |||
1114 | ||||
1115 | // If there wasn't explicit visibility there, and this is a | |||
1116 | // specialization of a class template, check for visibility | |||
1117 | // on the pattern. | |||
1118 | if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(ND)) { | |||
1119 | // Walk all the template decl till this point to see if there are | |||
1120 | // explicit visibility attributes. | |||
1121 | const auto *TD = spec->getSpecializedTemplate()->getTemplatedDecl(); | |||
1122 | while (TD != nullptr) { | |||
1123 | auto Vis = getVisibilityOf(TD, kind); | |||
1124 | if (Vis != None) | |||
1125 | return Vis; | |||
1126 | TD = TD->getPreviousDecl(); | |||
1127 | } | |||
1128 | return None; | |||
1129 | } | |||
1130 | ||||
1131 | // Use the most recent declaration. | |||
1132 | if (!IsMostRecent && !isa<NamespaceDecl>(ND)) { | |||
1133 | const NamedDecl *MostRecent = ND->getMostRecentDecl(); | |||
1134 | if (MostRecent != ND) | |||
1135 | return getExplicitVisibilityAux(MostRecent, kind, true); | |||
1136 | } | |||
1137 | ||||
1138 | if (const auto *Var = dyn_cast<VarDecl>(ND)) { | |||
1139 | if (Var->isStaticDataMember()) { | |||
1140 | VarDecl *InstantiatedFrom = Var->getInstantiatedFromStaticDataMember(); | |||
1141 | if (InstantiatedFrom) | |||
1142 | return getVisibilityOf(InstantiatedFrom, kind); | |||
1143 | } | |||
1144 | ||||
1145 | if (const auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Var)) | |||
1146 | return getVisibilityOf(VTSD->getSpecializedTemplate()->getTemplatedDecl(), | |||
1147 | kind); | |||
1148 | ||||
1149 | return None; | |||
1150 | } | |||
1151 | // Also handle function template specializations. | |||
1152 | if (const auto *fn = dyn_cast<FunctionDecl>(ND)) { | |||
1153 | // If the function is a specialization of a template with an | |||
1154 | // explicit visibility attribute, use that. | |||
1155 | if (FunctionTemplateSpecializationInfo *templateInfo | |||
1156 | = fn->getTemplateSpecializationInfo()) | |||
1157 | return getVisibilityOf(templateInfo->getTemplate()->getTemplatedDecl(), | |||
1158 | kind); | |||
1159 | ||||
1160 | // If the function is a member of a specialization of a class template | |||
1161 | // and the corresponding decl has explicit visibility, use that. | |||
1162 | FunctionDecl *InstantiatedFrom = fn->getInstantiatedFromMemberFunction(); | |||
1163 | if (InstantiatedFrom) | |||
1164 | return getVisibilityOf(InstantiatedFrom, kind); | |||
1165 | ||||
1166 | return None; | |||
1167 | } | |||
1168 | ||||
1169 | // The visibility of a template is stored in the templated decl. | |||
1170 | if (const auto *TD = dyn_cast<TemplateDecl>(ND)) | |||
1171 | return getVisibilityOf(TD->getTemplatedDecl(), kind); | |||
1172 | ||||
1173 | return None; | |||
1174 | } | |||
1175 | ||||
1176 | Optional<Visibility> | |||
1177 | NamedDecl::getExplicitVisibility(ExplicitVisibilityKind kind) const { | |||
1178 | return getExplicitVisibilityAux(this, kind, false); | |||
1179 | } | |||
1180 | ||||
1181 | LinkageInfo LinkageComputer::getLVForClosure(const DeclContext *DC, | |||
1182 | Decl *ContextDecl, | |||
1183 | LVComputationKind computation) { | |||
1184 | // This lambda has its linkage/visibility determined by its owner. | |||
1185 | const NamedDecl *Owner; | |||
1186 | if (!ContextDecl) | |||
1187 | Owner = dyn_cast<NamedDecl>(DC); | |||
1188 | else if (isa<ParmVarDecl>(ContextDecl)) | |||
1189 | Owner = | |||
1190 | dyn_cast<NamedDecl>(ContextDecl->getDeclContext()->getRedeclContext()); | |||
1191 | else | |||
1192 | Owner = cast<NamedDecl>(ContextDecl); | |||
1193 | ||||
1194 | if (!Owner) | |||
1195 | return LinkageInfo::none(); | |||
1196 | ||||
1197 | // If the owner has a deduced type, we need to skip querying the linkage and | |||
1198 | // visibility of that type, because it might involve this closure type. The | |||
1199 | // only effect of this is that we might give a lambda VisibleNoLinkage rather | |||
1200 | // than NoLinkage when we don't strictly need to, which is benign. | |||
1201 | auto *VD = dyn_cast<VarDecl>(Owner); | |||
1202 | LinkageInfo OwnerLV = | |||
1203 | VD && VD->getType()->getContainedDeducedType() | |||
1204 | ? computeLVForDecl(Owner, computation, /*IgnoreVarTypeLinkage*/true) | |||
1205 | : getLVForDecl(Owner, computation); | |||
1206 | ||||
1207 | // A lambda never formally has linkage. But if the owner is externally | |||
1208 | // visible, then the lambda is too. We apply the same rules to blocks. | |||
1209 | if (!isExternallyVisible(OwnerLV.getLinkage())) | |||
1210 | return LinkageInfo::none(); | |||
1211 | return LinkageInfo(VisibleNoLinkage, OwnerLV.getVisibility(), | |||
1212 | OwnerLV.isVisibilityExplicit()); | |||
1213 | } | |||
1214 | ||||
1215 | LinkageInfo LinkageComputer::getLVForLocalDecl(const NamedDecl *D, | |||
1216 | LVComputationKind computation) { | |||
1217 | if (const auto *Function = dyn_cast<FunctionDecl>(D)) { | |||
1218 | if (Function->isInAnonymousNamespace() && | |||
1219 | !isFirstInExternCContext(Function)) | |||
1220 | return getInternalLinkageFor(Function); | |||
1221 | ||||
1222 | // This is a "void f();" which got merged with a file static. | |||
1223 | if (Function->getCanonicalDecl()->getStorageClass() == SC_Static) | |||
1224 | return getInternalLinkageFor(Function); | |||
1225 | ||||
1226 | LinkageInfo LV; | |||
1227 | if (!hasExplicitVisibilityAlready(computation)) { | |||
1228 | if (Optional<Visibility> Vis = | |||
1229 | getExplicitVisibility(Function, computation)) | |||
1230 | LV.mergeVisibility(*Vis, true); | |||
1231 | } | |||
1232 | ||||
1233 | // Note that Sema::MergeCompatibleFunctionDecls already takes care of | |||
1234 | // merging storage classes and visibility attributes, so we don't have to | |||
1235 | // look at previous decls in here. | |||
1236 | ||||
1237 | return LV; | |||
1238 | } | |||
1239 | ||||
1240 | if (const auto *Var = dyn_cast<VarDecl>(D)) { | |||
1241 | if (Var->hasExternalStorage()) { | |||
1242 | if (Var->isInAnonymousNamespace() && !isFirstInExternCContext(Var)) | |||
1243 | return getInternalLinkageFor(Var); | |||
1244 | ||||
1245 | LinkageInfo LV; | |||
1246 | if (Var->getStorageClass() == SC_PrivateExtern) | |||
1247 | LV.mergeVisibility(HiddenVisibility, true); | |||
1248 | else if (!hasExplicitVisibilityAlready(computation)) { | |||
1249 | if (Optional<Visibility> Vis = getExplicitVisibility(Var, computation)) | |||
1250 | LV.mergeVisibility(*Vis, true); | |||
1251 | } | |||
1252 | ||||
1253 | if (const VarDecl *Prev = Var->getPreviousDecl()) { | |||
1254 | LinkageInfo PrevLV = getLVForDecl(Prev, computation); | |||
1255 | if (PrevLV.getLinkage()) | |||
1256 | LV.setLinkage(PrevLV.getLinkage()); | |||
1257 | LV.mergeVisibility(PrevLV); | |||
1258 | } | |||
1259 | ||||
1260 | return LV; | |||
1261 | } | |||
1262 | ||||
1263 | if (!Var->isStaticLocal()) | |||
1264 | return LinkageInfo::none(); | |||
1265 | } | |||
1266 | ||||
1267 | ASTContext &Context = D->getASTContext(); | |||
1268 | if (!Context.getLangOpts().CPlusPlus) | |||
1269 | return LinkageInfo::none(); | |||
1270 | ||||
1271 | const Decl *OuterD = getOutermostFuncOrBlockContext(D); | |||
1272 | if (!OuterD || OuterD->isInvalidDecl()) | |||
1273 | return LinkageInfo::none(); | |||
1274 | ||||
1275 | LinkageInfo LV; | |||
1276 | if (const auto *BD = dyn_cast<BlockDecl>(OuterD)) { | |||
1277 | if (!BD->getBlockManglingNumber()) | |||
1278 | return LinkageInfo::none(); | |||
1279 | ||||
1280 | LV = getLVForClosure(BD->getDeclContext()->getRedeclContext(), | |||
1281 | BD->getBlockManglingContextDecl(), computation); | |||
1282 | } else { | |||
1283 | const auto *FD = cast<FunctionDecl>(OuterD); | |||
1284 | if (!FD->isInlined() && | |||
1285 | !isTemplateInstantiation(FD->getTemplateSpecializationKind())) | |||
1286 | return LinkageInfo::none(); | |||
1287 | ||||
1288 | // If a function is hidden by -fvisibility-inlines-hidden option and | |||
1289 | // is not explicitly attributed as a hidden function, | |||
1290 | // we should not make static local variables in the function hidden. | |||
1291 | LV = getLVForDecl(FD, computation); | |||
1292 | if (isa<VarDecl>(D) && useInlineVisibilityHidden(FD) && | |||
1293 | !LV.isVisibilityExplicit()) { | |||
1294 | assert(cast<VarDecl>(D)->isStaticLocal())((cast<VarDecl>(D)->isStaticLocal()) ? static_cast< void> (0) : __assert_fail ("cast<VarDecl>(D)->isStaticLocal()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1294, __PRETTY_FUNCTION__)); | |||
1295 | // If this was an implicitly hidden inline method, check again for | |||
1296 | // explicit visibility on the parent class, and use that for static locals | |||
1297 | // if present. | |||
1298 | if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) | |||
1299 | LV = getLVForDecl(MD->getParent(), computation); | |||
1300 | if (!LV.isVisibilityExplicit()) { | |||
1301 | Visibility globalVisibility = | |||
1302 | computation.isValueVisibility() | |||
1303 | ? Context.getLangOpts().getValueVisibilityMode() | |||
1304 | : Context.getLangOpts().getTypeVisibilityMode(); | |||
1305 | return LinkageInfo(VisibleNoLinkage, globalVisibility, | |||
1306 | /*visibilityExplicit=*/false); | |||
1307 | } | |||
1308 | } | |||
1309 | } | |||
1310 | if (!isExternallyVisible(LV.getLinkage())) | |||
1311 | return LinkageInfo::none(); | |||
1312 | return LinkageInfo(VisibleNoLinkage, LV.getVisibility(), | |||
1313 | LV.isVisibilityExplicit()); | |||
1314 | } | |||
1315 | ||||
1316 | static inline const CXXRecordDecl* | |||
1317 | getOutermostEnclosingLambda(const CXXRecordDecl *Record) { | |||
1318 | const CXXRecordDecl *Ret = Record; | |||
1319 | while (Record && Record->isLambda()) { | |||
1320 | Ret = Record; | |||
1321 | if (!Record->getParent()) break; | |||
1322 | // Get the Containing Class of this Lambda Class | |||
1323 | Record = dyn_cast_or_null<CXXRecordDecl>( | |||
1324 | Record->getParent()->getParent()); | |||
1325 | } | |||
1326 | return Ret; | |||
1327 | } | |||
1328 | ||||
1329 | LinkageInfo LinkageComputer::computeLVForDecl(const NamedDecl *D, | |||
1330 | LVComputationKind computation, | |||
1331 | bool IgnoreVarTypeLinkage) { | |||
1332 | // Internal_linkage attribute overrides other considerations. | |||
1333 | if (D->hasAttr<InternalLinkageAttr>()) | |||
1334 | return getInternalLinkageFor(D); | |||
1335 | ||||
1336 | // Objective-C: treat all Objective-C declarations as having external | |||
1337 | // linkage. | |||
1338 | switch (D->getKind()) { | |||
1339 | default: | |||
1340 | break; | |||
1341 | ||||
1342 | // Per C++ [basic.link]p2, only the names of objects, references, | |||
1343 | // functions, types, templates, namespaces, and values ever have linkage. | |||
1344 | // | |||
1345 | // Note that the name of a typedef, namespace alias, using declaration, | |||
1346 | // and so on are not the name of the corresponding type, namespace, or | |||
1347 | // declaration, so they do *not* have linkage. | |||
1348 | case Decl::ImplicitParam: | |||
1349 | case Decl::Label: | |||
1350 | case Decl::NamespaceAlias: | |||
1351 | case Decl::ParmVar: | |||
1352 | case Decl::Using: | |||
1353 | case Decl::UsingShadow: | |||
1354 | case Decl::UsingDirective: | |||
1355 | return LinkageInfo::none(); | |||
1356 | ||||
1357 | case Decl::EnumConstant: | |||
1358 | // C++ [basic.link]p4: an enumerator has the linkage of its enumeration. | |||
1359 | if (D->getASTContext().getLangOpts().CPlusPlus) | |||
1360 | return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation); | |||
1361 | return LinkageInfo::visible_none(); | |||
1362 | ||||
1363 | case Decl::Typedef: | |||
1364 | case Decl::TypeAlias: | |||
1365 | // A typedef declaration has linkage if it gives a type a name for | |||
1366 | // linkage purposes. | |||
1367 | if (!cast<TypedefNameDecl>(D) | |||
1368 | ->getAnonDeclWithTypedefName(/*AnyRedecl*/true)) | |||
1369 | return LinkageInfo::none(); | |||
1370 | break; | |||
1371 | ||||
1372 | case Decl::TemplateTemplateParm: // count these as external | |||
1373 | case Decl::NonTypeTemplateParm: | |||
1374 | case Decl::ObjCAtDefsField: | |||
1375 | case Decl::ObjCCategory: | |||
1376 | case Decl::ObjCCategoryImpl: | |||
1377 | case Decl::ObjCCompatibleAlias: | |||
1378 | case Decl::ObjCImplementation: | |||
1379 | case Decl::ObjCMethod: | |||
1380 | case Decl::ObjCProperty: | |||
1381 | case Decl::ObjCPropertyImpl: | |||
1382 | case Decl::ObjCProtocol: | |||
1383 | return getExternalLinkageFor(D); | |||
1384 | ||||
1385 | case Decl::CXXRecord: { | |||
1386 | const auto *Record = cast<CXXRecordDecl>(D); | |||
1387 | if (Record->isLambda()) { | |||
1388 | if (!Record->getLambdaManglingNumber()) { | |||
1389 | // This lambda has no mangling number, so it's internal. | |||
1390 | return getInternalLinkageFor(D); | |||
1391 | } | |||
1392 | ||||
1393 | // This lambda has its linkage/visibility determined: | |||
1394 | // - either by the outermost lambda if that lambda has no mangling | |||
1395 | // number. | |||
1396 | // - or by the parent of the outer most lambda | |||
1397 | // This prevents infinite recursion in settings such as nested lambdas | |||
1398 | // used in NSDMI's, for e.g. | |||
1399 | // struct L { | |||
1400 | // int t{}; | |||
1401 | // int t2 = ([](int a) { return [](int b) { return b; };})(t)(t); | |||
1402 | // }; | |||
1403 | const CXXRecordDecl *OuterMostLambda = | |||
1404 | getOutermostEnclosingLambda(Record); | |||
1405 | if (!OuterMostLambda->getLambdaManglingNumber()) | |||
1406 | return getInternalLinkageFor(D); | |||
1407 | ||||
1408 | return getLVForClosure( | |||
1409 | OuterMostLambda->getDeclContext()->getRedeclContext(), | |||
1410 | OuterMostLambda->getLambdaContextDecl(), computation); | |||
1411 | } | |||
1412 | ||||
1413 | break; | |||
1414 | } | |||
1415 | } | |||
1416 | ||||
1417 | // Handle linkage for namespace-scope names. | |||
1418 | if (D->getDeclContext()->getRedeclContext()->isFileContext()) | |||
1419 | return getLVForNamespaceScopeDecl(D, computation, IgnoreVarTypeLinkage); | |||
1420 | ||||
1421 | // C++ [basic.link]p5: | |||
1422 | // In addition, a member function, static data member, a named | |||
1423 | // class or enumeration of class scope, or an unnamed class or | |||
1424 | // enumeration defined in a class-scope typedef declaration such | |||
1425 | // that the class or enumeration has the typedef name for linkage | |||
1426 | // purposes (7.1.3), has external linkage if the name of the class | |||
1427 | // has external linkage. | |||
1428 | if (D->getDeclContext()->isRecord()) | |||
1429 | return getLVForClassMember(D, computation, IgnoreVarTypeLinkage); | |||
1430 | ||||
1431 | // C++ [basic.link]p6: | |||
1432 | // The name of a function declared in block scope and the name of | |||
1433 | // an object declared by a block scope extern declaration have | |||
1434 | // linkage. If there is a visible declaration of an entity with | |||
1435 | // linkage having the same name and type, ignoring entities | |||
1436 | // declared outside the innermost enclosing namespace scope, the | |||
1437 | // block scope declaration declares that same entity and receives | |||
1438 | // the linkage of the previous declaration. If there is more than | |||
1439 | // one such matching entity, the program is ill-formed. Otherwise, | |||
1440 | // if no matching entity is found, the block scope entity receives | |||
1441 | // external linkage. | |||
1442 | if (D->getDeclContext()->isFunctionOrMethod()) | |||
1443 | return getLVForLocalDecl(D, computation); | |||
1444 | ||||
1445 | // C++ [basic.link]p6: | |||
1446 | // Names not covered by these rules have no linkage. | |||
1447 | return LinkageInfo::none(); | |||
1448 | } | |||
1449 | ||||
1450 | /// getLVForDecl - Get the linkage and visibility for the given declaration. | |||
1451 | LinkageInfo LinkageComputer::getLVForDecl(const NamedDecl *D, | |||
1452 | LVComputationKind computation) { | |||
1453 | // Internal_linkage attribute overrides other considerations. | |||
1454 | if (D->hasAttr<InternalLinkageAttr>()) | |||
1455 | return getInternalLinkageFor(D); | |||
1456 | ||||
1457 | if (computation.IgnoreAllVisibility && D->hasCachedLinkage()) | |||
1458 | return LinkageInfo(D->getCachedLinkage(), DefaultVisibility, false); | |||
1459 | ||||
1460 | if (llvm::Optional<LinkageInfo> LI = lookup(D, computation)) | |||
1461 | return *LI; | |||
1462 | ||||
1463 | LinkageInfo LV = computeLVForDecl(D, computation); | |||
1464 | if (D->hasCachedLinkage()) | |||
1465 | assert(D->getCachedLinkage() == LV.getLinkage())((D->getCachedLinkage() == LV.getLinkage()) ? static_cast< void> (0) : __assert_fail ("D->getCachedLinkage() == LV.getLinkage()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1465, __PRETTY_FUNCTION__)); | |||
1466 | ||||
1467 | D->setCachedLinkage(LV.getLinkage()); | |||
1468 | cache(D, computation, LV); | |||
1469 | ||||
1470 | #ifndef NDEBUG | |||
1471 | // In C (because of gnu inline) and in c++ with microsoft extensions an | |||
1472 | // static can follow an extern, so we can have two decls with different | |||
1473 | // linkages. | |||
1474 | const LangOptions &Opts = D->getASTContext().getLangOpts(); | |||
1475 | if (!Opts.CPlusPlus || Opts.MicrosoftExt) | |||
1476 | return LV; | |||
1477 | ||||
1478 | // We have just computed the linkage for this decl. By induction we know | |||
1479 | // that all other computed linkages match, check that the one we just | |||
1480 | // computed also does. | |||
1481 | NamedDecl *Old = nullptr; | |||
1482 | for (auto I : D->redecls()) { | |||
1483 | auto *T = cast<NamedDecl>(I); | |||
1484 | if (T == D) | |||
1485 | continue; | |||
1486 | if (!T->isInvalidDecl() && T->hasCachedLinkage()) { | |||
1487 | Old = T; | |||
1488 | break; | |||
1489 | } | |||
1490 | } | |||
1491 | assert(!Old || Old->getCachedLinkage() == D->getCachedLinkage())((!Old || Old->getCachedLinkage() == D->getCachedLinkage ()) ? static_cast<void> (0) : __assert_fail ("!Old || Old->getCachedLinkage() == D->getCachedLinkage()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1491, __PRETTY_FUNCTION__)); | |||
1492 | #endif | |||
1493 | ||||
1494 | return LV; | |||
1495 | } | |||
1496 | ||||
1497 | LinkageInfo LinkageComputer::getDeclLinkageAndVisibility(const NamedDecl *D) { | |||
1498 | return getLVForDecl(D, | |||
1499 | LVComputationKind(usesTypeVisibility(D) | |||
1500 | ? NamedDecl::VisibilityForType | |||
1501 | : NamedDecl::VisibilityForValue)); | |||
1502 | } | |||
1503 | ||||
1504 | Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const { | |||
1505 | Module *M = getOwningModule(); | |||
1506 | if (!M) | |||
1507 | return nullptr; | |||
1508 | ||||
1509 | switch (M->Kind) { | |||
1510 | case Module::ModuleMapModule: | |||
1511 | // Module map modules have no special linkage semantics. | |||
1512 | return nullptr; | |||
1513 | ||||
1514 | case Module::ModuleInterfaceUnit: | |||
1515 | return M; | |||
1516 | ||||
1517 | case Module::GlobalModuleFragment: { | |||
1518 | // External linkage declarations in the global module have no owning module | |||
1519 | // for linkage purposes. But internal linkage declarations in the global | |||
1520 | // module fragment of a particular module are owned by that module for | |||
1521 | // linkage purposes. | |||
1522 | if (IgnoreLinkage) | |||
1523 | return nullptr; | |||
1524 | bool InternalLinkage; | |||
1525 | if (auto *ND = dyn_cast<NamedDecl>(this)) | |||
1526 | InternalLinkage = !ND->hasExternalFormalLinkage(); | |||
1527 | else { | |||
1528 | auto *NSD = dyn_cast<NamespaceDecl>(this); | |||
1529 | InternalLinkage = (NSD && NSD->isAnonymousNamespace()) || | |||
1530 | isInAnonymousNamespace(); | |||
1531 | } | |||
1532 | return InternalLinkage ? M->Parent : nullptr; | |||
1533 | } | |||
1534 | ||||
1535 | case Module::PrivateModuleFragment: | |||
1536 | // The private module fragment is part of its containing module for linkage | |||
1537 | // purposes. | |||
1538 | return M->Parent; | |||
1539 | } | |||
1540 | ||||
1541 | llvm_unreachable("unknown module kind")::llvm::llvm_unreachable_internal("unknown module kind", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1541); | |||
1542 | } | |||
1543 | ||||
1544 | void NamedDecl::printName(raw_ostream &os) const { | |||
1545 | os << Name; | |||
1546 | } | |||
1547 | ||||
1548 | std::string NamedDecl::getQualifiedNameAsString() const { | |||
1549 | std::string QualName; | |||
1550 | llvm::raw_string_ostream OS(QualName); | |||
1551 | printQualifiedName(OS, getASTContext().getPrintingPolicy()); | |||
1552 | return OS.str(); | |||
1553 | } | |||
1554 | ||||
1555 | void NamedDecl::printQualifiedName(raw_ostream &OS) const { | |||
1556 | printQualifiedName(OS, getASTContext().getPrintingPolicy()); | |||
1557 | } | |||
1558 | ||||
1559 | void NamedDecl::printQualifiedName(raw_ostream &OS, | |||
1560 | const PrintingPolicy &P) const { | |||
1561 | const DeclContext *Ctx = getDeclContext(); | |||
1562 | ||||
1563 | // For ObjC methods and properties, look through categories and use the | |||
1564 | // interface as context. | |||
1565 | if (auto *MD = dyn_cast<ObjCMethodDecl>(this)) | |||
1566 | if (auto *ID = MD->getClassInterface()) | |||
1567 | Ctx = ID; | |||
1568 | if (auto *PD = dyn_cast<ObjCPropertyDecl>(this)) { | |||
1569 | if (auto *MD = PD->getGetterMethodDecl()) | |||
1570 | if (auto *ID = MD->getClassInterface()) | |||
1571 | Ctx = ID; | |||
1572 | } | |||
1573 | ||||
1574 | if (Ctx->isFunctionOrMethod()) { | |||
1575 | printName(OS); | |||
1576 | return; | |||
1577 | } | |||
1578 | ||||
1579 | using ContextsTy = SmallVector<const DeclContext *, 8>; | |||
1580 | ContextsTy Contexts; | |||
1581 | ||||
1582 | // Collect named contexts. | |||
1583 | while (Ctx) { | |||
1584 | if (isa<NamedDecl>(Ctx)) | |||
1585 | Contexts.push_back(Ctx); | |||
1586 | Ctx = Ctx->getParent(); | |||
1587 | } | |||
1588 | ||||
1589 | for (const DeclContext *DC : llvm::reverse(Contexts)) { | |||
1590 | if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) { | |||
1591 | OS << Spec->getName(); | |||
1592 | const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); | |||
1593 | printTemplateArgumentList(OS, TemplateArgs.asArray(), P); | |||
1594 | } else if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) { | |||
1595 | if (P.SuppressUnwrittenScope && | |||
1596 | (ND->isAnonymousNamespace() || ND->isInline())) | |||
1597 | continue; | |||
1598 | if (ND->isAnonymousNamespace()) { | |||
1599 | OS << (P.MSVCFormatting ? "`anonymous namespace\'" | |||
1600 | : "(anonymous namespace)"); | |||
1601 | } | |||
1602 | else | |||
1603 | OS << *ND; | |||
1604 | } else if (const auto *RD = dyn_cast<RecordDecl>(DC)) { | |||
1605 | if (!RD->getIdentifier()) | |||
1606 | OS << "(anonymous " << RD->getKindName() << ')'; | |||
1607 | else | |||
1608 | OS << *RD; | |||
1609 | } else if (const auto *FD = dyn_cast<FunctionDecl>(DC)) { | |||
1610 | const FunctionProtoType *FT = nullptr; | |||
1611 | if (FD->hasWrittenPrototype()) | |||
1612 | FT = dyn_cast<FunctionProtoType>(FD->getType()->castAs<FunctionType>()); | |||
1613 | ||||
1614 | OS << *FD << '('; | |||
1615 | if (FT) { | |||
1616 | unsigned NumParams = FD->getNumParams(); | |||
1617 | for (unsigned i = 0; i < NumParams; ++i) { | |||
1618 | if (i) | |||
1619 | OS << ", "; | |||
1620 | OS << FD->getParamDecl(i)->getType().stream(P); | |||
1621 | } | |||
1622 | ||||
1623 | if (FT->isVariadic()) { | |||
1624 | if (NumParams > 0) | |||
1625 | OS << ", "; | |||
1626 | OS << "..."; | |||
1627 | } | |||
1628 | } | |||
1629 | OS << ')'; | |||
1630 | } else if (const auto *ED = dyn_cast<EnumDecl>(DC)) { | |||
1631 | // C++ [dcl.enum]p10: Each enum-name and each unscoped | |||
1632 | // enumerator is declared in the scope that immediately contains | |||
1633 | // the enum-specifier. Each scoped enumerator is declared in the | |||
1634 | // scope of the enumeration. | |||
1635 | // For the case of unscoped enumerator, do not include in the qualified | |||
1636 | // name any information about its enum enclosing scope, as its visibility | |||
1637 | // is global. | |||
1638 | if (ED->isScoped()) | |||
1639 | OS << *ED; | |||
1640 | else | |||
1641 | continue; | |||
1642 | } else { | |||
1643 | OS << *cast<NamedDecl>(DC); | |||
1644 | } | |||
1645 | OS << "::"; | |||
1646 | } | |||
1647 | ||||
1648 | if (getDeclName() || isa<DecompositionDecl>(this)) | |||
1649 | OS << *this; | |||
1650 | else | |||
1651 | OS << "(anonymous)"; | |||
1652 | } | |||
1653 | ||||
1654 | void NamedDecl::getNameForDiagnostic(raw_ostream &OS, | |||
1655 | const PrintingPolicy &Policy, | |||
1656 | bool Qualified) const { | |||
1657 | if (Qualified) | |||
1658 | printQualifiedName(OS, Policy); | |||
1659 | else | |||
1660 | printName(OS); | |||
1661 | } | |||
1662 | ||||
1663 | template<typename T> static bool isRedeclarableImpl(Redeclarable<T> *) { | |||
1664 | return true; | |||
1665 | } | |||
1666 | static bool isRedeclarableImpl(...) { return false; } | |||
1667 | static bool isRedeclarable(Decl::Kind K) { | |||
1668 | switch (K) { | |||
1669 | #define DECL(Type, Base) \ | |||
1670 | case Decl::Type: \ | |||
1671 | return isRedeclarableImpl((Type##Decl *)nullptr); | |||
1672 | #define ABSTRACT_DECL(DECL) | |||
1673 | #include "clang/AST/DeclNodes.inc" | |||
1674 | } | |||
1675 | llvm_unreachable("unknown decl kind")::llvm::llvm_unreachable_internal("unknown decl kind", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1675); | |||
1676 | } | |||
1677 | ||||
1678 | bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const { | |||
1679 | assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch")((getDeclName() == OldD->getDeclName() && "Declaration name mismatch" ) ? static_cast<void> (0) : __assert_fail ("getDeclName() == OldD->getDeclName() && \"Declaration name mismatch\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1679, __PRETTY_FUNCTION__)); | |||
1680 | ||||
1681 | // Never replace one imported declaration with another; we need both results | |||
1682 | // when re-exporting. | |||
1683 | if (OldD->isFromASTFile() && isFromASTFile()) | |||
1684 | return false; | |||
1685 | ||||
1686 | // A kind mismatch implies that the declaration is not replaced. | |||
1687 | if (OldD->getKind() != getKind()) | |||
1688 | return false; | |||
1689 | ||||
1690 | // For method declarations, we never replace. (Why?) | |||
1691 | if (isa<ObjCMethodDecl>(this)) | |||
1692 | return false; | |||
1693 | ||||
1694 | // For parameters, pick the newer one. This is either an error or (in | |||
1695 | // Objective-C) permitted as an extension. | |||
1696 | if (isa<ParmVarDecl>(this)) | |||
1697 | return true; | |||
1698 | ||||
1699 | // Inline namespaces can give us two declarations with the same | |||
1700 | // name and kind in the same scope but different contexts; we should | |||
1701 | // keep both declarations in this case. | |||
1702 | if (!this->getDeclContext()->getRedeclContext()->Equals( | |||
1703 | OldD->getDeclContext()->getRedeclContext())) | |||
1704 | return false; | |||
1705 | ||||
1706 | // Using declarations can be replaced if they import the same name from the | |||
1707 | // same context. | |||
1708 | if (auto *UD = dyn_cast<UsingDecl>(this)) { | |||
1709 | ASTContext &Context = getASTContext(); | |||
1710 | return Context.getCanonicalNestedNameSpecifier(UD->getQualifier()) == | |||
1711 | Context.getCanonicalNestedNameSpecifier( | |||
1712 | cast<UsingDecl>(OldD)->getQualifier()); | |||
1713 | } | |||
1714 | if (auto *UUVD = dyn_cast<UnresolvedUsingValueDecl>(this)) { | |||
1715 | ASTContext &Context = getASTContext(); | |||
1716 | return Context.getCanonicalNestedNameSpecifier(UUVD->getQualifier()) == | |||
1717 | Context.getCanonicalNestedNameSpecifier( | |||
1718 | cast<UnresolvedUsingValueDecl>(OldD)->getQualifier()); | |||
1719 | } | |||
1720 | ||||
1721 | if (isRedeclarable(getKind())) { | |||
1722 | if (getCanonicalDecl() != OldD->getCanonicalDecl()) | |||
1723 | return false; | |||
1724 | ||||
1725 | if (IsKnownNewer) | |||
1726 | return true; | |||
1727 | ||||
1728 | // Check whether this is actually newer than OldD. We want to keep the | |||
1729 | // newer declaration. This loop will usually only iterate once, because | |||
1730 | // OldD is usually the previous declaration. | |||
1731 | for (auto D : redecls()) { | |||
1732 | if (D == OldD) | |||
1733 | break; | |||
1734 | ||||
1735 | // If we reach the canonical declaration, then OldD is not actually older | |||
1736 | // than this one. | |||
1737 | // | |||
1738 | // FIXME: In this case, we should not add this decl to the lookup table. | |||
1739 | if (D->isCanonicalDecl()) | |||
1740 | return false; | |||
1741 | } | |||
1742 | ||||
1743 | // It's a newer declaration of the same kind of declaration in the same | |||
1744 | // scope: we want this decl instead of the existing one. | |||
1745 | return true; | |||
1746 | } | |||
1747 | ||||
1748 | // In all other cases, we need to keep both declarations in case they have | |||
1749 | // different visibility. Any attempt to use the name will result in an | |||
1750 | // ambiguity if more than one is visible. | |||
1751 | return false; | |||
1752 | } | |||
1753 | ||||
1754 | bool NamedDecl::hasLinkage() const { | |||
1755 | return getFormalLinkage() != NoLinkage; | |||
1756 | } | |||
1757 | ||||
1758 | NamedDecl *NamedDecl::getUnderlyingDeclImpl() { | |||
1759 | NamedDecl *ND = this; | |||
1760 | while (auto *UD = dyn_cast<UsingShadowDecl>(ND)) | |||
1761 | ND = UD->getTargetDecl(); | |||
1762 | ||||
1763 | if (auto *AD = dyn_cast<ObjCCompatibleAliasDecl>(ND)) | |||
1764 | return AD->getClassInterface(); | |||
1765 | ||||
1766 | if (auto *AD = dyn_cast<NamespaceAliasDecl>(ND)) | |||
1767 | return AD->getNamespace(); | |||
1768 | ||||
1769 | return ND; | |||
1770 | } | |||
1771 | ||||
1772 | bool NamedDecl::isCXXInstanceMember() const { | |||
1773 | if (!isCXXClassMember()) | |||
1774 | return false; | |||
1775 | ||||
1776 | const NamedDecl *D = this; | |||
1777 | if (isa<UsingShadowDecl>(D)) | |||
1778 | D = cast<UsingShadowDecl>(D)->getTargetDecl(); | |||
1779 | ||||
1780 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<MSPropertyDecl>(D)) | |||
1781 | return true; | |||
1782 | if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction())) | |||
1783 | return MD->isInstance(); | |||
1784 | return false; | |||
1785 | } | |||
1786 | ||||
1787 | //===----------------------------------------------------------------------===// | |||
1788 | // DeclaratorDecl Implementation | |||
1789 | //===----------------------------------------------------------------------===// | |||
1790 | ||||
1791 | template <typename DeclT> | |||
1792 | static SourceLocation getTemplateOrInnerLocStart(const DeclT *decl) { | |||
1793 | if (decl->getNumTemplateParameterLists() > 0) | |||
1794 | return decl->getTemplateParameterList(0)->getTemplateLoc(); | |||
1795 | else | |||
1796 | return decl->getInnerLocStart(); | |||
1797 | } | |||
1798 | ||||
1799 | SourceLocation DeclaratorDecl::getTypeSpecStartLoc() const { | |||
1800 | TypeSourceInfo *TSI = getTypeSourceInfo(); | |||
1801 | if (TSI) return TSI->getTypeLoc().getBeginLoc(); | |||
1802 | return SourceLocation(); | |||
1803 | } | |||
1804 | ||||
1805 | void DeclaratorDecl::setQualifierInfo(NestedNameSpecifierLoc QualifierLoc) { | |||
1806 | if (QualifierLoc) { | |||
1807 | // Make sure the extended decl info is allocated. | |||
1808 | if (!hasExtInfo()) { | |||
1809 | // Save (non-extended) type source info pointer. | |||
1810 | auto *savedTInfo = DeclInfo.get<TypeSourceInfo*>(); | |||
1811 | // Allocate external info struct. | |||
1812 | DeclInfo = new (getASTContext()) ExtInfo; | |||
1813 | // Restore savedTInfo into (extended) decl info. | |||
1814 | getExtInfo()->TInfo = savedTInfo; | |||
1815 | } | |||
1816 | // Set qualifier info. | |||
1817 | getExtInfo()->QualifierLoc = QualifierLoc; | |||
1818 | } else { | |||
1819 | // Here Qualifier == 0, i.e., we are removing the qualifier (if any). | |||
1820 | if (hasExtInfo()) { | |||
1821 | if (getExtInfo()->NumTemplParamLists == 0) { | |||
1822 | // Save type source info pointer. | |||
1823 | TypeSourceInfo *savedTInfo = getExtInfo()->TInfo; | |||
1824 | // Deallocate the extended decl info. | |||
1825 | getASTContext().Deallocate(getExtInfo()); | |||
1826 | // Restore savedTInfo into (non-extended) decl info. | |||
1827 | DeclInfo = savedTInfo; | |||
1828 | } | |||
1829 | else | |||
1830 | getExtInfo()->QualifierLoc = QualifierLoc; | |||
1831 | } | |||
1832 | } | |||
1833 | } | |||
1834 | ||||
1835 | void DeclaratorDecl::setTemplateParameterListsInfo( | |||
1836 | ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists) { | |||
1837 | assert(!TPLists.empty())((!TPLists.empty()) ? static_cast<void> (0) : __assert_fail ("!TPLists.empty()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1837, __PRETTY_FUNCTION__)); | |||
1838 | // Make sure the extended decl info is allocated. | |||
1839 | if (!hasExtInfo()) { | |||
1840 | // Save (non-extended) type source info pointer. | |||
1841 | auto *savedTInfo = DeclInfo.get<TypeSourceInfo*>(); | |||
1842 | // Allocate external info struct. | |||
1843 | DeclInfo = new (getASTContext()) ExtInfo; | |||
1844 | // Restore savedTInfo into (extended) decl info. | |||
1845 | getExtInfo()->TInfo = savedTInfo; | |||
1846 | } | |||
1847 | // Set the template parameter lists info. | |||
1848 | getExtInfo()->setTemplateParameterListsInfo(Context, TPLists); | |||
1849 | } | |||
1850 | ||||
1851 | SourceLocation DeclaratorDecl::getOuterLocStart() const { | |||
1852 | return getTemplateOrInnerLocStart(this); | |||
1853 | } | |||
1854 | ||||
1855 | // Helper function: returns true if QT is or contains a type | |||
1856 | // having a postfix component. | |||
1857 | static bool typeIsPostfix(QualType QT) { | |||
1858 | while (true) { | |||
1859 | const Type* T = QT.getTypePtr(); | |||
1860 | switch (T->getTypeClass()) { | |||
1861 | default: | |||
1862 | return false; | |||
1863 | case Type::Pointer: | |||
1864 | QT = cast<PointerType>(T)->getPointeeType(); | |||
1865 | break; | |||
1866 | case Type::BlockPointer: | |||
1867 | QT = cast<BlockPointerType>(T)->getPointeeType(); | |||
1868 | break; | |||
1869 | case Type::MemberPointer: | |||
1870 | QT = cast<MemberPointerType>(T)->getPointeeType(); | |||
1871 | break; | |||
1872 | case Type::LValueReference: | |||
1873 | case Type::RValueReference: | |||
1874 | QT = cast<ReferenceType>(T)->getPointeeType(); | |||
1875 | break; | |||
1876 | case Type::PackExpansion: | |||
1877 | QT = cast<PackExpansionType>(T)->getPattern(); | |||
1878 | break; | |||
1879 | case Type::Paren: | |||
1880 | case Type::ConstantArray: | |||
1881 | case Type::DependentSizedArray: | |||
1882 | case Type::IncompleteArray: | |||
1883 | case Type::VariableArray: | |||
1884 | case Type::FunctionProto: | |||
1885 | case Type::FunctionNoProto: | |||
1886 | return true; | |||
1887 | } | |||
1888 | } | |||
1889 | } | |||
1890 | ||||
1891 | SourceRange DeclaratorDecl::getSourceRange() const { | |||
1892 | SourceLocation RangeEnd = getLocation(); | |||
1893 | if (TypeSourceInfo *TInfo = getTypeSourceInfo()) { | |||
1894 | // If the declaration has no name or the type extends past the name take the | |||
1895 | // end location of the type. | |||
1896 | if (!getDeclName() || typeIsPostfix(TInfo->getType())) | |||
1897 | RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd(); | |||
1898 | } | |||
1899 | return SourceRange(getOuterLocStart(), RangeEnd); | |||
1900 | } | |||
1901 | ||||
1902 | void QualifierInfo::setTemplateParameterListsInfo( | |||
1903 | ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists) { | |||
1904 | // Free previous template parameters (if any). | |||
1905 | if (NumTemplParamLists > 0) { | |||
1906 | Context.Deallocate(TemplParamLists); | |||
1907 | TemplParamLists = nullptr; | |||
1908 | NumTemplParamLists = 0; | |||
1909 | } | |||
1910 | // Set info on matched template parameter lists (if any). | |||
1911 | if (!TPLists.empty()) { | |||
1912 | TemplParamLists = new (Context) TemplateParameterList *[TPLists.size()]; | |||
1913 | NumTemplParamLists = TPLists.size(); | |||
1914 | std::copy(TPLists.begin(), TPLists.end(), TemplParamLists); | |||
1915 | } | |||
1916 | } | |||
1917 | ||||
1918 | //===----------------------------------------------------------------------===// | |||
1919 | // VarDecl Implementation | |||
1920 | //===----------------------------------------------------------------------===// | |||
1921 | ||||
1922 | const char *VarDecl::getStorageClassSpecifierString(StorageClass SC) { | |||
1923 | switch (SC) { | |||
1924 | case SC_None: break; | |||
1925 | case SC_Auto: return "auto"; | |||
1926 | case SC_Extern: return "extern"; | |||
1927 | case SC_PrivateExtern: return "__private_extern__"; | |||
1928 | case SC_Register: return "register"; | |||
1929 | case SC_Static: return "static"; | |||
1930 | } | |||
1931 | ||||
1932 | llvm_unreachable("Invalid storage class")::llvm::llvm_unreachable_internal("Invalid storage class", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1932); | |||
1933 | } | |||
1934 | ||||
1935 | VarDecl::VarDecl(Kind DK, ASTContext &C, DeclContext *DC, | |||
1936 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
1937 | IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, | |||
1938 | StorageClass SC) | |||
1939 | : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), | |||
1940 | redeclarable_base(C) { | |||
1941 | static_assert(sizeof(VarDeclBitfields) <= sizeof(unsigned), | |||
1942 | "VarDeclBitfields too large!"); | |||
1943 | static_assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned), | |||
1944 | "ParmVarDeclBitfields too large!"); | |||
1945 | static_assert(sizeof(NonParmVarDeclBitfields) <= sizeof(unsigned), | |||
1946 | "NonParmVarDeclBitfields too large!"); | |||
1947 | AllBits = 0; | |||
1948 | VarDeclBits.SClass = SC; | |||
1949 | // Everything else is implicitly initialized to false. | |||
1950 | } | |||
1951 | ||||
1952 | VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, | |||
1953 | SourceLocation StartL, SourceLocation IdL, | |||
1954 | IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, | |||
1955 | StorageClass S) { | |||
1956 | return new (C, DC) VarDecl(Var, C, DC, StartL, IdL, Id, T, TInfo, S); | |||
1957 | } | |||
1958 | ||||
1959 | VarDecl *VarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
1960 | return new (C, ID) | |||
1961 | VarDecl(Var, C, nullptr, SourceLocation(), SourceLocation(), nullptr, | |||
1962 | QualType(), nullptr, SC_None); | |||
1963 | } | |||
1964 | ||||
1965 | void VarDecl::setStorageClass(StorageClass SC) { | |||
1966 | assert(isLegalForVariable(SC))((isLegalForVariable(SC)) ? static_cast<void> (0) : __assert_fail ("isLegalForVariable(SC)", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1966, __PRETTY_FUNCTION__)); | |||
1967 | VarDeclBits.SClass = SC; | |||
1968 | } | |||
1969 | ||||
1970 | VarDecl::TLSKind VarDecl::getTLSKind() const { | |||
1971 | switch (VarDeclBits.TSCSpec) { | |||
1972 | case TSCS_unspecified: | |||
1973 | if (!hasAttr<ThreadAttr>() && | |||
1974 | !(getASTContext().getLangOpts().OpenMPUseTLS && | |||
1975 | getASTContext().getTargetInfo().isTLSSupported() && | |||
1976 | hasAttr<OMPThreadPrivateDeclAttr>())) | |||
1977 | return TLS_None; | |||
1978 | return ((getASTContext().getLangOpts().isCompatibleWithMSVC( | |||
1979 | LangOptions::MSVC2015)) || | |||
1980 | hasAttr<OMPThreadPrivateDeclAttr>()) | |||
1981 | ? TLS_Dynamic | |||
1982 | : TLS_Static; | |||
1983 | case TSCS___thread: // Fall through. | |||
1984 | case TSCS__Thread_local: | |||
1985 | return TLS_Static; | |||
1986 | case TSCS_thread_local: | |||
1987 | return TLS_Dynamic; | |||
1988 | } | |||
1989 | llvm_unreachable("Unknown thread storage class specifier!")::llvm::llvm_unreachable_internal("Unknown thread storage class specifier!" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 1989); | |||
1990 | } | |||
1991 | ||||
1992 | SourceRange VarDecl::getSourceRange() const { | |||
1993 | if (const Expr *Init = getInit()) { | |||
1994 | SourceLocation InitEnd = Init->getEndLoc(); | |||
1995 | // If Init is implicit, ignore its source range and fallback on | |||
1996 | // DeclaratorDecl::getSourceRange() to handle postfix elements. | |||
1997 | if (InitEnd.isValid() && InitEnd != getLocation()) | |||
1998 | return SourceRange(getOuterLocStart(), InitEnd); | |||
1999 | } | |||
2000 | return DeclaratorDecl::getSourceRange(); | |||
2001 | } | |||
2002 | ||||
2003 | template<typename T> | |||
2004 | static LanguageLinkage getDeclLanguageLinkage(const T &D) { | |||
2005 | // C++ [dcl.link]p1: All function types, function names with external linkage, | |||
2006 | // and variable names with external linkage have a language linkage. | |||
2007 | if (!D.hasExternalFormalLinkage()) | |||
2008 | return NoLanguageLinkage; | |||
2009 | ||||
2010 | // Language linkage is a C++ concept, but saying that everything else in C has | |||
2011 | // C language linkage fits the implementation nicely. | |||
2012 | ASTContext &Context = D.getASTContext(); | |||
2013 | if (!Context.getLangOpts().CPlusPlus) | |||
2014 | return CLanguageLinkage; | |||
2015 | ||||
2016 | // C++ [dcl.link]p4: A C language linkage is ignored in determining the | |||
2017 | // language linkage of the names of class members and the function type of | |||
2018 | // class member functions. | |||
2019 | const DeclContext *DC = D.getDeclContext(); | |||
2020 | if (DC->isRecord()) | |||
2021 | return CXXLanguageLinkage; | |||
2022 | ||||
2023 | // If the first decl is in an extern "C" context, any other redeclaration | |||
2024 | // will have C language linkage. If the first one is not in an extern "C" | |||
2025 | // context, we would have reported an error for any other decl being in one. | |||
2026 | if (isFirstInExternCContext(&D)) | |||
2027 | return CLanguageLinkage; | |||
2028 | return CXXLanguageLinkage; | |||
2029 | } | |||
2030 | ||||
2031 | template<typename T> | |||
2032 | static bool isDeclExternC(const T &D) { | |||
2033 | // Since the context is ignored for class members, they can only have C++ | |||
2034 | // language linkage or no language linkage. | |||
2035 | const DeclContext *DC = D.getDeclContext(); | |||
2036 | if (DC->isRecord()) { | |||
2037 | assert(D.getASTContext().getLangOpts().CPlusPlus)((D.getASTContext().getLangOpts().CPlusPlus) ? static_cast< void> (0) : __assert_fail ("D.getASTContext().getLangOpts().CPlusPlus" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2037, __PRETTY_FUNCTION__)); | |||
2038 | return false; | |||
2039 | } | |||
2040 | ||||
2041 | return D.getLanguageLinkage() == CLanguageLinkage; | |||
2042 | } | |||
2043 | ||||
2044 | LanguageLinkage VarDecl::getLanguageLinkage() const { | |||
2045 | return getDeclLanguageLinkage(*this); | |||
2046 | } | |||
2047 | ||||
2048 | bool VarDecl::isExternC() const { | |||
2049 | return isDeclExternC(*this); | |||
2050 | } | |||
2051 | ||||
2052 | bool VarDecl::isInExternCContext() const { | |||
2053 | return getLexicalDeclContext()->isExternCContext(); | |||
2054 | } | |||
2055 | ||||
2056 | bool VarDecl::isInExternCXXContext() const { | |||
2057 | return getLexicalDeclContext()->isExternCXXContext(); | |||
2058 | } | |||
2059 | ||||
2060 | VarDecl *VarDecl::getCanonicalDecl() { return getFirstDecl(); } | |||
2061 | ||||
2062 | VarDecl::DefinitionKind | |||
2063 | VarDecl::isThisDeclarationADefinition(ASTContext &C) const { | |||
2064 | if (isThisDeclarationADemotedDefinition()) | |||
2065 | return DeclarationOnly; | |||
2066 | ||||
2067 | // C++ [basic.def]p2: | |||
2068 | // A declaration is a definition unless [...] it contains the 'extern' | |||
2069 | // specifier or a linkage-specification and neither an initializer [...], | |||
2070 | // it declares a non-inline static data member in a class declaration [...], | |||
2071 | // it declares a static data member outside a class definition and the variable | |||
2072 | // was defined within the class with the constexpr specifier [...], | |||
2073 | // C++1y [temp.expl.spec]p15: | |||
2074 | // An explicit specialization of a static data member or an explicit | |||
2075 | // specialization of a static data member template is a definition if the | |||
2076 | // declaration includes an initializer; otherwise, it is a declaration. | |||
2077 | // | |||
2078 | // FIXME: How do you declare (but not define) a partial specialization of | |||
2079 | // a static data member template outside the containing class? | |||
2080 | if (isStaticDataMember()) { | |||
2081 | if (isOutOfLine() && | |||
2082 | !(getCanonicalDecl()->isInline() && | |||
2083 | getCanonicalDecl()->isConstexpr()) && | |||
2084 | (hasInit() || | |||
2085 | // If the first declaration is out-of-line, this may be an | |||
2086 | // instantiation of an out-of-line partial specialization of a variable | |||
2087 | // template for which we have not yet instantiated the initializer. | |||
2088 | (getFirstDecl()->isOutOfLine() | |||
2089 | ? getTemplateSpecializationKind() == TSK_Undeclared | |||
2090 | : getTemplateSpecializationKind() != | |||
2091 | TSK_ExplicitSpecialization) || | |||
2092 | isa<VarTemplatePartialSpecializationDecl>(this))) | |||
2093 | return Definition; | |||
2094 | else if (!isOutOfLine() && isInline()) | |||
2095 | return Definition; | |||
2096 | else | |||
2097 | return DeclarationOnly; | |||
2098 | } | |||
2099 | // C99 6.7p5: | |||
2100 | // A definition of an identifier is a declaration for that identifier that | |||
2101 | // [...] causes storage to be reserved for that object. | |||
2102 | // Note: that applies for all non-file-scope objects. | |||
2103 | // C99 6.9.2p1: | |||
2104 | // If the declaration of an identifier for an object has file scope and an | |||
2105 | // initializer, the declaration is an external definition for the identifier | |||
2106 | if (hasInit()) | |||
2107 | return Definition; | |||
2108 | ||||
2109 | if (hasDefiningAttr()) | |||
2110 | return Definition; | |||
2111 | ||||
2112 | if (const auto *SAA = getAttr<SelectAnyAttr>()) | |||
2113 | if (!SAA->isInherited()) | |||
2114 | return Definition; | |||
2115 | ||||
2116 | // A variable template specialization (other than a static data member | |||
2117 | // template or an explicit specialization) is a declaration until we | |||
2118 | // instantiate its initializer. | |||
2119 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(this)) { | |||
2120 | if (VTSD->getTemplateSpecializationKind() != TSK_ExplicitSpecialization && | |||
2121 | !isa<VarTemplatePartialSpecializationDecl>(VTSD) && | |||
2122 | !VTSD->IsCompleteDefinition) | |||
2123 | return DeclarationOnly; | |||
2124 | } | |||
2125 | ||||
2126 | if (hasExternalStorage()) | |||
2127 | return DeclarationOnly; | |||
2128 | ||||
2129 | // [dcl.link] p7: | |||
2130 | // A declaration directly contained in a linkage-specification is treated | |||
2131 | // as if it contains the extern specifier for the purpose of determining | |||
2132 | // the linkage of the declared name and whether it is a definition. | |||
2133 | if (isSingleLineLanguageLinkage(*this)) | |||
2134 | return DeclarationOnly; | |||
2135 | ||||
2136 | // C99 6.9.2p2: | |||
2137 | // A declaration of an object that has file scope without an initializer, | |||
2138 | // and without a storage class specifier or the scs 'static', constitutes | |||
2139 | // a tentative definition. | |||
2140 | // No such thing in C++. | |||
2141 | if (!C.getLangOpts().CPlusPlus && isFileVarDecl()) | |||
2142 | return TentativeDefinition; | |||
2143 | ||||
2144 | // What's left is (in C, block-scope) declarations without initializers or | |||
2145 | // external storage. These are definitions. | |||
2146 | return Definition; | |||
2147 | } | |||
2148 | ||||
2149 | VarDecl *VarDecl::getActingDefinition() { | |||
2150 | DefinitionKind Kind = isThisDeclarationADefinition(); | |||
2151 | if (Kind != TentativeDefinition) | |||
2152 | return nullptr; | |||
2153 | ||||
2154 | VarDecl *LastTentative = nullptr; | |||
2155 | VarDecl *First = getFirstDecl(); | |||
2156 | for (auto I : First->redecls()) { | |||
2157 | Kind = I->isThisDeclarationADefinition(); | |||
2158 | if (Kind == Definition) | |||
2159 | return nullptr; | |||
2160 | else if (Kind == TentativeDefinition) | |||
2161 | LastTentative = I; | |||
2162 | } | |||
2163 | return LastTentative; | |||
2164 | } | |||
2165 | ||||
2166 | VarDecl *VarDecl::getDefinition(ASTContext &C) { | |||
2167 | VarDecl *First = getFirstDecl(); | |||
2168 | for (auto I : First->redecls()) { | |||
2169 | if (I->isThisDeclarationADefinition(C) == Definition) | |||
2170 | return I; | |||
2171 | } | |||
2172 | return nullptr; | |||
2173 | } | |||
2174 | ||||
2175 | VarDecl::DefinitionKind VarDecl::hasDefinition(ASTContext &C) const { | |||
2176 | DefinitionKind Kind = DeclarationOnly; | |||
2177 | ||||
2178 | const VarDecl *First = getFirstDecl(); | |||
2179 | for (auto I : First->redecls()) { | |||
2180 | Kind = std::max(Kind, I->isThisDeclarationADefinition(C)); | |||
2181 | if (Kind == Definition) | |||
2182 | break; | |||
2183 | } | |||
2184 | ||||
2185 | return Kind; | |||
2186 | } | |||
2187 | ||||
2188 | const Expr *VarDecl::getAnyInitializer(const VarDecl *&D) const { | |||
2189 | for (auto I : redecls()) { | |||
2190 | if (auto Expr = I->getInit()) { | |||
2191 | D = I; | |||
2192 | return Expr; | |||
2193 | } | |||
2194 | } | |||
2195 | return nullptr; | |||
2196 | } | |||
2197 | ||||
2198 | bool VarDecl::hasInit() const { | |||
2199 | if (auto *P = dyn_cast<ParmVarDecl>(this)) | |||
2200 | if (P->hasUnparsedDefaultArg() || P->hasUninstantiatedDefaultArg()) | |||
2201 | return false; | |||
2202 | ||||
2203 | return !Init.isNull(); | |||
2204 | } | |||
2205 | ||||
2206 | Expr *VarDecl::getInit() { | |||
2207 | if (!hasInit()) | |||
2208 | return nullptr; | |||
2209 | ||||
2210 | if (auto *S = Init.dyn_cast<Stmt *>()) | |||
2211 | return cast<Expr>(S); | |||
2212 | ||||
2213 | return cast_or_null<Expr>(Init.get<EvaluatedStmt *>()->Value); | |||
2214 | } | |||
2215 | ||||
2216 | Stmt **VarDecl::getInitAddress() { | |||
2217 | if (auto *ES = Init.dyn_cast<EvaluatedStmt *>()) | |||
2218 | return &ES->Value; | |||
2219 | ||||
2220 | return Init.getAddrOfPtr1(); | |||
2221 | } | |||
2222 | ||||
2223 | bool VarDecl::isOutOfLine() const { | |||
2224 | if (Decl::isOutOfLine()) | |||
2225 | return true; | |||
2226 | ||||
2227 | if (!isStaticDataMember()) | |||
2228 | return false; | |||
2229 | ||||
2230 | // If this static data member was instantiated from a static data member of | |||
2231 | // a class template, check whether that static data member was defined | |||
2232 | // out-of-line. | |||
2233 | if (VarDecl *VD = getInstantiatedFromStaticDataMember()) | |||
2234 | return VD->isOutOfLine(); | |||
2235 | ||||
2236 | return false; | |||
2237 | } | |||
2238 | ||||
2239 | void VarDecl::setInit(Expr *I) { | |||
2240 | if (auto *Eval = Init.dyn_cast<EvaluatedStmt *>()) { | |||
2241 | Eval->~EvaluatedStmt(); | |||
2242 | getASTContext().Deallocate(Eval); | |||
2243 | } | |||
2244 | ||||
2245 | Init = I; | |||
2246 | } | |||
2247 | ||||
2248 | bool VarDecl::isUsableInConstantExpressions(ASTContext &C) const { | |||
2249 | const LangOptions &Lang = C.getLangOpts(); | |||
2250 | ||||
2251 | if (!Lang.CPlusPlus) | |||
2252 | return false; | |||
2253 | ||||
2254 | // In C++11, any variable of reference type can be used in a constant | |||
2255 | // expression if it is initialized by a constant expression. | |||
2256 | if (Lang.CPlusPlus11 && getType()->isReferenceType()) | |||
2257 | return true; | |||
2258 | ||||
2259 | // Only const objects can be used in constant expressions in C++. C++98 does | |||
2260 | // not require the variable to be non-volatile, but we consider this to be a | |||
2261 | // defect. | |||
2262 | if (!getType().isConstQualified() || getType().isVolatileQualified()) | |||
2263 | return false; | |||
2264 | ||||
2265 | // In C++, const, non-volatile variables of integral or enumeration types | |||
2266 | // can be used in constant expressions. | |||
2267 | if (getType()->isIntegralOrEnumerationType()) | |||
2268 | return true; | |||
2269 | ||||
2270 | // Additionally, in C++11, non-volatile constexpr variables can be used in | |||
2271 | // constant expressions. | |||
2272 | return Lang.CPlusPlus11 && isConstexpr(); | |||
2273 | } | |||
2274 | ||||
2275 | /// Convert the initializer for this declaration to the elaborated EvaluatedStmt | |||
2276 | /// form, which contains extra information on the evaluated value of the | |||
2277 | /// initializer. | |||
2278 | EvaluatedStmt *VarDecl::ensureEvaluatedStmt() const { | |||
2279 | auto *Eval = Init.dyn_cast<EvaluatedStmt *>(); | |||
2280 | if (!Eval) { | |||
2281 | // Note: EvaluatedStmt contains an APValue, which usually holds | |||
2282 | // resources not allocated from the ASTContext. We need to do some | |||
2283 | // work to avoid leaking those, but we do so in VarDecl::evaluateValue | |||
2284 | // where we can detect whether there's anything to clean up or not. | |||
2285 | Eval = new (getASTContext()) EvaluatedStmt; | |||
2286 | Eval->Value = Init.get<Stmt *>(); | |||
2287 | Init = Eval; | |||
2288 | } | |||
2289 | return Eval; | |||
2290 | } | |||
2291 | ||||
2292 | APValue *VarDecl::evaluateValue() const { | |||
2293 | SmallVector<PartialDiagnosticAt, 8> Notes; | |||
2294 | return evaluateValue(Notes); | |||
2295 | } | |||
2296 | ||||
2297 | APValue *VarDecl::evaluateValue( | |||
2298 | SmallVectorImpl<PartialDiagnosticAt> &Notes) const { | |||
2299 | EvaluatedStmt *Eval = ensureEvaluatedStmt(); | |||
2300 | ||||
2301 | // We only produce notes indicating why an initializer is non-constant the | |||
2302 | // first time it is evaluated. FIXME: The notes won't always be emitted the | |||
2303 | // first time we try evaluation, so might not be produced at all. | |||
2304 | if (Eval->WasEvaluated) | |||
2305 | return Eval->Evaluated.isAbsent() ? nullptr : &Eval->Evaluated; | |||
2306 | ||||
2307 | const auto *Init = cast<Expr>(Eval->Value); | |||
2308 | assert(!Init->isValueDependent())((!Init->isValueDependent()) ? static_cast<void> (0) : __assert_fail ("!Init->isValueDependent()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2308, __PRETTY_FUNCTION__)); | |||
2309 | ||||
2310 | if (Eval->IsEvaluating) { | |||
2311 | // FIXME: Produce a diagnostic for self-initialization. | |||
2312 | Eval->CheckedICE = true; | |||
2313 | Eval->IsICE = false; | |||
2314 | return nullptr; | |||
2315 | } | |||
2316 | ||||
2317 | Eval->IsEvaluating = true; | |||
2318 | ||||
2319 | bool Result = Init->EvaluateAsInitializer(Eval->Evaluated, getASTContext(), | |||
2320 | this, Notes); | |||
2321 | ||||
2322 | // Ensure the computed APValue is cleaned up later if evaluation succeeded, | |||
2323 | // or that it's empty (so that there's nothing to clean up) if evaluation | |||
2324 | // failed. | |||
2325 | if (!Result) | |||
2326 | Eval->Evaluated = APValue(); | |||
2327 | else if (Eval->Evaluated.needsCleanup()) | |||
2328 | getASTContext().addDestruction(&Eval->Evaluated); | |||
2329 | ||||
2330 | Eval->IsEvaluating = false; | |||
2331 | Eval->WasEvaluated = true; | |||
2332 | ||||
2333 | // In C++11, we have determined whether the initializer was a constant | |||
2334 | // expression as a side-effect. | |||
2335 | if (getASTContext().getLangOpts().CPlusPlus11 && !Eval->CheckedICE) { | |||
2336 | Eval->CheckedICE = true; | |||
2337 | Eval->IsICE = Result && Notes.empty(); | |||
2338 | } | |||
2339 | ||||
2340 | return Result ? &Eval->Evaluated : nullptr; | |||
2341 | } | |||
2342 | ||||
2343 | APValue *VarDecl::getEvaluatedValue() const { | |||
2344 | if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) | |||
2345 | if (Eval->WasEvaluated) | |||
2346 | return &Eval->Evaluated; | |||
2347 | ||||
2348 | return nullptr; | |||
2349 | } | |||
2350 | ||||
2351 | bool VarDecl::isInitKnownICE() const { | |||
2352 | if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) | |||
2353 | return Eval->CheckedICE; | |||
2354 | ||||
2355 | return false; | |||
2356 | } | |||
2357 | ||||
2358 | bool VarDecl::isInitICE() const { | |||
2359 | assert(isInitKnownICE() &&((isInitKnownICE() && "Check whether we already know that the initializer is an ICE" ) ? static_cast<void> (0) : __assert_fail ("isInitKnownICE() && \"Check whether we already know that the initializer is an ICE\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2360, __PRETTY_FUNCTION__)) | |||
2360 | "Check whether we already know that the initializer is an ICE")((isInitKnownICE() && "Check whether we already know that the initializer is an ICE" ) ? static_cast<void> (0) : __assert_fail ("isInitKnownICE() && \"Check whether we already know that the initializer is an ICE\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2360, __PRETTY_FUNCTION__)); | |||
2361 | return Init.get<EvaluatedStmt *>()->IsICE; | |||
2362 | } | |||
2363 | ||||
2364 | bool VarDecl::checkInitIsICE() const { | |||
2365 | // Initializers of weak variables are never ICEs. | |||
2366 | if (isWeak()) | |||
2367 | return false; | |||
2368 | ||||
2369 | EvaluatedStmt *Eval = ensureEvaluatedStmt(); | |||
2370 | if (Eval->CheckedICE) | |||
2371 | // We have already checked whether this subexpression is an | |||
2372 | // integral constant expression. | |||
2373 | return Eval->IsICE; | |||
2374 | ||||
2375 | const auto *Init = cast<Expr>(Eval->Value); | |||
2376 | assert(!Init->isValueDependent())((!Init->isValueDependent()) ? static_cast<void> (0) : __assert_fail ("!Init->isValueDependent()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2376, __PRETTY_FUNCTION__)); | |||
2377 | ||||
2378 | // In C++11, evaluate the initializer to check whether it's a constant | |||
2379 | // expression. | |||
2380 | if (getASTContext().getLangOpts().CPlusPlus11) { | |||
2381 | SmallVector<PartialDiagnosticAt, 8> Notes; | |||
2382 | evaluateValue(Notes); | |||
2383 | return Eval->IsICE; | |||
2384 | } | |||
2385 | ||||
2386 | // It's an ICE whether or not the definition we found is | |||
2387 | // out-of-line. See DR 721 and the discussion in Clang PR | |||
2388 | // 6206 for details. | |||
2389 | ||||
2390 | if (Eval->CheckingICE) | |||
2391 | return false; | |||
2392 | Eval->CheckingICE = true; | |||
2393 | ||||
2394 | Eval->IsICE = Init->isIntegerConstantExpr(getASTContext()); | |||
2395 | Eval->CheckingICE = false; | |||
2396 | Eval->CheckedICE = true; | |||
2397 | return Eval->IsICE; | |||
2398 | } | |||
2399 | ||||
2400 | bool VarDecl::isParameterPack() const { | |||
2401 | return isa<PackExpansionType>(getType()); | |||
2402 | } | |||
2403 | ||||
2404 | template<typename DeclT> | |||
2405 | static DeclT *getDefinitionOrSelf(DeclT *D) { | |||
2406 | assert(D)((D) ? static_cast<void> (0) : __assert_fail ("D", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2406, __PRETTY_FUNCTION__)); | |||
2407 | if (auto *Def = D->getDefinition()) | |||
2408 | return Def; | |||
2409 | return D; | |||
2410 | } | |||
2411 | ||||
2412 | bool VarDecl::isEscapingByref() const { | |||
2413 | return hasAttr<BlocksAttr>() && NonParmVarDeclBits.EscapingByref; | |||
2414 | } | |||
2415 | ||||
2416 | bool VarDecl::isNonEscapingByref() const { | |||
2417 | return hasAttr<BlocksAttr>() && !NonParmVarDeclBits.EscapingByref; | |||
2418 | } | |||
2419 | ||||
2420 | VarDecl *VarDecl::getTemplateInstantiationPattern() const { | |||
2421 | const VarDecl *VD = this; | |||
2422 | ||||
2423 | // If this is an instantiated member, walk back to the template from which | |||
2424 | // it was instantiated. | |||
2425 | if (MemberSpecializationInfo *MSInfo = VD->getMemberSpecializationInfo()) { | |||
2426 | if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) { | |||
2427 | VD = VD->getInstantiatedFromStaticDataMember(); | |||
2428 | while (auto *NewVD = VD->getInstantiatedFromStaticDataMember()) | |||
2429 | VD = NewVD; | |||
2430 | } | |||
2431 | } | |||
2432 | ||||
2433 | // If it's an instantiated variable template specialization, find the | |||
2434 | // template or partial specialization from which it was instantiated. | |||
2435 | if (auto *VDTemplSpec = dyn_cast<VarTemplateSpecializationDecl>(VD)) { | |||
2436 | if (isTemplateInstantiation(VDTemplSpec->getTemplateSpecializationKind())) { | |||
2437 | auto From = VDTemplSpec->getInstantiatedFrom(); | |||
2438 | if (auto *VTD = From.dyn_cast<VarTemplateDecl *>()) { | |||
2439 | while (!VTD->isMemberSpecialization()) { | |||
2440 | auto *NewVTD = VTD->getInstantiatedFromMemberTemplate(); | |||
2441 | if (!NewVTD) | |||
2442 | break; | |||
2443 | VTD = NewVTD; | |||
2444 | } | |||
2445 | return getDefinitionOrSelf(VTD->getTemplatedDecl()); | |||
2446 | } | |||
2447 | if (auto *VTPSD = | |||
2448 | From.dyn_cast<VarTemplatePartialSpecializationDecl *>()) { | |||
2449 | while (!VTPSD->isMemberSpecialization()) { | |||
2450 | auto *NewVTPSD = VTPSD->getInstantiatedFromMember(); | |||
2451 | if (!NewVTPSD) | |||
2452 | break; | |||
2453 | VTPSD = NewVTPSD; | |||
2454 | } | |||
2455 | return getDefinitionOrSelf<VarDecl>(VTPSD); | |||
2456 | } | |||
2457 | } | |||
2458 | } | |||
2459 | ||||
2460 | // If this is the pattern of a variable template, find where it was | |||
2461 | // instantiated from. FIXME: Is this necessary? | |||
2462 | if (VarTemplateDecl *VarTemplate = VD->getDescribedVarTemplate()) { | |||
2463 | while (!VarTemplate->isMemberSpecialization()) { | |||
2464 | auto *NewVT = VarTemplate->getInstantiatedFromMemberTemplate(); | |||
2465 | if (!NewVT) | |||
2466 | break; | |||
2467 | VarTemplate = NewVT; | |||
2468 | } | |||
2469 | ||||
2470 | return getDefinitionOrSelf(VarTemplate->getTemplatedDecl()); | |||
2471 | } | |||
2472 | ||||
2473 | if (VD == this) | |||
2474 | return nullptr; | |||
2475 | return getDefinitionOrSelf(const_cast<VarDecl*>(VD)); | |||
2476 | } | |||
2477 | ||||
2478 | VarDecl *VarDecl::getInstantiatedFromStaticDataMember() const { | |||
2479 | if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) | |||
2480 | return cast<VarDecl>(MSI->getInstantiatedFrom()); | |||
2481 | ||||
2482 | return nullptr; | |||
2483 | } | |||
2484 | ||||
2485 | TemplateSpecializationKind VarDecl::getTemplateSpecializationKind() const { | |||
2486 | if (const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(this)) | |||
2487 | return Spec->getSpecializationKind(); | |||
2488 | ||||
2489 | if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) | |||
2490 | return MSI->getTemplateSpecializationKind(); | |||
2491 | ||||
2492 | return TSK_Undeclared; | |||
2493 | } | |||
2494 | ||||
2495 | TemplateSpecializationKind | |||
2496 | VarDecl::getTemplateSpecializationKindForInstantiation() const { | |||
2497 | if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) | |||
2498 | return MSI->getTemplateSpecializationKind(); | |||
2499 | ||||
2500 | if (const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(this)) | |||
2501 | return Spec->getSpecializationKind(); | |||
2502 | ||||
2503 | return TSK_Undeclared; | |||
2504 | } | |||
2505 | ||||
2506 | SourceLocation VarDecl::getPointOfInstantiation() const { | |||
2507 | if (const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(this)) | |||
2508 | return Spec->getPointOfInstantiation(); | |||
2509 | ||||
2510 | if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) | |||
2511 | return MSI->getPointOfInstantiation(); | |||
2512 | ||||
2513 | return SourceLocation(); | |||
2514 | } | |||
2515 | ||||
2516 | VarTemplateDecl *VarDecl::getDescribedVarTemplate() const { | |||
2517 | return getASTContext().getTemplateOrSpecializationInfo(this) | |||
2518 | .dyn_cast<VarTemplateDecl *>(); | |||
2519 | } | |||
2520 | ||||
2521 | void VarDecl::setDescribedVarTemplate(VarTemplateDecl *Template) { | |||
2522 | getASTContext().setTemplateOrSpecializationInfo(this, Template); | |||
2523 | } | |||
2524 | ||||
2525 | bool VarDecl::isKnownToBeDefined() const { | |||
2526 | const auto &LangOpts = getASTContext().getLangOpts(); | |||
2527 | // In CUDA mode without relocatable device code, variables of form 'extern | |||
2528 | // __shared__ Foo foo[]' are pointers to the base of the GPU core's shared | |||
2529 | // memory pool. These are never undefined variables, even if they appear | |||
2530 | // inside of an anon namespace or static function. | |||
2531 | // | |||
2532 | // With CUDA relocatable device code enabled, these variables don't get | |||
2533 | // special handling; they're treated like regular extern variables. | |||
2534 | if (LangOpts.CUDA && !LangOpts.GPURelocatableDeviceCode && | |||
2535 | hasExternalStorage() && hasAttr<CUDASharedAttr>() && | |||
2536 | isa<IncompleteArrayType>(getType())) | |||
2537 | return true; | |||
2538 | ||||
2539 | return hasDefinition(); | |||
2540 | } | |||
2541 | ||||
2542 | bool VarDecl::isNoDestroy(const ASTContext &Ctx) const { | |||
2543 | return hasGlobalStorage() && (hasAttr<NoDestroyAttr>() || | |||
2544 | (!Ctx.getLangOpts().RegisterStaticDestructors && | |||
2545 | !hasAttr<AlwaysDestroyAttr>())); | |||
2546 | } | |||
2547 | ||||
2548 | MemberSpecializationInfo *VarDecl::getMemberSpecializationInfo() const { | |||
2549 | if (isStaticDataMember()) | |||
2550 | // FIXME: Remove ? | |||
2551 | // return getASTContext().getInstantiatedFromStaticDataMember(this); | |||
2552 | return getASTContext().getTemplateOrSpecializationInfo(this) | |||
2553 | .dyn_cast<MemberSpecializationInfo *>(); | |||
2554 | return nullptr; | |||
2555 | } | |||
2556 | ||||
2557 | void VarDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK, | |||
2558 | SourceLocation PointOfInstantiation) { | |||
2559 | assert((isa<VarTemplateSpecializationDecl>(this) ||(((isa<VarTemplateSpecializationDecl>(this) || getMemberSpecializationInfo ()) && "not a variable or static data member template specialization" ) ? static_cast<void> (0) : __assert_fail ("(isa<VarTemplateSpecializationDecl>(this) || getMemberSpecializationInfo()) && \"not a variable or static data member template specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2561, __PRETTY_FUNCTION__)) | |||
2560 | getMemberSpecializationInfo()) &&(((isa<VarTemplateSpecializationDecl>(this) || getMemberSpecializationInfo ()) && "not a variable or static data member template specialization" ) ? static_cast<void> (0) : __assert_fail ("(isa<VarTemplateSpecializationDecl>(this) || getMemberSpecializationInfo()) && \"not a variable or static data member template specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2561, __PRETTY_FUNCTION__)) | |||
2561 | "not a variable or static data member template specialization")(((isa<VarTemplateSpecializationDecl>(this) || getMemberSpecializationInfo ()) && "not a variable or static data member template specialization" ) ? static_cast<void> (0) : __assert_fail ("(isa<VarTemplateSpecializationDecl>(this) || getMemberSpecializationInfo()) && \"not a variable or static data member template specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2561, __PRETTY_FUNCTION__)); | |||
2562 | ||||
2563 | if (VarTemplateSpecializationDecl *Spec = | |||
2564 | dyn_cast<VarTemplateSpecializationDecl>(this)) { | |||
2565 | Spec->setSpecializationKind(TSK); | |||
2566 | if (TSK != TSK_ExplicitSpecialization && | |||
2567 | PointOfInstantiation.isValid() && | |||
2568 | Spec->getPointOfInstantiation().isInvalid()) { | |||
2569 | Spec->setPointOfInstantiation(PointOfInstantiation); | |||
2570 | if (ASTMutationListener *L = getASTContext().getASTMutationListener()) | |||
2571 | L->InstantiationRequested(this); | |||
2572 | } | |||
2573 | } else if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) { | |||
2574 | MSI->setTemplateSpecializationKind(TSK); | |||
2575 | if (TSK != TSK_ExplicitSpecialization && PointOfInstantiation.isValid() && | |||
2576 | MSI->getPointOfInstantiation().isInvalid()) { | |||
2577 | MSI->setPointOfInstantiation(PointOfInstantiation); | |||
2578 | if (ASTMutationListener *L = getASTContext().getASTMutationListener()) | |||
2579 | L->InstantiationRequested(this); | |||
2580 | } | |||
2581 | } | |||
2582 | } | |||
2583 | ||||
2584 | void | |||
2585 | VarDecl::setInstantiationOfStaticDataMember(VarDecl *VD, | |||
2586 | TemplateSpecializationKind TSK) { | |||
2587 | assert(getASTContext().getTemplateOrSpecializationInfo(this).isNull() &&((getASTContext().getTemplateOrSpecializationInfo(this).isNull () && "Previous template or instantiation?") ? static_cast <void> (0) : __assert_fail ("getASTContext().getTemplateOrSpecializationInfo(this).isNull() && \"Previous template or instantiation?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2588, __PRETTY_FUNCTION__)) | |||
2588 | "Previous template or instantiation?")((getASTContext().getTemplateOrSpecializationInfo(this).isNull () && "Previous template or instantiation?") ? static_cast <void> (0) : __assert_fail ("getASTContext().getTemplateOrSpecializationInfo(this).isNull() && \"Previous template or instantiation?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2588, __PRETTY_FUNCTION__)); | |||
2589 | getASTContext().setInstantiatedFromStaticDataMember(this, VD, TSK); | |||
2590 | } | |||
2591 | ||||
2592 | //===----------------------------------------------------------------------===// | |||
2593 | // ParmVarDecl Implementation | |||
2594 | //===----------------------------------------------------------------------===// | |||
2595 | ||||
2596 | ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, | |||
2597 | SourceLocation StartLoc, | |||
2598 | SourceLocation IdLoc, IdentifierInfo *Id, | |||
2599 | QualType T, TypeSourceInfo *TInfo, | |||
2600 | StorageClass S, Expr *DefArg) { | |||
2601 | return new (C, DC) ParmVarDecl(ParmVar, C, DC, StartLoc, IdLoc, Id, T, TInfo, | |||
2602 | S, DefArg); | |||
2603 | } | |||
2604 | ||||
2605 | QualType ParmVarDecl::getOriginalType() const { | |||
2606 | TypeSourceInfo *TSI = getTypeSourceInfo(); | |||
2607 | QualType T = TSI ? TSI->getType() : getType(); | |||
2608 | if (const auto *DT = dyn_cast<DecayedType>(T)) | |||
2609 | return DT->getOriginalType(); | |||
2610 | return T; | |||
2611 | } | |||
2612 | ||||
2613 | ParmVarDecl *ParmVarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2614 | return new (C, ID) | |||
2615 | ParmVarDecl(ParmVar, C, nullptr, SourceLocation(), SourceLocation(), | |||
2616 | nullptr, QualType(), nullptr, SC_None, nullptr); | |||
2617 | } | |||
2618 | ||||
2619 | SourceRange ParmVarDecl::getSourceRange() const { | |||
2620 | if (!hasInheritedDefaultArg()) { | |||
2621 | SourceRange ArgRange = getDefaultArgRange(); | |||
2622 | if (ArgRange.isValid()) | |||
2623 | return SourceRange(getOuterLocStart(), ArgRange.getEnd()); | |||
2624 | } | |||
2625 | ||||
2626 | // DeclaratorDecl considers the range of postfix types as overlapping with the | |||
2627 | // declaration name, but this is not the case with parameters in ObjC methods. | |||
2628 | if (isa<ObjCMethodDecl>(getDeclContext())) | |||
2629 | return SourceRange(DeclaratorDecl::getBeginLoc(), getLocation()); | |||
2630 | ||||
2631 | return DeclaratorDecl::getSourceRange(); | |||
2632 | } | |||
2633 | ||||
2634 | Expr *ParmVarDecl::getDefaultArg() { | |||
2635 | assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!")((!hasUnparsedDefaultArg() && "Default argument is not yet parsed!" ) ? static_cast<void> (0) : __assert_fail ("!hasUnparsedDefaultArg() && \"Default argument is not yet parsed!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2635, __PRETTY_FUNCTION__)); | |||
2636 | assert(!hasUninstantiatedDefaultArg() &&((!hasUninstantiatedDefaultArg() && "Default argument is not yet instantiated!" ) ? static_cast<void> (0) : __assert_fail ("!hasUninstantiatedDefaultArg() && \"Default argument is not yet instantiated!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2637, __PRETTY_FUNCTION__)) | |||
2637 | "Default argument is not yet instantiated!")((!hasUninstantiatedDefaultArg() && "Default argument is not yet instantiated!" ) ? static_cast<void> (0) : __assert_fail ("!hasUninstantiatedDefaultArg() && \"Default argument is not yet instantiated!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2637, __PRETTY_FUNCTION__)); | |||
2638 | ||||
2639 | Expr *Arg = getInit(); | |||
2640 | if (auto *E = dyn_cast_or_null<FullExpr>(Arg)) | |||
2641 | return E->getSubExpr(); | |||
2642 | ||||
2643 | return Arg; | |||
2644 | } | |||
2645 | ||||
2646 | void ParmVarDecl::setDefaultArg(Expr *defarg) { | |||
2647 | ParmVarDeclBits.DefaultArgKind = DAK_Normal; | |||
2648 | Init = defarg; | |||
2649 | } | |||
2650 | ||||
2651 | SourceRange ParmVarDecl::getDefaultArgRange() const { | |||
2652 | switch (ParmVarDeclBits.DefaultArgKind) { | |||
2653 | case DAK_None: | |||
2654 | case DAK_Unparsed: | |||
2655 | // Nothing we can do here. | |||
2656 | return SourceRange(); | |||
2657 | ||||
2658 | case DAK_Uninstantiated: | |||
2659 | return getUninstantiatedDefaultArg()->getSourceRange(); | |||
2660 | ||||
2661 | case DAK_Normal: | |||
2662 | if (const Expr *E = getInit()) | |||
2663 | return E->getSourceRange(); | |||
2664 | ||||
2665 | // Missing an actual expression, may be invalid. | |||
2666 | return SourceRange(); | |||
2667 | } | |||
2668 | llvm_unreachable("Invalid default argument kind.")::llvm::llvm_unreachable_internal("Invalid default argument kind." , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2668); | |||
2669 | } | |||
2670 | ||||
2671 | void ParmVarDecl::setUninstantiatedDefaultArg(Expr *arg) { | |||
2672 | ParmVarDeclBits.DefaultArgKind = DAK_Uninstantiated; | |||
2673 | Init = arg; | |||
2674 | } | |||
2675 | ||||
2676 | Expr *ParmVarDecl::getUninstantiatedDefaultArg() { | |||
2677 | assert(hasUninstantiatedDefaultArg() &&((hasUninstantiatedDefaultArg() && "Wrong kind of initialization expression!" ) ? static_cast<void> (0) : __assert_fail ("hasUninstantiatedDefaultArg() && \"Wrong kind of initialization expression!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2678, __PRETTY_FUNCTION__)) | |||
2678 | "Wrong kind of initialization expression!")((hasUninstantiatedDefaultArg() && "Wrong kind of initialization expression!" ) ? static_cast<void> (0) : __assert_fail ("hasUninstantiatedDefaultArg() && \"Wrong kind of initialization expression!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2678, __PRETTY_FUNCTION__)); | |||
2679 | return cast_or_null<Expr>(Init.get<Stmt *>()); | |||
2680 | } | |||
2681 | ||||
2682 | bool ParmVarDecl::hasDefaultArg() const { | |||
2683 | // FIXME: We should just return false for DAK_None here once callers are | |||
2684 | // prepared for the case that we encountered an invalid default argument and | |||
2685 | // were unable to even build an invalid expression. | |||
2686 | return hasUnparsedDefaultArg() || hasUninstantiatedDefaultArg() || | |||
2687 | !Init.isNull(); | |||
2688 | } | |||
2689 | ||||
2690 | void ParmVarDecl::setParameterIndexLarge(unsigned parameterIndex) { | |||
2691 | getASTContext().setParameterIndex(this, parameterIndex); | |||
2692 | ParmVarDeclBits.ParameterIndex = ParameterIndexSentinel; | |||
2693 | } | |||
2694 | ||||
2695 | unsigned ParmVarDecl::getParameterIndexLarge() const { | |||
2696 | return getASTContext().getParameterIndex(this); | |||
2697 | } | |||
2698 | ||||
2699 | //===----------------------------------------------------------------------===// | |||
2700 | // FunctionDecl Implementation | |||
2701 | //===----------------------------------------------------------------------===// | |||
2702 | ||||
2703 | FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, | |||
2704 | SourceLocation StartLoc, | |||
2705 | const DeclarationNameInfo &NameInfo, QualType T, | |||
2706 | TypeSourceInfo *TInfo, StorageClass S, | |||
2707 | bool isInlineSpecified, bool isConstexprSpecified) | |||
2708 | : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo, | |||
2709 | StartLoc), | |||
2710 | DeclContext(DK), redeclarable_base(C), ODRHash(0), | |||
2711 | EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) { | |||
2712 | assert(T.isNull() || T->isFunctionType())((T.isNull() || T->isFunctionType()) ? static_cast<void > (0) : __assert_fail ("T.isNull() || T->isFunctionType()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2712, __PRETTY_FUNCTION__)); | |||
2713 | FunctionDeclBits.SClass = S; | |||
2714 | FunctionDeclBits.IsInline = isInlineSpecified; | |||
2715 | FunctionDeclBits.IsInlineSpecified = isInlineSpecified; | |||
2716 | FunctionDeclBits.IsVirtualAsWritten = false; | |||
2717 | FunctionDeclBits.IsPure = false; | |||
2718 | FunctionDeclBits.HasInheritedPrototype = false; | |||
2719 | FunctionDeclBits.HasWrittenPrototype = true; | |||
2720 | FunctionDeclBits.IsDeleted = false; | |||
2721 | FunctionDeclBits.IsTrivial = false; | |||
2722 | FunctionDeclBits.IsTrivialForCall = false; | |||
2723 | FunctionDeclBits.IsDefaulted = false; | |||
2724 | FunctionDeclBits.IsExplicitlyDefaulted = false; | |||
2725 | FunctionDeclBits.HasImplicitReturnZero = false; | |||
2726 | FunctionDeclBits.IsLateTemplateParsed = false; | |||
2727 | FunctionDeclBits.IsConstexpr = isConstexprSpecified; | |||
2728 | FunctionDeclBits.InstantiationIsPending = false; | |||
2729 | FunctionDeclBits.UsesSEHTry = false; | |||
2730 | FunctionDeclBits.HasSkippedBody = false; | |||
2731 | FunctionDeclBits.WillHaveBody = false; | |||
2732 | FunctionDeclBits.IsMultiVersion = false; | |||
2733 | FunctionDeclBits.IsCopyDeductionCandidate = false; | |||
2734 | FunctionDeclBits.HasODRHash = false; | |||
2735 | } | |||
2736 | ||||
2737 | void FunctionDecl::getNameForDiagnostic( | |||
2738 | raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const { | |||
2739 | NamedDecl::getNameForDiagnostic(OS, Policy, Qualified); | |||
2740 | const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs(); | |||
2741 | if (TemplateArgs) | |||
2742 | printTemplateArgumentList(OS, TemplateArgs->asArray(), Policy); | |||
2743 | } | |||
2744 | ||||
2745 | bool FunctionDecl::isVariadic() const { | |||
2746 | if (const auto *FT = getType()->getAs<FunctionProtoType>()) | |||
2747 | return FT->isVariadic(); | |||
2748 | return false; | |||
2749 | } | |||
2750 | ||||
2751 | bool FunctionDecl::hasBody(const FunctionDecl *&Definition) const { | |||
2752 | for (auto I : redecls()) { | |||
2753 | if (I->doesThisDeclarationHaveABody()) { | |||
2754 | Definition = I; | |||
2755 | return true; | |||
2756 | } | |||
2757 | } | |||
2758 | ||||
2759 | return false; | |||
2760 | } | |||
2761 | ||||
2762 | bool FunctionDecl::hasTrivialBody() const | |||
2763 | { | |||
2764 | Stmt *S = getBody(); | |||
2765 | if (!S) { | |||
2766 | // Since we don't have a body for this function, we don't know if it's | |||
2767 | // trivial or not. | |||
2768 | return false; | |||
2769 | } | |||
2770 | ||||
2771 | if (isa<CompoundStmt>(S) && cast<CompoundStmt>(S)->body_empty()) | |||
2772 | return true; | |||
2773 | return false; | |||
2774 | } | |||
2775 | ||||
2776 | bool FunctionDecl::isDefined(const FunctionDecl *&Definition) const { | |||
2777 | for (auto I : redecls()) { | |||
2778 | if (I->isThisDeclarationADefinition()) { | |||
2779 | Definition = I; | |||
2780 | return true; | |||
2781 | } | |||
2782 | } | |||
2783 | ||||
2784 | return false; | |||
2785 | } | |||
2786 | ||||
2787 | Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const { | |||
2788 | if (!hasBody(Definition)) | |||
2789 | return nullptr; | |||
2790 | ||||
2791 | if (Definition->Body) | |||
2792 | return Definition->Body.get(getASTContext().getExternalSource()); | |||
2793 | ||||
2794 | return nullptr; | |||
2795 | } | |||
2796 | ||||
2797 | void FunctionDecl::setBody(Stmt *B) { | |||
2798 | Body = B; | |||
2799 | if (B) | |||
2800 | EndRangeLoc = B->getEndLoc(); | |||
2801 | } | |||
2802 | ||||
2803 | void FunctionDecl::setPure(bool P) { | |||
2804 | FunctionDeclBits.IsPure = P; | |||
2805 | if (P) | |||
2806 | if (auto *Parent = dyn_cast<CXXRecordDecl>(getDeclContext())) | |||
2807 | Parent->markedVirtualFunctionPure(); | |||
2808 | } | |||
2809 | ||||
2810 | template<std::size_t Len> | |||
2811 | static bool isNamed(const NamedDecl *ND, const char (&Str)[Len]) { | |||
2812 | IdentifierInfo *II = ND->getIdentifier(); | |||
2813 | return II && II->isStr(Str); | |||
2814 | } | |||
2815 | ||||
2816 | bool FunctionDecl::isMain() const { | |||
2817 | const TranslationUnitDecl *tunit = | |||
2818 | dyn_cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext()); | |||
2819 | return tunit && | |||
2820 | !tunit->getASTContext().getLangOpts().Freestanding && | |||
2821 | isNamed(this, "main"); | |||
2822 | } | |||
2823 | ||||
2824 | bool FunctionDecl::isMSVCRTEntryPoint() const { | |||
2825 | const TranslationUnitDecl *TUnit = | |||
2826 | dyn_cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext()); | |||
2827 | if (!TUnit) | |||
2828 | return false; | |||
2829 | ||||
2830 | // Even though we aren't really targeting MSVCRT if we are freestanding, | |||
2831 | // semantic analysis for these functions remains the same. | |||
2832 | ||||
2833 | // MSVCRT entry points only exist on MSVCRT targets. | |||
2834 | if (!TUnit->getASTContext().getTargetInfo().getTriple().isOSMSVCRT()) | |||
2835 | return false; | |||
2836 | ||||
2837 | // Nameless functions like constructors cannot be entry points. | |||
2838 | if (!getIdentifier()) | |||
2839 | return false; | |||
2840 | ||||
2841 | return llvm::StringSwitch<bool>(getName()) | |||
2842 | .Cases("main", // an ANSI console app | |||
2843 | "wmain", // a Unicode console App | |||
2844 | "WinMain", // an ANSI GUI app | |||
2845 | "wWinMain", // a Unicode GUI app | |||
2846 | "DllMain", // a DLL | |||
2847 | true) | |||
2848 | .Default(false); | |||
2849 | } | |||
2850 | ||||
2851 | bool FunctionDecl::isReservedGlobalPlacementOperator() const { | |||
2852 | assert(getDeclName().getNameKind() == DeclarationName::CXXOperatorName)((getDeclName().getNameKind() == DeclarationName::CXXOperatorName ) ? static_cast<void> (0) : __assert_fail ("getDeclName().getNameKind() == DeclarationName::CXXOperatorName" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2852, __PRETTY_FUNCTION__)); | |||
2853 | assert(getDeclName().getCXXOverloadedOperator() == OO_New ||((getDeclName().getCXXOverloadedOperator() == OO_New || getDeclName ().getCXXOverloadedOperator() == OO_Delete || getDeclName().getCXXOverloadedOperator () == OO_Array_New || getDeclName().getCXXOverloadedOperator( ) == OO_Array_Delete) ? static_cast<void> (0) : __assert_fail ("getDeclName().getCXXOverloadedOperator() == OO_New || getDeclName().getCXXOverloadedOperator() == OO_Delete || getDeclName().getCXXOverloadedOperator() == OO_Array_New || getDeclName().getCXXOverloadedOperator() == OO_Array_Delete" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2856, __PRETTY_FUNCTION__)) | |||
2854 | getDeclName().getCXXOverloadedOperator() == OO_Delete ||((getDeclName().getCXXOverloadedOperator() == OO_New || getDeclName ().getCXXOverloadedOperator() == OO_Delete || getDeclName().getCXXOverloadedOperator () == OO_Array_New || getDeclName().getCXXOverloadedOperator( ) == OO_Array_Delete) ? static_cast<void> (0) : __assert_fail ("getDeclName().getCXXOverloadedOperator() == OO_New || getDeclName().getCXXOverloadedOperator() == OO_Delete || getDeclName().getCXXOverloadedOperator() == OO_Array_New || getDeclName().getCXXOverloadedOperator() == OO_Array_Delete" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2856, __PRETTY_FUNCTION__)) | |||
2855 | getDeclName().getCXXOverloadedOperator() == OO_Array_New ||((getDeclName().getCXXOverloadedOperator() == OO_New || getDeclName ().getCXXOverloadedOperator() == OO_Delete || getDeclName().getCXXOverloadedOperator () == OO_Array_New || getDeclName().getCXXOverloadedOperator( ) == OO_Array_Delete) ? static_cast<void> (0) : __assert_fail ("getDeclName().getCXXOverloadedOperator() == OO_New || getDeclName().getCXXOverloadedOperator() == OO_Delete || getDeclName().getCXXOverloadedOperator() == OO_Array_New || getDeclName().getCXXOverloadedOperator() == OO_Array_Delete" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2856, __PRETTY_FUNCTION__)) | |||
2856 | getDeclName().getCXXOverloadedOperator() == OO_Array_Delete)((getDeclName().getCXXOverloadedOperator() == OO_New || getDeclName ().getCXXOverloadedOperator() == OO_Delete || getDeclName().getCXXOverloadedOperator () == OO_Array_New || getDeclName().getCXXOverloadedOperator( ) == OO_Array_Delete) ? static_cast<void> (0) : __assert_fail ("getDeclName().getCXXOverloadedOperator() == OO_New || getDeclName().getCXXOverloadedOperator() == OO_Delete || getDeclName().getCXXOverloadedOperator() == OO_Array_New || getDeclName().getCXXOverloadedOperator() == OO_Array_Delete" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 2856, __PRETTY_FUNCTION__)); | |||
2857 | ||||
2858 | if (!getDeclContext()->getRedeclContext()->isTranslationUnit()) | |||
2859 | return false; | |||
2860 | ||||
2861 | const auto *proto = getType()->castAs<FunctionProtoType>(); | |||
2862 | if (proto->getNumParams() != 2 || proto->isVariadic()) | |||
2863 | return false; | |||
2864 | ||||
2865 | ASTContext &Context = | |||
2866 | cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext()) | |||
2867 | ->getASTContext(); | |||
2868 | ||||
2869 | // The result type and first argument type are constant across all | |||
2870 | // these operators. The second argument must be exactly void*. | |||
2871 | return (proto->getParamType(1).getCanonicalType() == Context.VoidPtrTy); | |||
2872 | } | |||
2873 | ||||
2874 | bool FunctionDecl::isReplaceableGlobalAllocationFunction(bool *IsAligned) const { | |||
2875 | if (getDeclName().getNameKind() != DeclarationName::CXXOperatorName) | |||
2876 | return false; | |||
2877 | if (getDeclName().getCXXOverloadedOperator() != OO_New && | |||
2878 | getDeclName().getCXXOverloadedOperator() != OO_Delete && | |||
2879 | getDeclName().getCXXOverloadedOperator() != OO_Array_New && | |||
2880 | getDeclName().getCXXOverloadedOperator() != OO_Array_Delete) | |||
2881 | return false; | |||
2882 | ||||
2883 | if (isa<CXXRecordDecl>(getDeclContext())) | |||
2884 | return false; | |||
2885 | ||||
2886 | // This can only fail for an invalid 'operator new' declaration. | |||
2887 | if (!getDeclContext()->getRedeclContext()->isTranslationUnit()) | |||
2888 | return false; | |||
2889 | ||||
2890 | const auto *FPT = getType()->castAs<FunctionProtoType>(); | |||
2891 | if (FPT->getNumParams() == 0 || FPT->getNumParams() > 3 || FPT->isVariadic()) | |||
2892 | return false; | |||
2893 | ||||
2894 | // If this is a single-parameter function, it must be a replaceable global | |||
2895 | // allocation or deallocation function. | |||
2896 | if (FPT->getNumParams() == 1) | |||
2897 | return true; | |||
2898 | ||||
2899 | unsigned Params = 1; | |||
2900 | QualType Ty = FPT->getParamType(Params); | |||
2901 | ASTContext &Ctx = getASTContext(); | |||
2902 | ||||
2903 | auto Consume = [&] { | |||
2904 | ++Params; | |||
2905 | Ty = Params < FPT->getNumParams() ? FPT->getParamType(Params) : QualType(); | |||
2906 | }; | |||
2907 | ||||
2908 | // In C++14, the next parameter can be a 'std::size_t' for sized delete. | |||
2909 | bool IsSizedDelete = false; | |||
2910 | if (Ctx.getLangOpts().SizedDeallocation && | |||
2911 | (getDeclName().getCXXOverloadedOperator() == OO_Delete || | |||
2912 | getDeclName().getCXXOverloadedOperator() == OO_Array_Delete) && | |||
2913 | Ctx.hasSameType(Ty, Ctx.getSizeType())) { | |||
2914 | IsSizedDelete = true; | |||
2915 | Consume(); | |||
2916 | } | |||
2917 | ||||
2918 | // In C++17, the next parameter can be a 'std::align_val_t' for aligned | |||
2919 | // new/delete. | |||
2920 | if (Ctx.getLangOpts().AlignedAllocation && !Ty.isNull() && Ty->isAlignValT()) { | |||
2921 | if (IsAligned) | |||
2922 | *IsAligned = true; | |||
2923 | Consume(); | |||
2924 | } | |||
2925 | ||||
2926 | // Finally, if this is not a sized delete, the final parameter can | |||
2927 | // be a 'const std::nothrow_t&'. | |||
2928 | if (!IsSizedDelete && !Ty.isNull() && Ty->isReferenceType()) { | |||
2929 | Ty = Ty->getPointeeType(); | |||
2930 | if (Ty.getCVRQualifiers() != Qualifiers::Const) | |||
2931 | return false; | |||
2932 | const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); | |||
2933 | if (RD && isNamed(RD, "nothrow_t") && RD->isInStdNamespace()) | |||
2934 | Consume(); | |||
2935 | } | |||
2936 | ||||
2937 | return Params == FPT->getNumParams(); | |||
2938 | } | |||
2939 | ||||
2940 | bool FunctionDecl::isDestroyingOperatorDelete() const { | |||
2941 | // C++ P0722: | |||
2942 | // Within a class C, a single object deallocation function with signature | |||
2943 | // (T, std::destroying_delete_t, <more params>) | |||
2944 | // is a destroying operator delete. | |||
2945 | if (!isa<CXXMethodDecl>(this) || getOverloadedOperator() != OO_Delete || | |||
2946 | getNumParams() < 2) | |||
2947 | return false; | |||
2948 | ||||
2949 | auto *RD = getParamDecl(1)->getType()->getAsCXXRecordDecl(); | |||
2950 | return RD && RD->isInStdNamespace() && RD->getIdentifier() && | |||
2951 | RD->getIdentifier()->isStr("destroying_delete_t"); | |||
2952 | } | |||
2953 | ||||
2954 | LanguageLinkage FunctionDecl::getLanguageLinkage() const { | |||
2955 | return getDeclLanguageLinkage(*this); | |||
2956 | } | |||
2957 | ||||
2958 | bool FunctionDecl::isExternC() const { | |||
2959 | return isDeclExternC(*this); | |||
2960 | } | |||
2961 | ||||
2962 | bool FunctionDecl::isInExternCContext() const { | |||
2963 | if (hasAttr<OpenCLKernelAttr>()) | |||
2964 | return true; | |||
2965 | return getLexicalDeclContext()->isExternCContext(); | |||
2966 | } | |||
2967 | ||||
2968 | bool FunctionDecl::isInExternCXXContext() const { | |||
2969 | return getLexicalDeclContext()->isExternCXXContext(); | |||
2970 | } | |||
2971 | ||||
2972 | bool FunctionDecl::isGlobal() const { | |||
2973 | if (const auto *Method = dyn_cast<CXXMethodDecl>(this)) | |||
2974 | return Method->isStatic(); | |||
2975 | ||||
2976 | if (getCanonicalDecl()->getStorageClass() == SC_Static) | |||
2977 | return false; | |||
2978 | ||||
2979 | for (const DeclContext *DC = getDeclContext(); | |||
2980 | DC->isNamespace(); | |||
2981 | DC = DC->getParent()) { | |||
2982 | if (const auto *Namespace = cast<NamespaceDecl>(DC)) { | |||
2983 | if (!Namespace->getDeclName()) | |||
2984 | return false; | |||
2985 | break; | |||
2986 | } | |||
2987 | } | |||
2988 | ||||
2989 | return true; | |||
2990 | } | |||
2991 | ||||
2992 | bool FunctionDecl::isNoReturn() const { | |||
2993 | if (hasAttr<NoReturnAttr>() || hasAttr<CXX11NoReturnAttr>() || | |||
2994 | hasAttr<C11NoReturnAttr>()) | |||
2995 | return true; | |||
2996 | ||||
2997 | if (auto *FnTy = getType()->getAs<FunctionType>()) | |||
2998 | return FnTy->getNoReturnAttr(); | |||
2999 | ||||
3000 | return false; | |||
3001 | } | |||
3002 | ||||
3003 | ||||
3004 | MultiVersionKind FunctionDecl::getMultiVersionKind() const { | |||
3005 | if (hasAttr<TargetAttr>()) | |||
3006 | return MultiVersionKind::Target; | |||
3007 | if (hasAttr<CPUDispatchAttr>()) | |||
3008 | return MultiVersionKind::CPUDispatch; | |||
3009 | if (hasAttr<CPUSpecificAttr>()) | |||
3010 | return MultiVersionKind::CPUSpecific; | |||
3011 | return MultiVersionKind::None; | |||
3012 | } | |||
3013 | ||||
3014 | bool FunctionDecl::isCPUDispatchMultiVersion() const { | |||
3015 | return isMultiVersion() && hasAttr<CPUDispatchAttr>(); | |||
3016 | } | |||
3017 | ||||
3018 | bool FunctionDecl::isCPUSpecificMultiVersion() const { | |||
3019 | return isMultiVersion() && hasAttr<CPUSpecificAttr>(); | |||
3020 | } | |||
3021 | ||||
3022 | bool FunctionDecl::isTargetMultiVersion() const { | |||
3023 | return isMultiVersion() && hasAttr<TargetAttr>(); | |||
3024 | } | |||
3025 | ||||
3026 | void | |||
3027 | FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) { | |||
3028 | redeclarable_base::setPreviousDecl(PrevDecl); | |||
3029 | ||||
3030 | if (FunctionTemplateDecl *FunTmpl = getDescribedFunctionTemplate()) { | |||
3031 | FunctionTemplateDecl *PrevFunTmpl | |||
3032 | = PrevDecl? PrevDecl->getDescribedFunctionTemplate() : nullptr; | |||
3033 | assert((!PrevDecl || PrevFunTmpl) && "Function/function template mismatch")(((!PrevDecl || PrevFunTmpl) && "Function/function template mismatch" ) ? static_cast<void> (0) : __assert_fail ("(!PrevDecl || PrevFunTmpl) && \"Function/function template mismatch\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3033, __PRETTY_FUNCTION__)); | |||
3034 | FunTmpl->setPreviousDecl(PrevFunTmpl); | |||
3035 | } | |||
3036 | ||||
3037 | if (PrevDecl && PrevDecl->isInlined()) | |||
3038 | setImplicitlyInline(true); | |||
3039 | } | |||
3040 | ||||
3041 | FunctionDecl *FunctionDecl::getCanonicalDecl() { return getFirstDecl(); } | |||
3042 | ||||
3043 | /// Returns a value indicating whether this function corresponds to a builtin | |||
3044 | /// function. | |||
3045 | /// | |||
3046 | /// The function corresponds to a built-in function if it is declared at | |||
3047 | /// translation scope or within an extern "C" block and its name matches with | |||
3048 | /// the name of a builtin. The returned value will be 0 for functions that do | |||
3049 | /// not correspond to a builtin, a value of type \c Builtin::ID if in the | |||
3050 | /// target-independent range \c [1,Builtin::First), or a target-specific builtin | |||
3051 | /// value. | |||
3052 | /// | |||
3053 | /// \param ConsiderWrapperFunctions If true, we should consider wrapper | |||
3054 | /// functions as their wrapped builtins. This shouldn't be done in general, but | |||
3055 | /// it's useful in Sema to diagnose calls to wrappers based on their semantics. | |||
3056 | unsigned FunctionDecl::getBuiltinID(bool ConsiderWrapperFunctions) const { | |||
3057 | if (!getIdentifier()) | |||
3058 | return 0; | |||
3059 | ||||
3060 | unsigned BuiltinID = getIdentifier()->getBuiltinID(); | |||
3061 | if (!BuiltinID) | |||
3062 | return 0; | |||
3063 | ||||
3064 | ASTContext &Context = getASTContext(); | |||
3065 | if (Context.getLangOpts().CPlusPlus) { | |||
3066 | const auto *LinkageDecl = | |||
3067 | dyn_cast<LinkageSpecDecl>(getFirstDecl()->getDeclContext()); | |||
3068 | // In C++, the first declaration of a builtin is always inside an implicit | |||
3069 | // extern "C". | |||
3070 | // FIXME: A recognised library function may not be directly in an extern "C" | |||
3071 | // declaration, for instance "extern "C" { namespace std { decl } }". | |||
3072 | if (!LinkageDecl) { | |||
3073 | if (BuiltinID == Builtin::BI__GetExceptionInfo && | |||
3074 | Context.getTargetInfo().getCXXABI().isMicrosoft()) | |||
3075 | return Builtin::BI__GetExceptionInfo; | |||
3076 | return 0; | |||
3077 | } | |||
3078 | if (LinkageDecl->getLanguage() != LinkageSpecDecl::lang_c) | |||
3079 | return 0; | |||
3080 | } | |||
3081 | ||||
3082 | // If the function is marked "overloadable", it has a different mangled name | |||
3083 | // and is not the C library function. | |||
3084 | if (!ConsiderWrapperFunctions && hasAttr<OverloadableAttr>()) | |||
3085 | return 0; | |||
3086 | ||||
3087 | if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) | |||
3088 | return BuiltinID; | |||
3089 | ||||
3090 | // This function has the name of a known C library | |||
3091 | // function. Determine whether it actually refers to the C library | |||
3092 | // function or whether it just has the same name. | |||
3093 | ||||
3094 | // If this is a static function, it's not a builtin. | |||
3095 | if (!ConsiderWrapperFunctions && getStorageClass() == SC_Static) | |||
3096 | return 0; | |||
3097 | ||||
3098 | // OpenCL v1.2 s6.9.f - The library functions defined in | |||
3099 | // the C99 standard headers are not available. | |||
3100 | if (Context.getLangOpts().OpenCL && | |||
3101 | Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) | |||
3102 | return 0; | |||
3103 | ||||
3104 | // CUDA does not have device-side standard library. printf and malloc are the | |||
3105 | // only special cases that are supported by device-side runtime. | |||
3106 | if (Context.getLangOpts().CUDA && hasAttr<CUDADeviceAttr>() && | |||
3107 | !hasAttr<CUDAHostAttr>() && | |||
3108 | !(BuiltinID == Builtin::BIprintf || BuiltinID == Builtin::BImalloc)) | |||
3109 | return 0; | |||
3110 | ||||
3111 | return BuiltinID; | |||
3112 | } | |||
3113 | ||||
3114 | /// getNumParams - Return the number of parameters this function must have | |||
3115 | /// based on its FunctionType. This is the length of the ParamInfo array | |||
3116 | /// after it has been created. | |||
3117 | unsigned FunctionDecl::getNumParams() const { | |||
3118 | const auto *FPT = getType()->getAs<FunctionProtoType>(); | |||
3119 | return FPT ? FPT->getNumParams() : 0; | |||
3120 | } | |||
3121 | ||||
3122 | void FunctionDecl::setParams(ASTContext &C, | |||
3123 | ArrayRef<ParmVarDecl *> NewParamInfo) { | |||
3124 | assert(!ParamInfo && "Already has param info!")((!ParamInfo && "Already has param info!") ? static_cast <void> (0) : __assert_fail ("!ParamInfo && \"Already has param info!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3124, __PRETTY_FUNCTION__)); | |||
3125 | assert(NewParamInfo.size() == getNumParams() && "Parameter count mismatch!")((NewParamInfo.size() == getNumParams() && "Parameter count mismatch!" ) ? static_cast<void> (0) : __assert_fail ("NewParamInfo.size() == getNumParams() && \"Parameter count mismatch!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3125, __PRETTY_FUNCTION__)); | |||
3126 | ||||
3127 | // Zero params -> null pointer. | |||
3128 | if (!NewParamInfo.empty()) { | |||
3129 | ParamInfo = new (C) ParmVarDecl*[NewParamInfo.size()]; | |||
3130 | std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo); | |||
3131 | } | |||
3132 | } | |||
3133 | ||||
3134 | /// getMinRequiredArguments - Returns the minimum number of arguments | |||
3135 | /// needed to call this function. This may be fewer than the number of | |||
3136 | /// function parameters, if some of the parameters have default | |||
3137 | /// arguments (in C++) or are parameter packs (C++11). | |||
3138 | unsigned FunctionDecl::getMinRequiredArguments() const { | |||
3139 | if (!getASTContext().getLangOpts().CPlusPlus) | |||
3140 | return getNumParams(); | |||
3141 | ||||
3142 | unsigned NumRequiredArgs = 0; | |||
3143 | for (auto *Param : parameters()) | |||
3144 | if (!Param->isParameterPack() && !Param->hasDefaultArg()) | |||
3145 | ++NumRequiredArgs; | |||
3146 | return NumRequiredArgs; | |||
3147 | } | |||
3148 | ||||
3149 | /// The combination of the extern and inline keywords under MSVC forces | |||
3150 | /// the function to be required. | |||
3151 | /// | |||
3152 | /// Note: This function assumes that we will only get called when isInlined() | |||
3153 | /// would return true for this FunctionDecl. | |||
3154 | bool FunctionDecl::isMSExternInline() const { | |||
3155 | assert(isInlined() && "expected to get called on an inlined function!")((isInlined() && "expected to get called on an inlined function!" ) ? static_cast<void> (0) : __assert_fail ("isInlined() && \"expected to get called on an inlined function!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3155, __PRETTY_FUNCTION__)); | |||
3156 | ||||
3157 | const ASTContext &Context = getASTContext(); | |||
3158 | if (!Context.getTargetInfo().getCXXABI().isMicrosoft() && | |||
3159 | !hasAttr<DLLExportAttr>()) | |||
3160 | return false; | |||
3161 | ||||
3162 | for (const FunctionDecl *FD = getMostRecentDecl(); FD; | |||
3163 | FD = FD->getPreviousDecl()) | |||
3164 | if (!FD->isImplicit() && FD->getStorageClass() == SC_Extern) | |||
3165 | return true; | |||
3166 | ||||
3167 | return false; | |||
3168 | } | |||
3169 | ||||
3170 | static bool redeclForcesDefMSVC(const FunctionDecl *Redecl) { | |||
3171 | if (Redecl->getStorageClass() != SC_Extern) | |||
3172 | return false; | |||
3173 | ||||
3174 | for (const FunctionDecl *FD = Redecl->getPreviousDecl(); FD; | |||
3175 | FD = FD->getPreviousDecl()) | |||
3176 | if (!FD->isImplicit() && FD->getStorageClass() == SC_Extern) | |||
3177 | return false; | |||
3178 | ||||
3179 | return true; | |||
3180 | } | |||
3181 | ||||
3182 | static bool RedeclForcesDefC99(const FunctionDecl *Redecl) { | |||
3183 | // Only consider file-scope declarations in this test. | |||
3184 | if (!Redecl->getLexicalDeclContext()->isTranslationUnit()) | |||
3185 | return false; | |||
3186 | ||||
3187 | // Only consider explicit declarations; the presence of a builtin for a | |||
3188 | // libcall shouldn't affect whether a definition is externally visible. | |||
3189 | if (Redecl->isImplicit()) | |||
3190 | return false; | |||
3191 | ||||
3192 | if (!Redecl->isInlineSpecified() || Redecl->getStorageClass() == SC_Extern) | |||
3193 | return true; // Not an inline definition | |||
3194 | ||||
3195 | return false; | |||
3196 | } | |||
3197 | ||||
3198 | /// For a function declaration in C or C++, determine whether this | |||
3199 | /// declaration causes the definition to be externally visible. | |||
3200 | /// | |||
3201 | /// For instance, this determines if adding the current declaration to the set | |||
3202 | /// of redeclarations of the given functions causes | |||
3203 | /// isInlineDefinitionExternallyVisible to change from false to true. | |||
3204 | bool FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const { | |||
3205 | assert(!doesThisDeclarationHaveABody() &&((!doesThisDeclarationHaveABody() && "Must have a declaration without a body." ) ? static_cast<void> (0) : __assert_fail ("!doesThisDeclarationHaveABody() && \"Must have a declaration without a body.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3206, __PRETTY_FUNCTION__)) | |||
3206 | "Must have a declaration without a body.")((!doesThisDeclarationHaveABody() && "Must have a declaration without a body." ) ? static_cast<void> (0) : __assert_fail ("!doesThisDeclarationHaveABody() && \"Must have a declaration without a body.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3206, __PRETTY_FUNCTION__)); | |||
3207 | ||||
3208 | ASTContext &Context = getASTContext(); | |||
3209 | ||||
3210 | if (Context.getLangOpts().MSVCCompat) { | |||
3211 | const FunctionDecl *Definition; | |||
3212 | if (hasBody(Definition) && Definition->isInlined() && | |||
3213 | redeclForcesDefMSVC(this)) | |||
3214 | return true; | |||
3215 | } | |||
3216 | ||||
3217 | if (Context.getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) { | |||
3218 | // With GNU inlining, a declaration with 'inline' but not 'extern', forces | |||
3219 | // an externally visible definition. | |||
3220 | // | |||
3221 | // FIXME: What happens if gnu_inline gets added on after the first | |||
3222 | // declaration? | |||
3223 | if (!isInlineSpecified() || getStorageClass() == SC_Extern) | |||
3224 | return false; | |||
3225 | ||||
3226 | const FunctionDecl *Prev = this; | |||
3227 | bool FoundBody = false; | |||
3228 | while ((Prev = Prev->getPreviousDecl())) { | |||
3229 | FoundBody |= Prev->Body.isValid(); | |||
3230 | ||||
3231 | if (Prev->Body) { | |||
3232 | // If it's not the case that both 'inline' and 'extern' are | |||
3233 | // specified on the definition, then it is always externally visible. | |||
3234 | if (!Prev->isInlineSpecified() || | |||
3235 | Prev->getStorageClass() != SC_Extern) | |||
3236 | return false; | |||
3237 | } else if (Prev->isInlineSpecified() && | |||
3238 | Prev->getStorageClass() != SC_Extern) { | |||
3239 | return false; | |||
3240 | } | |||
3241 | } | |||
3242 | return FoundBody; | |||
3243 | } | |||
3244 | ||||
3245 | if (Context.getLangOpts().CPlusPlus) | |||
3246 | return false; | |||
3247 | ||||
3248 | // C99 6.7.4p6: | |||
3249 | // [...] If all of the file scope declarations for a function in a | |||
3250 | // translation unit include the inline function specifier without extern, | |||
3251 | // then the definition in that translation unit is an inline definition. | |||
3252 | if (isInlineSpecified() && getStorageClass() != SC_Extern) | |||
3253 | return false; | |||
3254 | const FunctionDecl *Prev = this; | |||
3255 | bool FoundBody = false; | |||
3256 | while ((Prev = Prev->getPreviousDecl())) { | |||
3257 | FoundBody |= Prev->Body.isValid(); | |||
3258 | if (RedeclForcesDefC99(Prev)) | |||
3259 | return false; | |||
3260 | } | |||
3261 | return FoundBody; | |||
3262 | } | |||
3263 | ||||
3264 | SourceRange FunctionDecl::getReturnTypeSourceRange() const { | |||
3265 | const TypeSourceInfo *TSI = getTypeSourceInfo(); | |||
3266 | if (!TSI) | |||
3267 | return SourceRange(); | |||
3268 | FunctionTypeLoc FTL = | |||
3269 | TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>(); | |||
3270 | if (!FTL) | |||
3271 | return SourceRange(); | |||
3272 | ||||
3273 | // Skip self-referential return types. | |||
3274 | const SourceManager &SM = getASTContext().getSourceManager(); | |||
3275 | SourceRange RTRange = FTL.getReturnLoc().getSourceRange(); | |||
3276 | SourceLocation Boundary = getNameInfo().getBeginLoc(); | |||
3277 | if (RTRange.isInvalid() || Boundary.isInvalid() || | |||
3278 | !SM.isBeforeInTranslationUnit(RTRange.getEnd(), Boundary)) | |||
3279 | return SourceRange(); | |||
3280 | ||||
3281 | return RTRange; | |||
3282 | } | |||
3283 | ||||
3284 | SourceRange FunctionDecl::getExceptionSpecSourceRange() const { | |||
3285 | const TypeSourceInfo *TSI = getTypeSourceInfo(); | |||
3286 | if (!TSI) | |||
3287 | return SourceRange(); | |||
3288 | FunctionTypeLoc FTL = | |||
3289 | TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>(); | |||
3290 | if (!FTL) | |||
3291 | return SourceRange(); | |||
3292 | ||||
3293 | return FTL.getExceptionSpecRange(); | |||
3294 | } | |||
3295 | ||||
3296 | /// For an inline function definition in C, or for a gnu_inline function | |||
3297 | /// in C++, determine whether the definition will be externally visible. | |||
3298 | /// | |||
3299 | /// Inline function definitions are always available for inlining optimizations. | |||
3300 | /// However, depending on the language dialect, declaration specifiers, and | |||
3301 | /// attributes, the definition of an inline function may or may not be | |||
3302 | /// "externally" visible to other translation units in the program. | |||
3303 | /// | |||
3304 | /// In C99, inline definitions are not externally visible by default. However, | |||
3305 | /// if even one of the global-scope declarations is marked "extern inline", the | |||
3306 | /// inline definition becomes externally visible (C99 6.7.4p6). | |||
3307 | /// | |||
3308 | /// In GNU89 mode, or if the gnu_inline attribute is attached to the function | |||
3309 | /// definition, we use the GNU semantics for inline, which are nearly the | |||
3310 | /// opposite of C99 semantics. In particular, "inline" by itself will create | |||
3311 | /// an externally visible symbol, but "extern inline" will not create an | |||
3312 | /// externally visible symbol. | |||
3313 | bool FunctionDecl::isInlineDefinitionExternallyVisible() const { | |||
3314 | assert((doesThisDeclarationHaveABody() || willHaveBody()) &&(((doesThisDeclarationHaveABody() || willHaveBody()) && "Must be a function definition") ? static_cast<void> ( 0) : __assert_fail ("(doesThisDeclarationHaveABody() || willHaveBody()) && \"Must be a function definition\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3315, __PRETTY_FUNCTION__)) | |||
3315 | "Must be a function definition")(((doesThisDeclarationHaveABody() || willHaveBody()) && "Must be a function definition") ? static_cast<void> ( 0) : __assert_fail ("(doesThisDeclarationHaveABody() || willHaveBody()) && \"Must be a function definition\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3315, __PRETTY_FUNCTION__)); | |||
3316 | assert(isInlined() && "Function must be inline")((isInlined() && "Function must be inline") ? static_cast <void> (0) : __assert_fail ("isInlined() && \"Function must be inline\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3316, __PRETTY_FUNCTION__)); | |||
3317 | ASTContext &Context = getASTContext(); | |||
3318 | ||||
3319 | if (Context.getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) { | |||
3320 | // Note: If you change the logic here, please change | |||
3321 | // doesDeclarationForceExternallyVisibleDefinition as well. | |||
3322 | // | |||
3323 | // If it's not the case that both 'inline' and 'extern' are | |||
3324 | // specified on the definition, then this inline definition is | |||
3325 | // externally visible. | |||
3326 | if (!(isInlineSpecified() && getStorageClass() == SC_Extern)) | |||
3327 | return true; | |||
3328 | ||||
3329 | // If any declaration is 'inline' but not 'extern', then this definition | |||
3330 | // is externally visible. | |||
3331 | for (auto Redecl : redecls()) { | |||
3332 | if (Redecl->isInlineSpecified() && | |||
3333 | Redecl->getStorageClass() != SC_Extern) | |||
3334 | return true; | |||
3335 | } | |||
3336 | ||||
3337 | return false; | |||
3338 | } | |||
3339 | ||||
3340 | // The rest of this function is C-only. | |||
3341 | assert(!Context.getLangOpts().CPlusPlus &&((!Context.getLangOpts().CPlusPlus && "should not use C inline rules in C++" ) ? static_cast<void> (0) : __assert_fail ("!Context.getLangOpts().CPlusPlus && \"should not use C inline rules in C++\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3342, __PRETTY_FUNCTION__)) | |||
3342 | "should not use C inline rules in C++")((!Context.getLangOpts().CPlusPlus && "should not use C inline rules in C++" ) ? static_cast<void> (0) : __assert_fail ("!Context.getLangOpts().CPlusPlus && \"should not use C inline rules in C++\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3342, __PRETTY_FUNCTION__)); | |||
3343 | ||||
3344 | // C99 6.7.4p6: | |||
3345 | // [...] If all of the file scope declarations for a function in a | |||
3346 | // translation unit include the inline function specifier without extern, | |||
3347 | // then the definition in that translation unit is an inline definition. | |||
3348 | for (auto Redecl : redecls()) { | |||
3349 | if (RedeclForcesDefC99(Redecl)) | |||
3350 | return true; | |||
3351 | } | |||
3352 | ||||
3353 | // C99 6.7.4p6: | |||
3354 | // An inline definition does not provide an external definition for the | |||
3355 | // function, and does not forbid an external definition in another | |||
3356 | // translation unit. | |||
3357 | return false; | |||
3358 | } | |||
3359 | ||||
3360 | /// getOverloadedOperator - Which C++ overloaded operator this | |||
3361 | /// function represents, if any. | |||
3362 | OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { | |||
3363 | if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName) | |||
3364 | return getDeclName().getCXXOverloadedOperator(); | |||
3365 | else | |||
3366 | return OO_None; | |||
3367 | } | |||
3368 | ||||
3369 | /// getLiteralIdentifier - The literal suffix identifier this function | |||
3370 | /// represents, if any. | |||
3371 | const IdentifierInfo *FunctionDecl::getLiteralIdentifier() const { | |||
3372 | if (getDeclName().getNameKind() == DeclarationName::CXXLiteralOperatorName) | |||
3373 | return getDeclName().getCXXLiteralIdentifier(); | |||
3374 | else | |||
3375 | return nullptr; | |||
3376 | } | |||
3377 | ||||
3378 | FunctionDecl::TemplatedKind FunctionDecl::getTemplatedKind() const { | |||
3379 | if (TemplateOrSpecialization.isNull()) | |||
3380 | return TK_NonTemplate; | |||
3381 | if (TemplateOrSpecialization.is<FunctionTemplateDecl *>()) | |||
3382 | return TK_FunctionTemplate; | |||
3383 | if (TemplateOrSpecialization.is<MemberSpecializationInfo *>()) | |||
3384 | return TK_MemberSpecialization; | |||
3385 | if (TemplateOrSpecialization.is<FunctionTemplateSpecializationInfo *>()) | |||
3386 | return TK_FunctionTemplateSpecialization; | |||
3387 | if (TemplateOrSpecialization.is | |||
3388 | <DependentFunctionTemplateSpecializationInfo*>()) | |||
3389 | return TK_DependentFunctionTemplateSpecialization; | |||
3390 | ||||
3391 | llvm_unreachable("Did we miss a TemplateOrSpecialization type?")::llvm::llvm_unreachable_internal("Did we miss a TemplateOrSpecialization type?" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3391); | |||
3392 | } | |||
3393 | ||||
3394 | FunctionDecl *FunctionDecl::getInstantiatedFromMemberFunction() const { | |||
3395 | if (MemberSpecializationInfo *Info = getMemberSpecializationInfo()) | |||
3396 | return cast<FunctionDecl>(Info->getInstantiatedFrom()); | |||
3397 | ||||
3398 | return nullptr; | |||
3399 | } | |||
3400 | ||||
3401 | MemberSpecializationInfo *FunctionDecl::getMemberSpecializationInfo() const { | |||
3402 | if (auto *MSI = | |||
3403 | TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>()) | |||
3404 | return MSI; | |||
3405 | if (auto *FTSI = TemplateOrSpecialization | |||
3406 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) | |||
3407 | return FTSI->getMemberSpecializationInfo(); | |||
3408 | return nullptr; | |||
3409 | } | |||
3410 | ||||
3411 | void | |||
3412 | FunctionDecl::setInstantiationOfMemberFunction(ASTContext &C, | |||
3413 | FunctionDecl *FD, | |||
3414 | TemplateSpecializationKind TSK) { | |||
3415 | assert(TemplateOrSpecialization.isNull() &&((TemplateOrSpecialization.isNull() && "Member function is already a specialization" ) ? static_cast<void> (0) : __assert_fail ("TemplateOrSpecialization.isNull() && \"Member function is already a specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3416, __PRETTY_FUNCTION__)) | |||
3416 | "Member function is already a specialization")((TemplateOrSpecialization.isNull() && "Member function is already a specialization" ) ? static_cast<void> (0) : __assert_fail ("TemplateOrSpecialization.isNull() && \"Member function is already a specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3416, __PRETTY_FUNCTION__)); | |||
3417 | MemberSpecializationInfo *Info | |||
3418 | = new (C) MemberSpecializationInfo(FD, TSK); | |||
3419 | TemplateOrSpecialization = Info; | |||
3420 | } | |||
3421 | ||||
3422 | FunctionTemplateDecl *FunctionDecl::getDescribedFunctionTemplate() const { | |||
3423 | return TemplateOrSpecialization.dyn_cast<FunctionTemplateDecl *>(); | |||
3424 | } | |||
3425 | ||||
3426 | void FunctionDecl::setDescribedFunctionTemplate(FunctionTemplateDecl *Template) { | |||
3427 | assert(TemplateOrSpecialization.isNull() &&((TemplateOrSpecialization.isNull() && "Member function is already a specialization" ) ? static_cast<void> (0) : __assert_fail ("TemplateOrSpecialization.isNull() && \"Member function is already a specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3428, __PRETTY_FUNCTION__)) | |||
3428 | "Member function is already a specialization")((TemplateOrSpecialization.isNull() && "Member function is already a specialization" ) ? static_cast<void> (0) : __assert_fail ("TemplateOrSpecialization.isNull() && \"Member function is already a specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3428, __PRETTY_FUNCTION__)); | |||
3429 | TemplateOrSpecialization = Template; | |||
3430 | } | |||
3431 | ||||
3432 | bool FunctionDecl::isImplicitlyInstantiable() const { | |||
3433 | // If the function is invalid, it can't be implicitly instantiated. | |||
3434 | if (isInvalidDecl()) | |||
3435 | return false; | |||
3436 | ||||
3437 | switch (getTemplateSpecializationKindForInstantiation()) { | |||
3438 | case TSK_Undeclared: | |||
3439 | case TSK_ExplicitInstantiationDefinition: | |||
3440 | case TSK_ExplicitSpecialization: | |||
3441 | return false; | |||
3442 | ||||
3443 | case TSK_ImplicitInstantiation: | |||
3444 | return true; | |||
3445 | ||||
3446 | case TSK_ExplicitInstantiationDeclaration: | |||
3447 | // Handled below. | |||
3448 | break; | |||
3449 | } | |||
3450 | ||||
3451 | // Find the actual template from which we will instantiate. | |||
3452 | const FunctionDecl *PatternDecl = getTemplateInstantiationPattern(); | |||
3453 | bool HasPattern = false; | |||
3454 | if (PatternDecl) | |||
3455 | HasPattern = PatternDecl->hasBody(PatternDecl); | |||
3456 | ||||
3457 | // C++0x [temp.explicit]p9: | |||
3458 | // Except for inline functions, other explicit instantiation declarations | |||
3459 | // have the effect of suppressing the implicit instantiation of the entity | |||
3460 | // to which they refer. | |||
3461 | if (!HasPattern || !PatternDecl) | |||
3462 | return true; | |||
3463 | ||||
3464 | return PatternDecl->isInlined(); | |||
3465 | } | |||
3466 | ||||
3467 | bool FunctionDecl::isTemplateInstantiation() const { | |||
3468 | // FIXME: Remove this, it's not clear what it means. (Which template | |||
3469 | // specialization kind?) | |||
3470 | return clang::isTemplateInstantiation(getTemplateSpecializationKind()); | |||
3471 | } | |||
3472 | ||||
3473 | FunctionDecl *FunctionDecl::getTemplateInstantiationPattern() const { | |||
3474 | // If this is a generic lambda call operator specialization, its | |||
3475 | // instantiation pattern is always its primary template's pattern | |||
3476 | // even if its primary template was instantiated from another | |||
3477 | // member template (which happens with nested generic lambdas). | |||
3478 | // Since a lambda's call operator's body is transformed eagerly, | |||
3479 | // we don't have to go hunting for a prototype definition template | |||
3480 | // (i.e. instantiated-from-member-template) to use as an instantiation | |||
3481 | // pattern. | |||
3482 | ||||
3483 | if (isGenericLambdaCallOperatorSpecialization( | |||
3484 | dyn_cast<CXXMethodDecl>(this))) { | |||
3485 | assert(getPrimaryTemplate() && "not a generic lambda call operator?")((getPrimaryTemplate() && "not a generic lambda call operator?" ) ? static_cast<void> (0) : __assert_fail ("getPrimaryTemplate() && \"not a generic lambda call operator?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3485, __PRETTY_FUNCTION__)); | |||
3486 | return getDefinitionOrSelf(getPrimaryTemplate()->getTemplatedDecl()); | |||
3487 | } | |||
3488 | ||||
3489 | if (MemberSpecializationInfo *Info = getMemberSpecializationInfo()) { | |||
3490 | if (!clang::isTemplateInstantiation(Info->getTemplateSpecializationKind())) | |||
3491 | return nullptr; | |||
3492 | return getDefinitionOrSelf(cast<FunctionDecl>(Info->getInstantiatedFrom())); | |||
3493 | } | |||
3494 | ||||
3495 | if (!clang::isTemplateInstantiation(getTemplateSpecializationKind())) | |||
3496 | return nullptr; | |||
3497 | ||||
3498 | if (FunctionTemplateDecl *Primary = getPrimaryTemplate()) { | |||
3499 | // If we hit a point where the user provided a specialization of this | |||
3500 | // template, we're done looking. | |||
3501 | while (!Primary->isMemberSpecialization()) { | |||
3502 | auto *NewPrimary = Primary->getInstantiatedFromMemberTemplate(); | |||
3503 | if (!NewPrimary) | |||
3504 | break; | |||
3505 | Primary = NewPrimary; | |||
3506 | } | |||
3507 | ||||
3508 | return getDefinitionOrSelf(Primary->getTemplatedDecl()); | |||
3509 | } | |||
3510 | ||||
3511 | return nullptr; | |||
3512 | } | |||
3513 | ||||
3514 | FunctionTemplateDecl *FunctionDecl::getPrimaryTemplate() const { | |||
3515 | if (FunctionTemplateSpecializationInfo *Info | |||
3516 | = TemplateOrSpecialization | |||
3517 | .dyn_cast<FunctionTemplateSpecializationInfo*>()) { | |||
3518 | return Info->getTemplate(); | |||
3519 | } | |||
3520 | return nullptr; | |||
3521 | } | |||
3522 | ||||
3523 | FunctionTemplateSpecializationInfo * | |||
3524 | FunctionDecl::getTemplateSpecializationInfo() const { | |||
3525 | return TemplateOrSpecialization | |||
3526 | .dyn_cast<FunctionTemplateSpecializationInfo *>(); | |||
3527 | } | |||
3528 | ||||
3529 | const TemplateArgumentList * | |||
3530 | FunctionDecl::getTemplateSpecializationArgs() const { | |||
3531 | if (FunctionTemplateSpecializationInfo *Info | |||
3532 | = TemplateOrSpecialization | |||
3533 | .dyn_cast<FunctionTemplateSpecializationInfo*>()) { | |||
3534 | return Info->TemplateArguments; | |||
3535 | } | |||
3536 | return nullptr; | |||
3537 | } | |||
3538 | ||||
3539 | const ASTTemplateArgumentListInfo * | |||
3540 | FunctionDecl::getTemplateSpecializationArgsAsWritten() const { | |||
3541 | if (FunctionTemplateSpecializationInfo *Info | |||
3542 | = TemplateOrSpecialization | |||
3543 | .dyn_cast<FunctionTemplateSpecializationInfo*>()) { | |||
3544 | return Info->TemplateArgumentsAsWritten; | |||
3545 | } | |||
3546 | return nullptr; | |||
3547 | } | |||
3548 | ||||
3549 | void | |||
3550 | FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C, | |||
3551 | FunctionTemplateDecl *Template, | |||
3552 | const TemplateArgumentList *TemplateArgs, | |||
3553 | void *InsertPos, | |||
3554 | TemplateSpecializationKind TSK, | |||
3555 | const TemplateArgumentListInfo *TemplateArgsAsWritten, | |||
3556 | SourceLocation PointOfInstantiation) { | |||
3557 | assert((TemplateOrSpecialization.isNull() ||(((TemplateOrSpecialization.isNull() || TemplateOrSpecialization .is<MemberSpecializationInfo *>()) && "Member function is already a specialization" ) ? static_cast<void> (0) : __assert_fail ("(TemplateOrSpecialization.isNull() || TemplateOrSpecialization.is<MemberSpecializationInfo *>()) && \"Member function is already a specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3559, __PRETTY_FUNCTION__)) | |||
3558 | TemplateOrSpecialization.is<MemberSpecializationInfo *>()) &&(((TemplateOrSpecialization.isNull() || TemplateOrSpecialization .is<MemberSpecializationInfo *>()) && "Member function is already a specialization" ) ? static_cast<void> (0) : __assert_fail ("(TemplateOrSpecialization.isNull() || TemplateOrSpecialization.is<MemberSpecializationInfo *>()) && \"Member function is already a specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3559, __PRETTY_FUNCTION__)) | |||
3559 | "Member function is already a specialization")(((TemplateOrSpecialization.isNull() || TemplateOrSpecialization .is<MemberSpecializationInfo *>()) && "Member function is already a specialization" ) ? static_cast<void> (0) : __assert_fail ("(TemplateOrSpecialization.isNull() || TemplateOrSpecialization.is<MemberSpecializationInfo *>()) && \"Member function is already a specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3559, __PRETTY_FUNCTION__)); | |||
3560 | assert(TSK != TSK_Undeclared &&((TSK != TSK_Undeclared && "Must specify the type of function template specialization" ) ? static_cast<void> (0) : __assert_fail ("TSK != TSK_Undeclared && \"Must specify the type of function template specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3561, __PRETTY_FUNCTION__)) | |||
3561 | "Must specify the type of function template specialization")((TSK != TSK_Undeclared && "Must specify the type of function template specialization" ) ? static_cast<void> (0) : __assert_fail ("TSK != TSK_Undeclared && \"Must specify the type of function template specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3561, __PRETTY_FUNCTION__)); | |||
3562 | assert((TemplateOrSpecialization.isNull() ||(((TemplateOrSpecialization.isNull() || TSK == TSK_ExplicitSpecialization ) && "Member specialization must be an explicit specialization" ) ? static_cast<void> (0) : __assert_fail ("(TemplateOrSpecialization.isNull() || TSK == TSK_ExplicitSpecialization) && \"Member specialization must be an explicit specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3564, __PRETTY_FUNCTION__)) | |||
3563 | TSK == TSK_ExplicitSpecialization) &&(((TemplateOrSpecialization.isNull() || TSK == TSK_ExplicitSpecialization ) && "Member specialization must be an explicit specialization" ) ? static_cast<void> (0) : __assert_fail ("(TemplateOrSpecialization.isNull() || TSK == TSK_ExplicitSpecialization) && \"Member specialization must be an explicit specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3564, __PRETTY_FUNCTION__)) | |||
3564 | "Member specialization must be an explicit specialization")(((TemplateOrSpecialization.isNull() || TSK == TSK_ExplicitSpecialization ) && "Member specialization must be an explicit specialization" ) ? static_cast<void> (0) : __assert_fail ("(TemplateOrSpecialization.isNull() || TSK == TSK_ExplicitSpecialization) && \"Member specialization must be an explicit specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3564, __PRETTY_FUNCTION__)); | |||
3565 | FunctionTemplateSpecializationInfo *Info = | |||
3566 | FunctionTemplateSpecializationInfo::Create( | |||
3567 | C, this, Template, TSK, TemplateArgs, TemplateArgsAsWritten, | |||
3568 | PointOfInstantiation, | |||
3569 | TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>()); | |||
3570 | TemplateOrSpecialization = Info; | |||
3571 | Template->addSpecialization(Info, InsertPos); | |||
3572 | } | |||
3573 | ||||
3574 | void | |||
3575 | FunctionDecl::setDependentTemplateSpecialization(ASTContext &Context, | |||
3576 | const UnresolvedSetImpl &Templates, | |||
3577 | const TemplateArgumentListInfo &TemplateArgs) { | |||
3578 | assert(TemplateOrSpecialization.isNull())((TemplateOrSpecialization.isNull()) ? static_cast<void> (0) : __assert_fail ("TemplateOrSpecialization.isNull()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3578, __PRETTY_FUNCTION__)); | |||
3579 | DependentFunctionTemplateSpecializationInfo *Info = | |||
3580 | DependentFunctionTemplateSpecializationInfo::Create(Context, Templates, | |||
3581 | TemplateArgs); | |||
3582 | TemplateOrSpecialization = Info; | |||
3583 | } | |||
3584 | ||||
3585 | DependentFunctionTemplateSpecializationInfo * | |||
3586 | FunctionDecl::getDependentSpecializationInfo() const { | |||
3587 | return TemplateOrSpecialization | |||
3588 | .dyn_cast<DependentFunctionTemplateSpecializationInfo *>(); | |||
3589 | } | |||
3590 | ||||
3591 | DependentFunctionTemplateSpecializationInfo * | |||
3592 | DependentFunctionTemplateSpecializationInfo::Create( | |||
3593 | ASTContext &Context, const UnresolvedSetImpl &Ts, | |||
3594 | const TemplateArgumentListInfo &TArgs) { | |||
3595 | void *Buffer = Context.Allocate( | |||
3596 | totalSizeToAlloc<TemplateArgumentLoc, FunctionTemplateDecl *>( | |||
3597 | TArgs.size(), Ts.size())); | |||
3598 | return new (Buffer) DependentFunctionTemplateSpecializationInfo(Ts, TArgs); | |||
3599 | } | |||
3600 | ||||
3601 | DependentFunctionTemplateSpecializationInfo:: | |||
3602 | DependentFunctionTemplateSpecializationInfo(const UnresolvedSetImpl &Ts, | |||
3603 | const TemplateArgumentListInfo &TArgs) | |||
3604 | : AngleLocs(TArgs.getLAngleLoc(), TArgs.getRAngleLoc()) { | |||
3605 | NumTemplates = Ts.size(); | |||
3606 | NumArgs = TArgs.size(); | |||
3607 | ||||
3608 | FunctionTemplateDecl **TsArray = getTrailingObjects<FunctionTemplateDecl *>(); | |||
3609 | for (unsigned I = 0, E = Ts.size(); I != E; ++I) | |||
3610 | TsArray[I] = cast<FunctionTemplateDecl>(Ts[I]->getUnderlyingDecl()); | |||
3611 | ||||
3612 | TemplateArgumentLoc *ArgsArray = getTrailingObjects<TemplateArgumentLoc>(); | |||
3613 | for (unsigned I = 0, E = TArgs.size(); I != E; ++I) | |||
3614 | new (&ArgsArray[I]) TemplateArgumentLoc(TArgs[I]); | |||
3615 | } | |||
3616 | ||||
3617 | TemplateSpecializationKind FunctionDecl::getTemplateSpecializationKind() const { | |||
3618 | // For a function template specialization, query the specialization | |||
3619 | // information object. | |||
3620 | if (FunctionTemplateSpecializationInfo *FTSInfo = | |||
3621 | TemplateOrSpecialization | |||
3622 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) | |||
3623 | return FTSInfo->getTemplateSpecializationKind(); | |||
3624 | ||||
3625 | if (MemberSpecializationInfo *MSInfo = | |||
3626 | TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>()) | |||
3627 | return MSInfo->getTemplateSpecializationKind(); | |||
3628 | ||||
3629 | return TSK_Undeclared; | |||
3630 | } | |||
3631 | ||||
3632 | TemplateSpecializationKind | |||
3633 | FunctionDecl::getTemplateSpecializationKindForInstantiation() const { | |||
3634 | // This is the same as getTemplateSpecializationKind(), except that for a | |||
3635 | // function that is both a function template specialization and a member | |||
3636 | // specialization, we prefer the member specialization information. Eg: | |||
3637 | // | |||
3638 | // template<typename T> struct A { | |||
3639 | // template<typename U> void f() {} | |||
3640 | // template<> void f<int>() {} | |||
3641 | // }; | |||
3642 | // | |||
3643 | // For A<int>::f<int>(): | |||
3644 | // * getTemplateSpecializationKind() will return TSK_ExplicitSpecialization | |||
3645 | // * getTemplateSpecializationKindForInstantiation() will return | |||
3646 | // TSK_ImplicitInstantiation | |||
3647 | // | |||
3648 | // This reflects the facts that A<int>::f<int> is an explicit specialization | |||
3649 | // of A<int>::f, and that A<int>::f<int> should be implicitly instantiated | |||
3650 | // from A::f<int> if a definition is needed. | |||
3651 | if (FunctionTemplateSpecializationInfo *FTSInfo = | |||
3652 | TemplateOrSpecialization | |||
3653 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) { | |||
3654 | if (auto *MSInfo = FTSInfo->getMemberSpecializationInfo()) | |||
3655 | return MSInfo->getTemplateSpecializationKind(); | |||
3656 | return FTSInfo->getTemplateSpecializationKind(); | |||
3657 | } | |||
3658 | ||||
3659 | if (MemberSpecializationInfo *MSInfo = | |||
3660 | TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>()) | |||
3661 | return MSInfo->getTemplateSpecializationKind(); | |||
3662 | ||||
3663 | return TSK_Undeclared; | |||
3664 | } | |||
3665 | ||||
3666 | void | |||
3667 | FunctionDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK, | |||
3668 | SourceLocation PointOfInstantiation) { | |||
3669 | if (FunctionTemplateSpecializationInfo *FTSInfo | |||
3670 | = TemplateOrSpecialization.dyn_cast< | |||
3671 | FunctionTemplateSpecializationInfo*>()) { | |||
3672 | FTSInfo->setTemplateSpecializationKind(TSK); | |||
3673 | if (TSK != TSK_ExplicitSpecialization && | |||
3674 | PointOfInstantiation.isValid() && | |||
3675 | FTSInfo->getPointOfInstantiation().isInvalid()) { | |||
3676 | FTSInfo->setPointOfInstantiation(PointOfInstantiation); | |||
3677 | if (ASTMutationListener *L = getASTContext().getASTMutationListener()) | |||
3678 | L->InstantiationRequested(this); | |||
3679 | } | |||
3680 | } else if (MemberSpecializationInfo *MSInfo | |||
3681 | = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>()) { | |||
3682 | MSInfo->setTemplateSpecializationKind(TSK); | |||
3683 | if (TSK != TSK_ExplicitSpecialization && | |||
3684 | PointOfInstantiation.isValid() && | |||
3685 | MSInfo->getPointOfInstantiation().isInvalid()) { | |||
3686 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | |||
3687 | if (ASTMutationListener *L = getASTContext().getASTMutationListener()) | |||
3688 | L->InstantiationRequested(this); | |||
3689 | } | |||
3690 | } else | |||
3691 | llvm_unreachable("Function cannot have a template specialization kind")::llvm::llvm_unreachable_internal("Function cannot have a template specialization kind" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3691); | |||
3692 | } | |||
3693 | ||||
3694 | SourceLocation FunctionDecl::getPointOfInstantiation() const { | |||
3695 | if (FunctionTemplateSpecializationInfo *FTSInfo | |||
3696 | = TemplateOrSpecialization.dyn_cast< | |||
3697 | FunctionTemplateSpecializationInfo*>()) | |||
3698 | return FTSInfo->getPointOfInstantiation(); | |||
3699 | else if (MemberSpecializationInfo *MSInfo | |||
3700 | = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>()) | |||
3701 | return MSInfo->getPointOfInstantiation(); | |||
3702 | ||||
3703 | return SourceLocation(); | |||
3704 | } | |||
3705 | ||||
3706 | bool FunctionDecl::isOutOfLine() const { | |||
3707 | if (Decl::isOutOfLine()) | |||
3708 | return true; | |||
3709 | ||||
3710 | // If this function was instantiated from a member function of a | |||
3711 | // class template, check whether that member function was defined out-of-line. | |||
3712 | if (FunctionDecl *FD = getInstantiatedFromMemberFunction()) { | |||
3713 | const FunctionDecl *Definition; | |||
3714 | if (FD->hasBody(Definition)) | |||
3715 | return Definition->isOutOfLine(); | |||
3716 | } | |||
3717 | ||||
3718 | // If this function was instantiated from a function template, | |||
3719 | // check whether that function template was defined out-of-line. | |||
3720 | if (FunctionTemplateDecl *FunTmpl = getPrimaryTemplate()) { | |||
3721 | const FunctionDecl *Definition; | |||
3722 | if (FunTmpl->getTemplatedDecl()->hasBody(Definition)) | |||
3723 | return Definition->isOutOfLine(); | |||
3724 | } | |||
3725 | ||||
3726 | return false; | |||
3727 | } | |||
3728 | ||||
3729 | SourceRange FunctionDecl::getSourceRange() const { | |||
3730 | return SourceRange(getOuterLocStart(), EndRangeLoc); | |||
3731 | } | |||
3732 | ||||
3733 | unsigned FunctionDecl::getMemoryFunctionKind() const { | |||
3734 | IdentifierInfo *FnInfo = getIdentifier(); | |||
3735 | ||||
3736 | if (!FnInfo) | |||
3737 | return 0; | |||
3738 | ||||
3739 | // Builtin handling. | |||
3740 | switch (getBuiltinID()) { | |||
3741 | case Builtin::BI__builtin_memset: | |||
3742 | case Builtin::BI__builtin___memset_chk: | |||
3743 | case Builtin::BImemset: | |||
3744 | return Builtin::BImemset; | |||
3745 | ||||
3746 | case Builtin::BI__builtin_memcpy: | |||
3747 | case Builtin::BI__builtin___memcpy_chk: | |||
3748 | case Builtin::BImemcpy: | |||
3749 | return Builtin::BImemcpy; | |||
3750 | ||||
3751 | case Builtin::BI__builtin_memmove: | |||
3752 | case Builtin::BI__builtin___memmove_chk: | |||
3753 | case Builtin::BImemmove: | |||
3754 | return Builtin::BImemmove; | |||
3755 | ||||
3756 | // case Builtin::BIstrlcpy: | |||
3757 | // case Builtin::BI__builtin___strlcpy_chk: | |||
3758 | // return Builtin::BIstrlcpy; | |||
3759 | ||||
3760 | // case Builtin::BIstrlcat: | |||
3761 | // case Builtin::BI__builtin___strlcat_chk: | |||
3762 | // return Builtin::BIstrlcat; | |||
3763 | ||||
3764 | case Builtin::BI__builtin_memcmp: | |||
3765 | case Builtin::BImemcmp: | |||
3766 | return Builtin::BImemcmp; | |||
3767 | ||||
3768 | case Builtin::BI__builtin_bcmp: | |||
3769 | case Builtin::BIbcmp: | |||
3770 | return Builtin::BIbcmp; | |||
3771 | ||||
3772 | case Builtin::BI__builtin_strncpy: | |||
3773 | case Builtin::BI__builtin___strncpy_chk: | |||
3774 | case Builtin::BIstrncpy: | |||
3775 | return Builtin::BIstrncpy; | |||
3776 | ||||
3777 | case Builtin::BI__builtin_strncmp: | |||
3778 | case Builtin::BIstrncmp: | |||
3779 | return Builtin::BIstrncmp; | |||
3780 | ||||
3781 | case Builtin::BI__builtin_strncasecmp: | |||
3782 | case Builtin::BIstrncasecmp: | |||
3783 | return Builtin::BIstrncasecmp; | |||
3784 | ||||
3785 | case Builtin::BI__builtin_strncat: | |||
3786 | case Builtin::BI__builtin___strncat_chk: | |||
3787 | case Builtin::BIstrncat: | |||
3788 | return Builtin::BIstrncat; | |||
3789 | ||||
3790 | case Builtin::BI__builtin_strndup: | |||
3791 | case Builtin::BIstrndup: | |||
3792 | return Builtin::BIstrndup; | |||
3793 | ||||
3794 | case Builtin::BI__builtin_strlen: | |||
3795 | case Builtin::BIstrlen: | |||
3796 | return Builtin::BIstrlen; | |||
3797 | ||||
3798 | case Builtin::BI__builtin_bzero: | |||
3799 | case Builtin::BIbzero: | |||
3800 | return Builtin::BIbzero; | |||
3801 | ||||
3802 | default: | |||
3803 | if (isExternC()) { | |||
3804 | if (FnInfo->isStr("memset")) | |||
3805 | return Builtin::BImemset; | |||
3806 | else if (FnInfo->isStr("memcpy")) | |||
3807 | return Builtin::BImemcpy; | |||
3808 | else if (FnInfo->isStr("memmove")) | |||
3809 | return Builtin::BImemmove; | |||
3810 | else if (FnInfo->isStr("memcmp")) | |||
3811 | return Builtin::BImemcmp; | |||
3812 | else if (FnInfo->isStr("bcmp")) | |||
3813 | return Builtin::BIbcmp; | |||
3814 | else if (FnInfo->isStr("strncpy")) | |||
3815 | return Builtin::BIstrncpy; | |||
3816 | else if (FnInfo->isStr("strncmp")) | |||
3817 | return Builtin::BIstrncmp; | |||
3818 | else if (FnInfo->isStr("strncasecmp")) | |||
3819 | return Builtin::BIstrncasecmp; | |||
3820 | else if (FnInfo->isStr("strncat")) | |||
3821 | return Builtin::BIstrncat; | |||
3822 | else if (FnInfo->isStr("strndup")) | |||
3823 | return Builtin::BIstrndup; | |||
3824 | else if (FnInfo->isStr("strlen")) | |||
3825 | return Builtin::BIstrlen; | |||
3826 | else if (FnInfo->isStr("bzero")) | |||
3827 | return Builtin::BIbzero; | |||
3828 | } | |||
3829 | break; | |||
3830 | } | |||
3831 | return 0; | |||
3832 | } | |||
3833 | ||||
3834 | unsigned FunctionDecl::getODRHash() const { | |||
3835 | assert(hasODRHash())((hasODRHash()) ? static_cast<void> (0) : __assert_fail ("hasODRHash()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3835, __PRETTY_FUNCTION__)); | |||
3836 | return ODRHash; | |||
3837 | } | |||
3838 | ||||
3839 | unsigned FunctionDecl::getODRHash() { | |||
3840 | if (hasODRHash()) | |||
3841 | return ODRHash; | |||
3842 | ||||
3843 | if (auto *FT = getInstantiatedFromMemberFunction()) { | |||
3844 | setHasODRHash(true); | |||
3845 | ODRHash = FT->getODRHash(); | |||
3846 | return ODRHash; | |||
3847 | } | |||
3848 | ||||
3849 | class ODRHash Hash; | |||
3850 | Hash.AddFunctionDecl(this); | |||
3851 | setHasODRHash(true); | |||
3852 | ODRHash = Hash.CalculateHash(); | |||
3853 | return ODRHash; | |||
3854 | } | |||
3855 | ||||
3856 | //===----------------------------------------------------------------------===// | |||
3857 | // FieldDecl Implementation | |||
3858 | //===----------------------------------------------------------------------===// | |||
3859 | ||||
3860 | FieldDecl *FieldDecl::Create(const ASTContext &C, DeclContext *DC, | |||
3861 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
3862 | IdentifierInfo *Id, QualType T, | |||
3863 | TypeSourceInfo *TInfo, Expr *BW, bool Mutable, | |||
3864 | InClassInitStyle InitStyle) { | |||
3865 | return new (C, DC) FieldDecl(Decl::Field, DC, StartLoc, IdLoc, Id, T, TInfo, | |||
3866 | BW, Mutable, InitStyle); | |||
3867 | } | |||
3868 | ||||
3869 | FieldDecl *FieldDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
3870 | return new (C, ID) FieldDecl(Field, nullptr, SourceLocation(), | |||
3871 | SourceLocation(), nullptr, QualType(), nullptr, | |||
3872 | nullptr, false, ICIS_NoInit); | |||
3873 | } | |||
3874 | ||||
3875 | bool FieldDecl::isAnonymousStructOrUnion() const { | |||
3876 | if (!isImplicit() || getDeclName()) | |||
3877 | return false; | |||
3878 | ||||
3879 | if (const auto *Record = getType()->getAs<RecordType>()) | |||
3880 | return Record->getDecl()->isAnonymousStructOrUnion(); | |||
3881 | ||||
3882 | return false; | |||
3883 | } | |||
3884 | ||||
3885 | unsigned FieldDecl::getBitWidthValue(const ASTContext &Ctx) const { | |||
3886 | assert(isBitField() && "not a bitfield")((isBitField() && "not a bitfield") ? static_cast< void> (0) : __assert_fail ("isBitField() && \"not a bitfield\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3886, __PRETTY_FUNCTION__)); | |||
3887 | return getBitWidth()->EvaluateKnownConstInt(Ctx).getZExtValue(); | |||
3888 | } | |||
3889 | ||||
3890 | bool FieldDecl::isZeroLengthBitField(const ASTContext &Ctx) const { | |||
3891 | return isUnnamedBitfield() && !getBitWidth()->isValueDependent() && | |||
3892 | getBitWidthValue(Ctx) == 0; | |||
3893 | } | |||
3894 | ||||
3895 | unsigned FieldDecl::getFieldIndex() const { | |||
3896 | const FieldDecl *Canonical = getCanonicalDecl(); | |||
3897 | if (Canonical != this) | |||
3898 | return Canonical->getFieldIndex(); | |||
3899 | ||||
3900 | if (CachedFieldIndex) return CachedFieldIndex - 1; | |||
3901 | ||||
3902 | unsigned Index = 0; | |||
3903 | const RecordDecl *RD = getParent()->getDefinition(); | |||
3904 | assert(RD && "requested index for field of struct with no definition")((RD && "requested index for field of struct with no definition" ) ? static_cast<void> (0) : __assert_fail ("RD && \"requested index for field of struct with no definition\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3904, __PRETTY_FUNCTION__)); | |||
3905 | ||||
3906 | for (auto *Field : RD->fields()) { | |||
3907 | Field->getCanonicalDecl()->CachedFieldIndex = Index + 1; | |||
3908 | ++Index; | |||
3909 | } | |||
3910 | ||||
3911 | assert(CachedFieldIndex && "failed to find field in parent")((CachedFieldIndex && "failed to find field in parent" ) ? static_cast<void> (0) : __assert_fail ("CachedFieldIndex && \"failed to find field in parent\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3911, __PRETTY_FUNCTION__)); | |||
3912 | return CachedFieldIndex - 1; | |||
3913 | } | |||
3914 | ||||
3915 | SourceRange FieldDecl::getSourceRange() const { | |||
3916 | const Expr *FinalExpr = getInClassInitializer(); | |||
3917 | if (!FinalExpr) | |||
3918 | FinalExpr = getBitWidth(); | |||
3919 | if (FinalExpr) | |||
3920 | return SourceRange(getInnerLocStart(), FinalExpr->getEndLoc()); | |||
3921 | return DeclaratorDecl::getSourceRange(); | |||
3922 | } | |||
3923 | ||||
3924 | void FieldDecl::setCapturedVLAType(const VariableArrayType *VLAType) { | |||
3925 | assert((getParent()->isLambda() || getParent()->isCapturedRecord()) &&(((getParent()->isLambda() || getParent()->isCapturedRecord ()) && "capturing type in non-lambda or captured record." ) ? static_cast<void> (0) : __assert_fail ("(getParent()->isLambda() || getParent()->isCapturedRecord()) && \"capturing type in non-lambda or captured record.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3926, __PRETTY_FUNCTION__)) | |||
3926 | "capturing type in non-lambda or captured record.")(((getParent()->isLambda() || getParent()->isCapturedRecord ()) && "capturing type in non-lambda or captured record." ) ? static_cast<void> (0) : __assert_fail ("(getParent()->isLambda() || getParent()->isCapturedRecord()) && \"capturing type in non-lambda or captured record.\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3926, __PRETTY_FUNCTION__)); | |||
3927 | assert(InitStorage.getInt() == ISK_NoInit &&((InitStorage.getInt() == ISK_NoInit && InitStorage.getPointer () == nullptr && "bit width, initializer or captured type already set" ) ? static_cast<void> (0) : __assert_fail ("InitStorage.getInt() == ISK_NoInit && InitStorage.getPointer() == nullptr && \"bit width, initializer or captured type already set\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3929, __PRETTY_FUNCTION__)) | |||
3928 | InitStorage.getPointer() == nullptr &&((InitStorage.getInt() == ISK_NoInit && InitStorage.getPointer () == nullptr && "bit width, initializer or captured type already set" ) ? static_cast<void> (0) : __assert_fail ("InitStorage.getInt() == ISK_NoInit && InitStorage.getPointer() == nullptr && \"bit width, initializer or captured type already set\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3929, __PRETTY_FUNCTION__)) | |||
3929 | "bit width, initializer or captured type already set")((InitStorage.getInt() == ISK_NoInit && InitStorage.getPointer () == nullptr && "bit width, initializer or captured type already set" ) ? static_cast<void> (0) : __assert_fail ("InitStorage.getInt() == ISK_NoInit && InitStorage.getPointer() == nullptr && \"bit width, initializer or captured type already set\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3929, __PRETTY_FUNCTION__)); | |||
3930 | InitStorage.setPointerAndInt(const_cast<VariableArrayType *>(VLAType), | |||
3931 | ISK_CapturedVLAType); | |||
3932 | } | |||
3933 | ||||
3934 | //===----------------------------------------------------------------------===// | |||
3935 | // TagDecl Implementation | |||
3936 | //===----------------------------------------------------------------------===// | |||
3937 | ||||
3938 | TagDecl::TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, | |||
3939 | SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, | |||
3940 | SourceLocation StartL) | |||
3941 | : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), redeclarable_base(C), | |||
3942 | TypedefNameDeclOrQualifier((TypedefNameDecl *)nullptr) { | |||
3943 | assert((DK != Enum || TK == TTK_Enum) &&(((DK != Enum || TK == TTK_Enum) && "EnumDecl not matched with TTK_Enum" ) ? static_cast<void> (0) : __assert_fail ("(DK != Enum || TK == TTK_Enum) && \"EnumDecl not matched with TTK_Enum\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3944, __PRETTY_FUNCTION__)) | |||
3944 | "EnumDecl not matched with TTK_Enum")(((DK != Enum || TK == TTK_Enum) && "EnumDecl not matched with TTK_Enum" ) ? static_cast<void> (0) : __assert_fail ("(DK != Enum || TK == TTK_Enum) && \"EnumDecl not matched with TTK_Enum\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3944, __PRETTY_FUNCTION__)); | |||
3945 | setPreviousDecl(PrevDecl); | |||
3946 | setTagKind(TK); | |||
3947 | setCompleteDefinition(false); | |||
3948 | setBeingDefined(false); | |||
3949 | setEmbeddedInDeclarator(false); | |||
3950 | setFreeStanding(false); | |||
3951 | setCompleteDefinitionRequired(false); | |||
3952 | } | |||
3953 | ||||
3954 | SourceLocation TagDecl::getOuterLocStart() const { | |||
3955 | return getTemplateOrInnerLocStart(this); | |||
3956 | } | |||
3957 | ||||
3958 | SourceRange TagDecl::getSourceRange() const { | |||
3959 | SourceLocation RBraceLoc = BraceRange.getEnd(); | |||
3960 | SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation(); | |||
3961 | return SourceRange(getOuterLocStart(), E); | |||
3962 | } | |||
3963 | ||||
3964 | TagDecl *TagDecl::getCanonicalDecl() { return getFirstDecl(); } | |||
3965 | ||||
3966 | void TagDecl::setTypedefNameForAnonDecl(TypedefNameDecl *TDD) { | |||
3967 | TypedefNameDeclOrQualifier = TDD; | |||
3968 | if (const Type *T = getTypeForDecl()) { | |||
3969 | (void)T; | |||
3970 | assert(T->isLinkageValid())((T->isLinkageValid()) ? static_cast<void> (0) : __assert_fail ("T->isLinkageValid()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3970, __PRETTY_FUNCTION__)); | |||
3971 | } | |||
3972 | assert(isLinkageValid())((isLinkageValid()) ? static_cast<void> (0) : __assert_fail ("isLinkageValid()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3972, __PRETTY_FUNCTION__)); | |||
3973 | } | |||
3974 | ||||
3975 | void TagDecl::startDefinition() { | |||
3976 | setBeingDefined(true); | |||
3977 | ||||
3978 | if (auto *D = dyn_cast<CXXRecordDecl>(this)) { | |||
3979 | struct CXXRecordDecl::DefinitionData *Data = | |||
3980 | new (getASTContext()) struct CXXRecordDecl::DefinitionData(D); | |||
3981 | for (auto I : redecls()) | |||
3982 | cast<CXXRecordDecl>(I)->DefinitionData = Data; | |||
3983 | } | |||
3984 | } | |||
3985 | ||||
3986 | void TagDecl::completeDefinition() { | |||
3987 | assert((!isa<CXXRecordDecl>(this) ||(((!isa<CXXRecordDecl>(this) || cast<CXXRecordDecl> (this)->hasDefinition()) && "definition completed but not started" ) ? static_cast<void> (0) : __assert_fail ("(!isa<CXXRecordDecl>(this) || cast<CXXRecordDecl>(this)->hasDefinition()) && \"definition completed but not started\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3989, __PRETTY_FUNCTION__)) | |||
3988 | cast<CXXRecordDecl>(this)->hasDefinition()) &&(((!isa<CXXRecordDecl>(this) || cast<CXXRecordDecl> (this)->hasDefinition()) && "definition completed but not started" ) ? static_cast<void> (0) : __assert_fail ("(!isa<CXXRecordDecl>(this) || cast<CXXRecordDecl>(this)->hasDefinition()) && \"definition completed but not started\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3989, __PRETTY_FUNCTION__)) | |||
3989 | "definition completed but not started")(((!isa<CXXRecordDecl>(this) || cast<CXXRecordDecl> (this)->hasDefinition()) && "definition completed but not started" ) ? static_cast<void> (0) : __assert_fail ("(!isa<CXXRecordDecl>(this) || cast<CXXRecordDecl>(this)->hasDefinition()) && \"definition completed but not started\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 3989, __PRETTY_FUNCTION__)); | |||
3990 | ||||
3991 | setCompleteDefinition(true); | |||
3992 | setBeingDefined(false); | |||
3993 | ||||
3994 | if (ASTMutationListener *L = getASTMutationListener()) | |||
3995 | L->CompletedTagDefinition(this); | |||
3996 | } | |||
3997 | ||||
3998 | TagDecl *TagDecl::getDefinition() const { | |||
3999 | if (isCompleteDefinition()) | |||
4000 | return const_cast<TagDecl *>(this); | |||
4001 | ||||
4002 | // If it's possible for us to have an out-of-date definition, check now. | |||
4003 | if (mayHaveOutOfDateDef()) { | |||
4004 | if (IdentifierInfo *II = getIdentifier()) { | |||
4005 | if (II->isOutOfDate()) { | |||
4006 | updateOutOfDate(*II); | |||
4007 | } | |||
4008 | } | |||
4009 | } | |||
4010 | ||||
4011 | if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(this)) | |||
4012 | return CXXRD->getDefinition(); | |||
4013 | ||||
4014 | for (auto R : redecls()) | |||
4015 | if (R->isCompleteDefinition()) | |||
4016 | return R; | |||
4017 | ||||
4018 | return nullptr; | |||
4019 | } | |||
4020 | ||||
4021 | void TagDecl::setQualifierInfo(NestedNameSpecifierLoc QualifierLoc) { | |||
4022 | if (QualifierLoc) { | |||
4023 | // Make sure the extended qualifier info is allocated. | |||
4024 | if (!hasExtInfo()) | |||
4025 | TypedefNameDeclOrQualifier = new (getASTContext()) ExtInfo; | |||
4026 | // Set qualifier info. | |||
4027 | getExtInfo()->QualifierLoc = QualifierLoc; | |||
4028 | } else { | |||
4029 | // Here Qualifier == 0, i.e., we are removing the qualifier (if any). | |||
4030 | if (hasExtInfo()) { | |||
4031 | if (getExtInfo()->NumTemplParamLists == 0) { | |||
4032 | getASTContext().Deallocate(getExtInfo()); | |||
4033 | TypedefNameDeclOrQualifier = (TypedefNameDecl *)nullptr; | |||
4034 | } | |||
4035 | else | |||
4036 | getExtInfo()->QualifierLoc = QualifierLoc; | |||
4037 | } | |||
4038 | } | |||
4039 | } | |||
4040 | ||||
4041 | void TagDecl::setTemplateParameterListsInfo( | |||
4042 | ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists) { | |||
4043 | assert(!TPLists.empty())((!TPLists.empty()) ? static_cast<void> (0) : __assert_fail ("!TPLists.empty()", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4043, __PRETTY_FUNCTION__)); | |||
4044 | // Make sure the extended decl info is allocated. | |||
4045 | if (!hasExtInfo()) | |||
4046 | // Allocate external info struct. | |||
4047 | TypedefNameDeclOrQualifier = new (getASTContext()) ExtInfo; | |||
4048 | // Set the template parameter lists info. | |||
4049 | getExtInfo()->setTemplateParameterListsInfo(Context, TPLists); | |||
4050 | } | |||
4051 | ||||
4052 | //===----------------------------------------------------------------------===// | |||
4053 | // EnumDecl Implementation | |||
4054 | //===----------------------------------------------------------------------===// | |||
4055 | ||||
4056 | EnumDecl::EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, | |||
4057 | SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, | |||
4058 | bool Scoped, bool ScopedUsingClassTag, bool Fixed) | |||
4059 | : TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc) { | |||
4060 | assert(Scoped || !ScopedUsingClassTag)((Scoped || !ScopedUsingClassTag) ? static_cast<void> ( 0) : __assert_fail ("Scoped || !ScopedUsingClassTag", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4060, __PRETTY_FUNCTION__)); | |||
4061 | IntegerType = nullptr; | |||
4062 | setNumPositiveBits(0); | |||
4063 | setNumNegativeBits(0); | |||
4064 | setScoped(Scoped); | |||
4065 | setScopedUsingClassTag(ScopedUsingClassTag); | |||
4066 | setFixed(Fixed); | |||
4067 | setHasODRHash(false); | |||
4068 | ODRHash = 0; | |||
4069 | } | |||
4070 | ||||
4071 | void EnumDecl::anchor() {} | |||
4072 | ||||
4073 | EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, | |||
4074 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
4075 | IdentifierInfo *Id, | |||
4076 | EnumDecl *PrevDecl, bool IsScoped, | |||
4077 | bool IsScopedUsingClassTag, bool IsFixed) { | |||
4078 | auto *Enum = new (C, DC) EnumDecl(C, DC, StartLoc, IdLoc, Id, PrevDecl, | |||
4079 | IsScoped, IsScopedUsingClassTag, IsFixed); | |||
4080 | Enum->setMayHaveOutOfDateDef(C.getLangOpts().Modules); | |||
4081 | C.getTypeDeclType(Enum, PrevDecl); | |||
4082 | return Enum; | |||
4083 | } | |||
4084 | ||||
4085 | EnumDecl *EnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4086 | EnumDecl *Enum = | |||
4087 | new (C, ID) EnumDecl(C, nullptr, SourceLocation(), SourceLocation(), | |||
4088 | nullptr, nullptr, false, false, false); | |||
4089 | Enum->setMayHaveOutOfDateDef(C.getLangOpts().Modules); | |||
4090 | return Enum; | |||
4091 | } | |||
4092 | ||||
4093 | SourceRange EnumDecl::getIntegerTypeRange() const { | |||
4094 | if (const TypeSourceInfo *TI = getIntegerTypeSourceInfo()) | |||
4095 | return TI->getTypeLoc().getSourceRange(); | |||
4096 | return SourceRange(); | |||
4097 | } | |||
4098 | ||||
4099 | void EnumDecl::completeDefinition(QualType NewType, | |||
4100 | QualType NewPromotionType, | |||
4101 | unsigned NumPositiveBits, | |||
4102 | unsigned NumNegativeBits) { | |||
4103 | assert(!isCompleteDefinition() && "Cannot redefine enums!")((!isCompleteDefinition() && "Cannot redefine enums!" ) ? static_cast<void> (0) : __assert_fail ("!isCompleteDefinition() && \"Cannot redefine enums!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4103, __PRETTY_FUNCTION__)); | |||
4104 | if (!IntegerType) | |||
4105 | IntegerType = NewType.getTypePtr(); | |||
4106 | PromotionType = NewPromotionType; | |||
4107 | setNumPositiveBits(NumPositiveBits); | |||
4108 | setNumNegativeBits(NumNegativeBits); | |||
4109 | TagDecl::completeDefinition(); | |||
4110 | } | |||
4111 | ||||
4112 | bool EnumDecl::isClosed() const { | |||
4113 | if (const auto *A = getAttr<EnumExtensibilityAttr>()) | |||
4114 | return A->getExtensibility() == EnumExtensibilityAttr::Closed; | |||
4115 | return true; | |||
4116 | } | |||
4117 | ||||
4118 | bool EnumDecl::isClosedFlag() const { | |||
4119 | return isClosed() && hasAttr<FlagEnumAttr>(); | |||
4120 | } | |||
4121 | ||||
4122 | bool EnumDecl::isClosedNonFlag() const { | |||
4123 | return isClosed() && !hasAttr<FlagEnumAttr>(); | |||
4124 | } | |||
4125 | ||||
4126 | TemplateSpecializationKind EnumDecl::getTemplateSpecializationKind() const { | |||
4127 | if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) | |||
4128 | return MSI->getTemplateSpecializationKind(); | |||
4129 | ||||
4130 | return TSK_Undeclared; | |||
4131 | } | |||
4132 | ||||
4133 | void EnumDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK, | |||
4134 | SourceLocation PointOfInstantiation) { | |||
4135 | MemberSpecializationInfo *MSI = getMemberSpecializationInfo(); | |||
4136 | assert(MSI && "Not an instantiated member enumeration?")((MSI && "Not an instantiated member enumeration?") ? static_cast<void> (0) : __assert_fail ("MSI && \"Not an instantiated member enumeration?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4136, __PRETTY_FUNCTION__)); | |||
4137 | MSI->setTemplateSpecializationKind(TSK); | |||
4138 | if (TSK != TSK_ExplicitSpecialization && | |||
4139 | PointOfInstantiation.isValid() && | |||
4140 | MSI->getPointOfInstantiation().isInvalid()) | |||
4141 | MSI->setPointOfInstantiation(PointOfInstantiation); | |||
4142 | } | |||
4143 | ||||
4144 | EnumDecl *EnumDecl::getTemplateInstantiationPattern() const { | |||
4145 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { | |||
4146 | if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) { | |||
4147 | EnumDecl *ED = getInstantiatedFromMemberEnum(); | |||
4148 | while (auto *NewED = ED->getInstantiatedFromMemberEnum()) | |||
4149 | ED = NewED; | |||
4150 | return getDefinitionOrSelf(ED); | |||
4151 | } | |||
4152 | } | |||
4153 | ||||
4154 | assert(!isTemplateInstantiation(getTemplateSpecializationKind()) &&((!isTemplateInstantiation(getTemplateSpecializationKind()) && "couldn't find pattern for enum instantiation") ? static_cast <void> (0) : __assert_fail ("!isTemplateInstantiation(getTemplateSpecializationKind()) && \"couldn't find pattern for enum instantiation\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4155, __PRETTY_FUNCTION__)) | |||
4155 | "couldn't find pattern for enum instantiation")((!isTemplateInstantiation(getTemplateSpecializationKind()) && "couldn't find pattern for enum instantiation") ? static_cast <void> (0) : __assert_fail ("!isTemplateInstantiation(getTemplateSpecializationKind()) && \"couldn't find pattern for enum instantiation\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4155, __PRETTY_FUNCTION__)); | |||
4156 | return nullptr; | |||
4157 | } | |||
4158 | ||||
4159 | EnumDecl *EnumDecl::getInstantiatedFromMemberEnum() const { | |||
4160 | if (SpecializationInfo) | |||
4161 | return cast<EnumDecl>(SpecializationInfo->getInstantiatedFrom()); | |||
4162 | ||||
4163 | return nullptr; | |||
4164 | } | |||
4165 | ||||
4166 | void EnumDecl::setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED, | |||
4167 | TemplateSpecializationKind TSK) { | |||
4168 | assert(!SpecializationInfo && "Member enum is already a specialization")((!SpecializationInfo && "Member enum is already a specialization" ) ? static_cast<void> (0) : __assert_fail ("!SpecializationInfo && \"Member enum is already a specialization\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4168, __PRETTY_FUNCTION__)); | |||
4169 | SpecializationInfo = new (C) MemberSpecializationInfo(ED, TSK); | |||
4170 | } | |||
4171 | ||||
4172 | unsigned EnumDecl::getODRHash() { | |||
4173 | if (hasODRHash()) | |||
4174 | return ODRHash; | |||
4175 | ||||
4176 | class ODRHash Hash; | |||
4177 | Hash.AddEnumDecl(this); | |||
4178 | setHasODRHash(true); | |||
4179 | ODRHash = Hash.CalculateHash(); | |||
4180 | return ODRHash; | |||
4181 | } | |||
4182 | ||||
4183 | //===----------------------------------------------------------------------===// | |||
4184 | // RecordDecl Implementation | |||
4185 | //===----------------------------------------------------------------------===// | |||
4186 | ||||
4187 | RecordDecl::RecordDecl(Kind DK, TagKind TK, const ASTContext &C, | |||
4188 | DeclContext *DC, SourceLocation StartLoc, | |||
4189 | SourceLocation IdLoc, IdentifierInfo *Id, | |||
4190 | RecordDecl *PrevDecl) | |||
4191 | : TagDecl(DK, TK, C, DC, IdLoc, Id, PrevDecl, StartLoc) { | |||
4192 | assert(classof(static_cast<Decl *>(this)) && "Invalid Kind!")((classof(static_cast<Decl *>(this)) && "Invalid Kind!" ) ? static_cast<void> (0) : __assert_fail ("classof(static_cast<Decl *>(this)) && \"Invalid Kind!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4192, __PRETTY_FUNCTION__)); | |||
4193 | setHasFlexibleArrayMember(false); | |||
4194 | setAnonymousStructOrUnion(false); | |||
4195 | setHasObjectMember(false); | |||
4196 | setHasVolatileMember(false); | |||
4197 | setHasLoadedFieldsFromExternalStorage(false); | |||
4198 | setNonTrivialToPrimitiveDefaultInitialize(false); | |||
4199 | setNonTrivialToPrimitiveCopy(false); | |||
4200 | setNonTrivialToPrimitiveDestroy(false); | |||
4201 | setParamDestroyedInCallee(false); | |||
4202 | setArgPassingRestrictions(APK_CanPassInRegs); | |||
4203 | } | |||
4204 | ||||
4205 | RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC, | |||
4206 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
4207 | IdentifierInfo *Id, RecordDecl* PrevDecl) { | |||
4208 | RecordDecl *R = new (C, DC) RecordDecl(Record, TK, C, DC, | |||
4209 | StartLoc, IdLoc, Id, PrevDecl); | |||
4210 | R->setMayHaveOutOfDateDef(C.getLangOpts().Modules); | |||
4211 | ||||
4212 | C.getTypeDeclType(R, PrevDecl); | |||
4213 | return R; | |||
4214 | } | |||
4215 | ||||
4216 | RecordDecl *RecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { | |||
4217 | RecordDecl *R = | |||
4218 | new (C, ID) RecordDecl(Record, TTK_Struct, C, nullptr, SourceLocation(), | |||
4219 | SourceLocation(), nullptr, nullptr); | |||
4220 | R->setMayHaveOutOfDateDef(C.getLangOpts().Modules); | |||
4221 | return R; | |||
4222 | } | |||
4223 | ||||
4224 | bool RecordDecl::isInjectedClassName() const { | |||
4225 | return isImplicit() && getDeclName() && getDeclContext()->isRecord() && | |||
4226 | cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName(); | |||
4227 | } | |||
4228 | ||||
4229 | bool RecordDecl::isLambda() const { | |||
4230 | if (auto RD = dyn_cast<CXXRecordDecl>(this)) | |||
4231 | return RD->isLambda(); | |||
4232 | return false; | |||
4233 | } | |||
4234 | ||||
4235 | bool RecordDecl::isCapturedRecord() const { | |||
4236 | return hasAttr<CapturedRecordAttr>(); | |||
4237 | } | |||
4238 | ||||
4239 | void RecordDecl::setCapturedRecord() { | |||
4240 | addAttr(CapturedRecordAttr::CreateImplicit(getASTContext())); | |||
| ||||
4241 | } | |||
4242 | ||||
4243 | RecordDecl::field_iterator RecordDecl::field_begin() const { | |||
4244 | if (hasExternalLexicalStorage() && !hasLoadedFieldsFromExternalStorage()) | |||
4245 | LoadFieldsFromExternalStorage(); | |||
4246 | ||||
4247 | return field_iterator(decl_iterator(FirstDecl)); | |||
4248 | } | |||
4249 | ||||
4250 | /// completeDefinition - Notes that the definition of this type is now | |||
4251 | /// complete. | |||
4252 | void RecordDecl::completeDefinition() { | |||
4253 | assert(!isCompleteDefinition() && "Cannot redefine record!")((!isCompleteDefinition() && "Cannot redefine record!" ) ? static_cast<void> (0) : __assert_fail ("!isCompleteDefinition() && \"Cannot redefine record!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4253, __PRETTY_FUNCTION__)); | |||
4254 | TagDecl::completeDefinition(); | |||
4255 | } | |||
4256 | ||||
4257 | /// isMsStruct - Get whether or not this record uses ms_struct layout. | |||
4258 | /// This which can be turned on with an attribute, pragma, or the | |||
4259 | /// -mms-bitfields command-line option. | |||
4260 | bool RecordDecl::isMsStruct(const ASTContext &C) const { | |||
4261 | return hasAttr<MSStructAttr>() || C.getLangOpts().MSBitfields == 1; | |||
4262 | } | |||
4263 | ||||
4264 | void RecordDecl::LoadFieldsFromExternalStorage() const { | |||
4265 | ExternalASTSource *Source = getASTContext().getExternalSource(); | |||
4266 | assert(hasExternalLexicalStorage() && Source && "No external storage?")((hasExternalLexicalStorage() && Source && "No external storage?" ) ? static_cast<void> (0) : __assert_fail ("hasExternalLexicalStorage() && Source && \"No external storage?\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4266, __PRETTY_FUNCTION__)); | |||
4267 | ||||
4268 | // Notify that we have a RecordDecl doing some initialization. | |||
4269 | ExternalASTSource::Deserializing TheFields(Source); | |||
4270 | ||||
4271 | SmallVector<Decl*, 64> Decls; | |||
4272 | setHasLoadedFieldsFromExternalStorage(true); | |||
4273 | Source->FindExternalLexicalDecls(this, [](Decl::Kind K) { | |||
4274 | return FieldDecl::classofKind(K) || IndirectFieldDecl::classofKind(K); | |||
4275 | }, Decls); | |||
4276 | ||||
4277 | #ifndef NDEBUG | |||
4278 | // Check that all decls we got were FieldDecls. | |||
4279 | for (unsigned i=0, e=Decls.size(); i != e; ++i) | |||
4280 | assert(isa<FieldDecl>(Decls[i]) || isa<IndirectFieldDecl>(Decls[i]))((isa<FieldDecl>(Decls[i]) || isa<IndirectFieldDecl> (Decls[i])) ? static_cast<void> (0) : __assert_fail ("isa<FieldDecl>(Decls[i]) || isa<IndirectFieldDecl>(Decls[i])" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4280, __PRETTY_FUNCTION__)); | |||
4281 | #endif | |||
4282 | ||||
4283 | if (Decls.empty()) | |||
4284 | return; | |||
4285 | ||||
4286 | std::tie(FirstDecl, LastDecl) = BuildDeclChain(Decls, | |||
4287 | /*FieldsAlreadyLoaded=*/false); | |||
4288 | } | |||
4289 | ||||
4290 | bool RecordDecl::mayInsertExtraPadding(bool EmitRemark) const { | |||
4291 | ASTContext &Context = getASTContext(); | |||
4292 | const SanitizerMask EnabledAsanMask = Context.getLangOpts().Sanitize.Mask & | |||
4293 | (SanitizerKind::Address | SanitizerKind::KernelAddress); | |||
4294 | if (!EnabledAsanMask || !Context.getLangOpts().SanitizeAddressFieldPadding) | |||
4295 | return false; | |||
4296 | const auto &Blacklist = Context.getSanitizerBlacklist(); | |||
4297 | const auto *CXXRD = dyn_cast<CXXRecordDecl>(this); | |||
4298 | // We may be able to relax some of these requirements. | |||
4299 | int ReasonToReject = -1; | |||
4300 | if (!CXXRD || CXXRD->isExternCContext()) | |||
4301 | ReasonToReject = 0; // is not C++. | |||
4302 | else if (CXXRD->hasAttr<PackedAttr>()) | |||
4303 | ReasonToReject = 1; // is packed. | |||
4304 | else if (CXXRD->isUnion()) | |||
4305 | ReasonToReject = 2; // is a union. | |||
4306 | else if (CXXRD->isTriviallyCopyable()) | |||
4307 | ReasonToReject = 3; // is trivially copyable. | |||
4308 | else if (CXXRD->hasTrivialDestructor()) | |||
4309 | ReasonToReject = 4; // has trivial destructor. | |||
4310 | else if (CXXRD->isStandardLayout()) | |||
4311 | ReasonToReject = 5; // is standard layout. | |||
4312 | else if (Blacklist.isBlacklistedLocation(EnabledAsanMask, getLocation(), | |||
4313 | "field-padding")) | |||
4314 | ReasonToReject = 6; // is in a blacklisted file. | |||
4315 | else if (Blacklist.isBlacklistedType(EnabledAsanMask, | |||
4316 | getQualifiedNameAsString(), | |||
4317 | "field-padding")) | |||
4318 | ReasonToReject = 7; // is blacklisted. | |||
4319 | ||||
4320 | if (EmitRemark) { | |||
4321 | if (ReasonToReject >= 0) | |||
4322 | Context.getDiagnostics().Report( | |||
4323 | getLocation(), | |||
4324 | diag::remark_sanitize_address_insert_extra_padding_rejected) | |||
4325 | << getQualifiedNameAsString() << ReasonToReject; | |||
4326 | else | |||
4327 | Context.getDiagnostics().Report( | |||
4328 | getLocation(), | |||
4329 | diag::remark_sanitize_address_insert_extra_padding_accepted) | |||
4330 | << getQualifiedNameAsString(); | |||
4331 | } | |||
4332 | return ReasonToReject < 0; | |||
4333 | } | |||
4334 | ||||
4335 | const FieldDecl *RecordDecl::findFirstNamedDataMember() const { | |||
4336 | for (const auto *I : fields()) { | |||
4337 | if (I->getIdentifier()) | |||
4338 | return I; | |||
4339 | ||||
4340 | if (const auto *RT = I->getType()->getAs<RecordType>()) | |||
4341 | if (const FieldDecl *NamedDataMember = | |||
4342 | RT->getDecl()->findFirstNamedDataMember()) | |||
4343 | return NamedDataMember; | |||
4344 | } | |||
4345 | ||||
4346 | // We didn't find a named data member. | |||
4347 | return nullptr; | |||
4348 | } | |||
4349 | ||||
4350 | //===----------------------------------------------------------------------===// | |||
4351 | // BlockDecl Implementation | |||
4352 | //===----------------------------------------------------------------------===// | |||
4353 | ||||
4354 | BlockDecl::BlockDecl(DeclContext *DC, SourceLocation CaretLoc) | |||
4355 | : Decl(Block, DC, CaretLoc), DeclContext(Block) { | |||
4356 | setIsVariadic(false); | |||
4357 | setCapturesCXXThis(false); | |||
4358 | setBlockMissingReturnType(true); | |||
4359 | setIsConversionFromLambda(false); | |||
4360 | setDoesNotEscape(false); | |||
4361 | setCanAvoidCopyToHeap(false); | |||
4362 | } | |||
4363 | ||||
4364 | void BlockDecl::setParams(ArrayRef<ParmVarDecl *> NewParamInfo) { | |||
4365 | assert(!ParamInfo && "Already has param info!")((!ParamInfo && "Already has param info!") ? static_cast <void> (0) : __assert_fail ("!ParamInfo && \"Already has param info!\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4365, __PRETTY_FUNCTION__)); | |||
4366 | ||||
4367 | // Zero params -> null pointer. | |||
4368 | if (!NewParamInfo.empty()) { | |||
4369 | NumParams = NewParamInfo.size(); | |||
4370 | ParamInfo = new (getASTContext()) ParmVarDecl*[NewParamInfo.size()]; | |||
4371 | std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo); | |||
4372 | } | |||
4373 | } | |||
4374 | ||||
4375 | void BlockDecl::setCaptures(ASTContext &Context, ArrayRef<Capture> Captures, | |||
4376 | bool CapturesCXXThis) { | |||
4377 | this->setCapturesCXXThis(CapturesCXXThis); | |||
4378 | this->NumCaptures = Captures.size(); | |||
4379 | ||||
4380 | if (Captures.empty()) { | |||
4381 | this->Captures = nullptr; | |||
4382 | return; | |||
4383 | } | |||
4384 | ||||
4385 | this->Captures = Captures.copy(Context).data(); | |||
4386 | } | |||
4387 | ||||
4388 | bool BlockDecl::capturesVariable(const VarDecl *variable) const { | |||
4389 | for (const auto &I : captures()) | |||
4390 | // Only auto vars can be captured, so no redeclaration worries. | |||
4391 | if (I.getVariable() == variable) | |||
4392 | return true; | |||
4393 | ||||
4394 | return false; | |||
4395 | } | |||
4396 | ||||
4397 | SourceRange BlockDecl::getSourceRange() const { | |||
4398 | return SourceRange(getLocation(), Body ? Body->getEndLoc() : getLocation()); | |||
4399 | } | |||
4400 | ||||
4401 | //===----------------------------------------------------------------------===// | |||
4402 | // Other Decl Allocation/Deallocation Method Implementations | |||
4403 | //===----------------------------------------------------------------------===// | |||
4404 | ||||
4405 | void TranslationUnitDecl::anchor() {} | |||
4406 | ||||
4407 | TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) { | |||
4408 | return new (C, (DeclContext *)nullptr) TranslationUnitDecl(C); | |||
4409 | } | |||
4410 | ||||
4411 | void PragmaCommentDecl::anchor() {} | |||
4412 | ||||
4413 | PragmaCommentDecl *PragmaCommentDecl::Create(const ASTContext &C, | |||
4414 | TranslationUnitDecl *DC, | |||
4415 | SourceLocation CommentLoc, | |||
4416 | PragmaMSCommentKind CommentKind, | |||
4417 | StringRef Arg) { | |||
4418 | PragmaCommentDecl *PCD = | |||
4419 | new (C, DC, additionalSizeToAlloc<char>(Arg.size() + 1)) | |||
4420 | PragmaCommentDecl(DC, CommentLoc, CommentKind); | |||
4421 | memcpy(PCD->getTrailingObjects<char>(), Arg.data(), Arg.size()); | |||
4422 | PCD->getTrailingObjects<char>()[Arg.size()] = '\0'; | |||
4423 | return PCD; | |||
4424 | } | |||
4425 | ||||
4426 | PragmaCommentDecl *PragmaCommentDecl::CreateDeserialized(ASTContext &C, | |||
4427 | unsigned ID, | |||
4428 | unsigned ArgSize) { | |||
4429 | return new (C, ID, additionalSizeToAlloc<char>(ArgSize + 1)) | |||
4430 | PragmaCommentDecl(nullptr, SourceLocation(), PCK_Unknown); | |||
4431 | } | |||
4432 | ||||
4433 | void PragmaDetectMismatchDecl::anchor() {} | |||
4434 | ||||
4435 | PragmaDetectMismatchDecl * | |||
4436 | PragmaDetectMismatchDecl::Create(const ASTContext &C, TranslationUnitDecl *DC, | |||
4437 | SourceLocation Loc, StringRef Name, | |||
4438 | StringRef Value) { | |||
4439 | size_t ValueStart = Name.size() + 1; | |||
4440 | PragmaDetectMismatchDecl *PDMD = | |||
4441 | new (C, DC, additionalSizeToAlloc<char>(ValueStart + Value.size() + 1)) | |||
4442 | PragmaDetectMismatchDecl(DC, Loc, ValueStart); | |||
4443 | memcpy(PDMD->getTrailingObjects<char>(), Name.data(), Name.size()); | |||
4444 | PDMD->getTrailingObjects<char>()[Name.size()] = '\0'; | |||
4445 | memcpy(PDMD->getTrailingObjects<char>() + ValueStart, Value.data(), | |||
4446 | Value.size()); | |||
4447 | PDMD->getTrailingObjects<char>()[ValueStart + Value.size()] = '\0'; | |||
4448 | return PDMD; | |||
4449 | } | |||
4450 | ||||
4451 | PragmaDetectMismatchDecl * | |||
4452 | PragmaDetectMismatchDecl::CreateDeserialized(ASTContext &C, unsigned ID, | |||
4453 | unsigned NameValueSize) { | |||
4454 | return new (C, ID, additionalSizeToAlloc<char>(NameValueSize + 1)) | |||
4455 | PragmaDetectMismatchDecl(nullptr, SourceLocation(), 0); | |||
4456 | } | |||
4457 | ||||
4458 | void ExternCContextDecl::anchor() {} | |||
4459 | ||||
4460 | ExternCContextDecl *ExternCContextDecl::Create(const ASTContext &C, | |||
4461 | TranslationUnitDecl *DC) { | |||
4462 | return new (C, DC) ExternCContextDecl(DC); | |||
4463 | } | |||
4464 | ||||
4465 | void LabelDecl::anchor() {} | |||
4466 | ||||
4467 | LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC, | |||
4468 | SourceLocation IdentL, IdentifierInfo *II) { | |||
4469 | return new (C, DC) LabelDecl(DC, IdentL, II, nullptr, IdentL); | |||
4470 | } | |||
4471 | ||||
4472 | LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC, | |||
4473 | SourceLocation IdentL, IdentifierInfo *II, | |||
4474 | SourceLocation GnuLabelL) { | |||
4475 | assert(GnuLabelL != IdentL && "Use this only for GNU local labels")((GnuLabelL != IdentL && "Use this only for GNU local labels" ) ? static_cast<void> (0) : __assert_fail ("GnuLabelL != IdentL && \"Use this only for GNU local labels\"" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4475, __PRETTY_FUNCTION__)); | |||
4476 | return new (C, DC) LabelDecl(DC, IdentL, II, nullptr, GnuLabelL); | |||
4477 | } | |||
4478 | ||||
4479 | LabelDecl *LabelDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4480 | return new (C, ID) LabelDecl(nullptr, SourceLocation(), nullptr, nullptr, | |||
4481 | SourceLocation()); | |||
4482 | } | |||
4483 | ||||
4484 | void LabelDecl::setMSAsmLabel(StringRef Name) { | |||
4485 | char *Buffer = new (getASTContext(), 1) char[Name.size() + 1]; | |||
4486 | memcpy(Buffer, Name.data(), Name.size()); | |||
4487 | Buffer[Name.size()] = '\0'; | |||
4488 | MSAsmName = Buffer; | |||
4489 | } | |||
4490 | ||||
4491 | void ValueDecl::anchor() {} | |||
4492 | ||||
4493 | bool ValueDecl::isWeak() const { | |||
4494 | for (const auto *I : attrs()) | |||
4495 | if (isa<WeakAttr>(I) || isa<WeakRefAttr>(I)) | |||
4496 | return true; | |||
4497 | ||||
4498 | return isWeakImported(); | |||
4499 | } | |||
4500 | ||||
4501 | void ImplicitParamDecl::anchor() {} | |||
4502 | ||||
4503 | ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, | |||
4504 | SourceLocation IdLoc, | |||
4505 | IdentifierInfo *Id, QualType Type, | |||
4506 | ImplicitParamKind ParamKind) { | |||
4507 | return new (C, DC) ImplicitParamDecl(C, DC, IdLoc, Id, Type, ParamKind); | |||
4508 | } | |||
4509 | ||||
4510 | ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, QualType Type, | |||
4511 | ImplicitParamKind ParamKind) { | |||
4512 | return new (C, nullptr) ImplicitParamDecl(C, Type, ParamKind); | |||
4513 | } | |||
4514 | ||||
4515 | ImplicitParamDecl *ImplicitParamDecl::CreateDeserialized(ASTContext &C, | |||
4516 | unsigned ID) { | |||
4517 | return new (C, ID) ImplicitParamDecl(C, QualType(), ImplicitParamKind::Other); | |||
4518 | } | |||
4519 | ||||
4520 | FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, | |||
4521 | SourceLocation StartLoc, | |||
4522 | const DeclarationNameInfo &NameInfo, | |||
4523 | QualType T, TypeSourceInfo *TInfo, | |||
4524 | StorageClass SC, | |||
4525 | bool isInlineSpecified, | |||
4526 | bool hasWrittenPrototype, | |||
4527 | bool isConstexprSpecified) { | |||
4528 | FunctionDecl *New = | |||
4529 | new (C, DC) FunctionDecl(Function, C, DC, StartLoc, NameInfo, T, TInfo, | |||
4530 | SC, isInlineSpecified, isConstexprSpecified); | |||
4531 | New->setHasWrittenPrototype(hasWrittenPrototype); | |||
4532 | return New; | |||
4533 | } | |||
4534 | ||||
4535 | FunctionDecl *FunctionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4536 | return new (C, ID) FunctionDecl(Function, C, nullptr, SourceLocation(), | |||
4537 | DeclarationNameInfo(), QualType(), nullptr, | |||
4538 | SC_None, false, false); | |||
4539 | } | |||
4540 | ||||
4541 | BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { | |||
4542 | return new (C, DC) BlockDecl(DC, L); | |||
4543 | } | |||
4544 | ||||
4545 | BlockDecl *BlockDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4546 | return new (C, ID) BlockDecl(nullptr, SourceLocation()); | |||
4547 | } | |||
4548 | ||||
4549 | CapturedDecl::CapturedDecl(DeclContext *DC, unsigned NumParams) | |||
4550 | : Decl(Captured, DC, SourceLocation()), DeclContext(Captured), | |||
4551 | NumParams(NumParams), ContextParam(0), BodyAndNothrow(nullptr, false) {} | |||
4552 | ||||
4553 | CapturedDecl *CapturedDecl::Create(ASTContext &C, DeclContext *DC, | |||
4554 | unsigned NumParams) { | |||
4555 | return new (C, DC, additionalSizeToAlloc<ImplicitParamDecl *>(NumParams)) | |||
4556 | CapturedDecl(DC, NumParams); | |||
4557 | } | |||
4558 | ||||
4559 | CapturedDecl *CapturedDecl::CreateDeserialized(ASTContext &C, unsigned ID, | |||
4560 | unsigned NumParams) { | |||
4561 | return new (C, ID, additionalSizeToAlloc<ImplicitParamDecl *>(NumParams)) | |||
4562 | CapturedDecl(nullptr, NumParams); | |||
4563 | } | |||
4564 | ||||
4565 | Stmt *CapturedDecl::getBody() const { return BodyAndNothrow.getPointer(); } | |||
4566 | void CapturedDecl::setBody(Stmt *B) { BodyAndNothrow.setPointer(B); } | |||
4567 | ||||
4568 | bool CapturedDecl::isNothrow() const { return BodyAndNothrow.getInt(); } | |||
4569 | void CapturedDecl::setNothrow(bool Nothrow) { BodyAndNothrow.setInt(Nothrow); } | |||
4570 | ||||
4571 | EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, | |||
4572 | SourceLocation L, | |||
4573 | IdentifierInfo *Id, QualType T, | |||
4574 | Expr *E, const llvm::APSInt &V) { | |||
4575 | return new (C, CD) EnumConstantDecl(CD, L, Id, T, E, V); | |||
4576 | } | |||
4577 | ||||
4578 | EnumConstantDecl * | |||
4579 | EnumConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4580 | return new (C, ID) EnumConstantDecl(nullptr, SourceLocation(), nullptr, | |||
4581 | QualType(), nullptr, llvm::APSInt()); | |||
4582 | } | |||
4583 | ||||
4584 | void IndirectFieldDecl::anchor() {} | |||
4585 | ||||
4586 | IndirectFieldDecl::IndirectFieldDecl(ASTContext &C, DeclContext *DC, | |||
4587 | SourceLocation L, DeclarationName N, | |||
4588 | QualType T, | |||
4589 | MutableArrayRef<NamedDecl *> CH) | |||
4590 | : ValueDecl(IndirectField, DC, L, N, T), Chaining(CH.data()), | |||
4591 | ChainingSize(CH.size()) { | |||
4592 | // In C++, indirect field declarations conflict with tag declarations in the | |||
4593 | // same scope, so add them to IDNS_Tag so that tag redeclaration finds them. | |||
4594 | if (C.getLangOpts().CPlusPlus) | |||
4595 | IdentifierNamespace |= IDNS_Tag; | |||
4596 | } | |||
4597 | ||||
4598 | IndirectFieldDecl * | |||
4599 | IndirectFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, | |||
4600 | IdentifierInfo *Id, QualType T, | |||
4601 | llvm::MutableArrayRef<NamedDecl *> CH) { | |||
4602 | return new (C, DC) IndirectFieldDecl(C, DC, L, Id, T, CH); | |||
4603 | } | |||
4604 | ||||
4605 | IndirectFieldDecl *IndirectFieldDecl::CreateDeserialized(ASTContext &C, | |||
4606 | unsigned ID) { | |||
4607 | return new (C, ID) IndirectFieldDecl(C, nullptr, SourceLocation(), | |||
4608 | DeclarationName(), QualType(), None); | |||
4609 | } | |||
4610 | ||||
4611 | SourceRange EnumConstantDecl::getSourceRange() const { | |||
4612 | SourceLocation End = getLocation(); | |||
4613 | if (Init) | |||
4614 | End = Init->getEndLoc(); | |||
4615 | return SourceRange(getLocation(), End); | |||
4616 | } | |||
4617 | ||||
4618 | void TypeDecl::anchor() {} | |||
4619 | ||||
4620 | TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, | |||
4621 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
4622 | IdentifierInfo *Id, TypeSourceInfo *TInfo) { | |||
4623 | return new (C, DC) TypedefDecl(C, DC, StartLoc, IdLoc, Id, TInfo); | |||
4624 | } | |||
4625 | ||||
4626 | void TypedefNameDecl::anchor() {} | |||
4627 | ||||
4628 | TagDecl *TypedefNameDecl::getAnonDeclWithTypedefName(bool AnyRedecl) const { | |||
4629 | if (auto *TT = getTypeSourceInfo()->getType()->getAs<TagType>()) { | |||
4630 | auto *OwningTypedef = TT->getDecl()->getTypedefNameForAnonDecl(); | |||
4631 | auto *ThisTypedef = this; | |||
4632 | if (AnyRedecl && OwningTypedef) { | |||
4633 | OwningTypedef = OwningTypedef->getCanonicalDecl(); | |||
4634 | ThisTypedef = ThisTypedef->getCanonicalDecl(); | |||
4635 | } | |||
4636 | if (OwningTypedef == ThisTypedef) | |||
4637 | return TT->getDecl(); | |||
4638 | } | |||
4639 | ||||
4640 | return nullptr; | |||
4641 | } | |||
4642 | ||||
4643 | bool TypedefNameDecl::isTransparentTagSlow() const { | |||
4644 | auto determineIsTransparent = [&]() { | |||
4645 | if (auto *TT = getUnderlyingType()->getAs<TagType>()) { | |||
4646 | if (auto *TD = TT->getDecl()) { | |||
4647 | if (TD->getName() != getName()) | |||
4648 | return false; | |||
4649 | SourceLocation TTLoc = getLocation(); | |||
4650 | SourceLocation TDLoc = TD->getLocation(); | |||
4651 | if (!TTLoc.isMacroID() || !TDLoc.isMacroID()) | |||
4652 | return false; | |||
4653 | SourceManager &SM = getASTContext().getSourceManager(); | |||
4654 | return SM.getSpellingLoc(TTLoc) == SM.getSpellingLoc(TDLoc); | |||
4655 | } | |||
4656 | } | |||
4657 | return false; | |||
4658 | }; | |||
4659 | ||||
4660 | bool isTransparent = determineIsTransparent(); | |||
4661 | MaybeModedTInfo.setInt((isTransparent << 1) | 1); | |||
4662 | return isTransparent; | |||
4663 | } | |||
4664 | ||||
4665 | TypedefDecl *TypedefDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4666 | return new (C, ID) TypedefDecl(C, nullptr, SourceLocation(), SourceLocation(), | |||
4667 | nullptr, nullptr); | |||
4668 | } | |||
4669 | ||||
4670 | TypeAliasDecl *TypeAliasDecl::Create(ASTContext &C, DeclContext *DC, | |||
4671 | SourceLocation StartLoc, | |||
4672 | SourceLocation IdLoc, IdentifierInfo *Id, | |||
4673 | TypeSourceInfo *TInfo) { | |||
4674 | return new (C, DC) TypeAliasDecl(C, DC, StartLoc, IdLoc, Id, TInfo); | |||
4675 | } | |||
4676 | ||||
4677 | TypeAliasDecl *TypeAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4678 | return new (C, ID) TypeAliasDecl(C, nullptr, SourceLocation(), | |||
4679 | SourceLocation(), nullptr, nullptr); | |||
4680 | } | |||
4681 | ||||
4682 | SourceRange TypedefDecl::getSourceRange() const { | |||
4683 | SourceLocation RangeEnd = getLocation(); | |||
4684 | if (TypeSourceInfo *TInfo = getTypeSourceInfo()) { | |||
4685 | if (typeIsPostfix(TInfo->getType())) | |||
4686 | RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd(); | |||
4687 | } | |||
4688 | return SourceRange(getBeginLoc(), RangeEnd); | |||
4689 | } | |||
4690 | ||||
4691 | SourceRange TypeAliasDecl::getSourceRange() const { | |||
4692 | SourceLocation RangeEnd = getBeginLoc(); | |||
4693 | if (TypeSourceInfo *TInfo = getTypeSourceInfo()) | |||
4694 | RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd(); | |||
4695 | return SourceRange(getBeginLoc(), RangeEnd); | |||
4696 | } | |||
4697 | ||||
4698 | void FileScopeAsmDecl::anchor() {} | |||
4699 | ||||
4700 | FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, | |||
4701 | StringLiteral *Str, | |||
4702 | SourceLocation AsmLoc, | |||
4703 | SourceLocation RParenLoc) { | |||
4704 | return new (C, DC) FileScopeAsmDecl(DC, Str, AsmLoc, RParenLoc); | |||
4705 | } | |||
4706 | ||||
4707 | FileScopeAsmDecl *FileScopeAsmDecl::CreateDeserialized(ASTContext &C, | |||
4708 | unsigned ID) { | |||
4709 | return new (C, ID) FileScopeAsmDecl(nullptr, nullptr, SourceLocation(), | |||
4710 | SourceLocation()); | |||
4711 | } | |||
4712 | ||||
4713 | void EmptyDecl::anchor() {} | |||
4714 | ||||
4715 | EmptyDecl *EmptyDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { | |||
4716 | return new (C, DC) EmptyDecl(DC, L); | |||
4717 | } | |||
4718 | ||||
4719 | EmptyDecl *EmptyDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4720 | return new (C, ID) EmptyDecl(nullptr, SourceLocation()); | |||
4721 | } | |||
4722 | ||||
4723 | //===----------------------------------------------------------------------===// | |||
4724 | // ImportDecl Implementation | |||
4725 | //===----------------------------------------------------------------------===// | |||
4726 | ||||
4727 | /// Retrieve the number of module identifiers needed to name the given | |||
4728 | /// module. | |||
4729 | static unsigned getNumModuleIdentifiers(Module *Mod) { | |||
4730 | unsigned Result = 1; | |||
4731 | while (Mod->Parent) { | |||
4732 | Mod = Mod->Parent; | |||
4733 | ++Result; | |||
4734 | } | |||
4735 | return Result; | |||
4736 | } | |||
4737 | ||||
4738 | ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc, | |||
4739 | Module *Imported, | |||
4740 | ArrayRef<SourceLocation> IdentifierLocs) | |||
4741 | : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, true) { | |||
4742 | assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size())((getNumModuleIdentifiers(Imported) == IdentifierLocs.size()) ? static_cast<void> (0) : __assert_fail ("getNumModuleIdentifiers(Imported) == IdentifierLocs.size()" , "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/AST/Decl.cpp" , 4742, __PRETTY_FUNCTION__)); | |||
4743 | auto *StoredLocs = getTrailingObjects<SourceLocation>(); | |||
4744 | std::uninitialized_copy(IdentifierLocs.begin(), IdentifierLocs.end(), | |||
4745 | StoredLocs); | |||
4746 | } | |||
4747 | ||||
4748 | ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc, | |||
4749 | Module *Imported, SourceLocation EndLoc) | |||
4750 | : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, false) { | |||
4751 | *getTrailingObjects<SourceLocation>() = EndLoc; | |||
4752 | } | |||
4753 | ||||
4754 | ImportDecl *ImportDecl::Create(ASTContext &C, DeclContext *DC, | |||
4755 | SourceLocation StartLoc, Module *Imported, | |||
4756 | ArrayRef<SourceLocation> IdentifierLocs) { | |||
4757 | return new (C, DC, | |||
4758 | additionalSizeToAlloc<SourceLocation>(IdentifierLocs.size())) | |||
4759 | ImportDecl(DC, StartLoc, Imported, IdentifierLocs); | |||
4760 | } | |||
4761 | ||||
4762 | ImportDecl *ImportDecl::CreateImplicit(ASTContext &C, DeclContext *DC, | |||
4763 | SourceLocation StartLoc, | |||
4764 | Module *Imported, | |||
4765 | SourceLocation EndLoc) { | |||
4766 | ImportDecl *Import = new (C, DC, additionalSizeToAlloc<SourceLocation>(1)) | |||
4767 | ImportDecl(DC, StartLoc, Imported, EndLoc); | |||
4768 | Import->setImplicit(); | |||
4769 | return Import; | |||
4770 | } | |||
4771 | ||||
4772 | ImportDecl *ImportDecl::CreateDeserialized(ASTContext &C, unsigned ID, | |||
4773 | unsigned NumLocations) { | |||
4774 | return new (C, ID, additionalSizeToAlloc<SourceLocation>(NumLocations)) | |||
4775 | ImportDecl(EmptyShell()); | |||
4776 | } | |||
4777 | ||||
4778 | ArrayRef<SourceLocation> ImportDecl::getIdentifierLocs() const { | |||
4779 | if (!ImportedAndComplete.getInt()) | |||
4780 | return None; | |||
4781 | ||||
4782 | const auto *StoredLocs = getTrailingObjects<SourceLocation>(); | |||
4783 | return llvm::makeArrayRef(StoredLocs, | |||
4784 | getNumModuleIdentifiers(getImportedModule())); | |||
4785 | } | |||
4786 | ||||
4787 | SourceRange ImportDecl::getSourceRange() const { | |||
4788 | if (!ImportedAndComplete.getInt()) | |||
4789 | return SourceRange(getLocation(), *getTrailingObjects<SourceLocation>()); | |||
4790 | ||||
4791 | return SourceRange(getLocation(), getIdentifierLocs().back()); | |||
4792 | } | |||
4793 | ||||
4794 | //===----------------------------------------------------------------------===// | |||
4795 | // ExportDecl Implementation | |||
4796 | //===----------------------------------------------------------------------===// | |||
4797 | ||||
4798 | void ExportDecl::anchor() {} | |||
4799 | ||||
4800 | ExportDecl *ExportDecl::Create(ASTContext &C, DeclContext *DC, | |||
4801 | SourceLocation ExportLoc) { | |||
4802 | return new (C, DC) ExportDecl(DC, ExportLoc); | |||
4803 | } | |||
4804 | ||||
4805 | ExportDecl *ExportDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
4806 | return new (C, ID) ExportDecl(nullptr, SourceLocation()); | |||
4807 | } |
1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ | |||
2 | |* *| | |||
3 | |* Attribute classes' definitions *| | |||
4 | |* *| | |||
5 | |* Automatically generated file, do not edit! *| | |||
6 | |* *| | |||
7 | \*===----------------------------------------------------------------------===*/ | |||
8 | ||||
9 | #ifndef LLVM_CLANG_ATTR_CLASSES_INC | |||
10 | #define LLVM_CLANG_ATTR_CLASSES_INC | |||
11 | ||||
12 | class AArch64VectorPcsAttr : public InheritableAttr { | |||
13 | public: | |||
14 | static AArch64VectorPcsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
15 | auto *A = new (Ctx) AArch64VectorPcsAttr(Loc, Ctx, 0); | |||
16 | A->setImplicit(true); | |||
17 | return A; | |||
18 | } | |||
19 | ||||
20 | AArch64VectorPcsAttr(SourceRange R, ASTContext &Ctx | |||
21 | , unsigned SI | |||
22 | ) | |||
23 | : InheritableAttr(attr::AArch64VectorPcs, R, SI, false, false) | |||
24 | { | |||
25 | } | |||
26 | ||||
27 | AArch64VectorPcsAttr *clone(ASTContext &C) const; | |||
28 | void printPretty(raw_ostream &OS, | |||
29 | const PrintingPolicy &Policy) const; | |||
30 | const char *getSpelling() const; | |||
31 | ||||
32 | ||||
33 | static bool classof(const Attr *A) { return A->getKind() == attr::AArch64VectorPcs; } | |||
34 | }; | |||
35 | ||||
36 | class AMDGPUFlatWorkGroupSizeAttr : public InheritableAttr { | |||
37 | Expr * min; | |||
38 | ||||
39 | Expr * max; | |||
40 | ||||
41 | public: | |||
42 | static AMDGPUFlatWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, Expr * Min, Expr * Max, SourceRange Loc = SourceRange()) { | |||
43 | auto *A = new (Ctx) AMDGPUFlatWorkGroupSizeAttr(Loc, Ctx, Min, Max, 0); | |||
44 | A->setImplicit(true); | |||
45 | return A; | |||
46 | } | |||
47 | ||||
48 | AMDGPUFlatWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx | |||
49 | , Expr * Min | |||
50 | , Expr * Max | |||
51 | , unsigned SI | |||
52 | ) | |||
53 | : InheritableAttr(attr::AMDGPUFlatWorkGroupSize, R, SI, false, false) | |||
54 | , min(Min) | |||
55 | , max(Max) | |||
56 | { | |||
57 | } | |||
58 | ||||
59 | AMDGPUFlatWorkGroupSizeAttr *clone(ASTContext &C) const; | |||
60 | void printPretty(raw_ostream &OS, | |||
61 | const PrintingPolicy &Policy) const; | |||
62 | const char *getSpelling() const; | |||
63 | Expr * getMin() const { | |||
64 | return min; | |||
65 | } | |||
66 | ||||
67 | Expr * getMax() const { | |||
68 | return max; | |||
69 | } | |||
70 | ||||
71 | ||||
72 | ||||
73 | static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUFlatWorkGroupSize; } | |||
74 | }; | |||
75 | ||||
76 | class AMDGPUNumSGPRAttr : public InheritableAttr { | |||
77 | unsigned numSGPR; | |||
78 | ||||
79 | public: | |||
80 | static AMDGPUNumSGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumSGPR, SourceRange Loc = SourceRange()) { | |||
81 | auto *A = new (Ctx) AMDGPUNumSGPRAttr(Loc, Ctx, NumSGPR, 0); | |||
82 | A->setImplicit(true); | |||
83 | return A; | |||
84 | } | |||
85 | ||||
86 | AMDGPUNumSGPRAttr(SourceRange R, ASTContext &Ctx | |||
87 | , unsigned NumSGPR | |||
88 | , unsigned SI | |||
89 | ) | |||
90 | : InheritableAttr(attr::AMDGPUNumSGPR, R, SI, false, false) | |||
91 | , numSGPR(NumSGPR) | |||
92 | { | |||
93 | } | |||
94 | ||||
95 | AMDGPUNumSGPRAttr *clone(ASTContext &C) const; | |||
96 | void printPretty(raw_ostream &OS, | |||
97 | const PrintingPolicy &Policy) const; | |||
98 | const char *getSpelling() const; | |||
99 | unsigned getNumSGPR() const { | |||
100 | return numSGPR; | |||
101 | } | |||
102 | ||||
103 | ||||
104 | ||||
105 | static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumSGPR; } | |||
106 | }; | |||
107 | ||||
108 | class AMDGPUNumVGPRAttr : public InheritableAttr { | |||
109 | unsigned numVGPR; | |||
110 | ||||
111 | public: | |||
112 | static AMDGPUNumVGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumVGPR, SourceRange Loc = SourceRange()) { | |||
113 | auto *A = new (Ctx) AMDGPUNumVGPRAttr(Loc, Ctx, NumVGPR, 0); | |||
114 | A->setImplicit(true); | |||
115 | return A; | |||
116 | } | |||
117 | ||||
118 | AMDGPUNumVGPRAttr(SourceRange R, ASTContext &Ctx | |||
119 | , unsigned NumVGPR | |||
120 | , unsigned SI | |||
121 | ) | |||
122 | : InheritableAttr(attr::AMDGPUNumVGPR, R, SI, false, false) | |||
123 | , numVGPR(NumVGPR) | |||
124 | { | |||
125 | } | |||
126 | ||||
127 | AMDGPUNumVGPRAttr *clone(ASTContext &C) const; | |||
128 | void printPretty(raw_ostream &OS, | |||
129 | const PrintingPolicy &Policy) const; | |||
130 | const char *getSpelling() const; | |||
131 | unsigned getNumVGPR() const { | |||
132 | return numVGPR; | |||
133 | } | |||
134 | ||||
135 | ||||
136 | ||||
137 | static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumVGPR; } | |||
138 | }; | |||
139 | ||||
140 | class AMDGPUWavesPerEUAttr : public InheritableAttr { | |||
141 | Expr * min; | |||
142 | ||||
143 | Expr * max; | |||
144 | ||||
145 | public: | |||
146 | static AMDGPUWavesPerEUAttr *CreateImplicit(ASTContext &Ctx, Expr * Min, Expr * Max, SourceRange Loc = SourceRange()) { | |||
147 | auto *A = new (Ctx) AMDGPUWavesPerEUAttr(Loc, Ctx, Min, Max, 0); | |||
148 | A->setImplicit(true); | |||
149 | return A; | |||
150 | } | |||
151 | ||||
152 | AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx | |||
153 | , Expr * Min | |||
154 | , Expr * Max | |||
155 | , unsigned SI | |||
156 | ) | |||
157 | : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false) | |||
158 | , min(Min) | |||
159 | , max(Max) | |||
160 | { | |||
161 | } | |||
162 | ||||
163 | AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx | |||
164 | , Expr * Min | |||
165 | , unsigned SI | |||
166 | ) | |||
167 | : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false) | |||
168 | , min(Min) | |||
169 | , max() | |||
170 | { | |||
171 | } | |||
172 | ||||
173 | AMDGPUWavesPerEUAttr *clone(ASTContext &C) const; | |||
174 | void printPretty(raw_ostream &OS, | |||
175 | const PrintingPolicy &Policy) const; | |||
176 | const char *getSpelling() const; | |||
177 | Expr * getMin() const { | |||
178 | return min; | |||
179 | } | |||
180 | ||||
181 | Expr * getMax() const { | |||
182 | return max; | |||
183 | } | |||
184 | ||||
185 | ||||
186 | ||||
187 | static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUWavesPerEU; } | |||
188 | }; | |||
189 | ||||
190 | class ARMInterruptAttr : public InheritableAttr { | |||
191 | public: | |||
192 | enum InterruptType { | |||
193 | IRQ, | |||
194 | FIQ, | |||
195 | SWI, | |||
196 | ABORT, | |||
197 | UNDEF, | |||
198 | Generic | |||
199 | }; | |||
200 | private: | |||
201 | InterruptType interrupt; | |||
202 | ||||
203 | public: | |||
204 | static ARMInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) { | |||
205 | auto *A = new (Ctx) ARMInterruptAttr(Loc, Ctx, Interrupt, 0); | |||
206 | A->setImplicit(true); | |||
207 | return A; | |||
208 | } | |||
209 | ||||
210 | ARMInterruptAttr(SourceRange R, ASTContext &Ctx | |||
211 | , InterruptType Interrupt | |||
212 | , unsigned SI | |||
213 | ) | |||
214 | : InheritableAttr(attr::ARMInterrupt, R, SI, false, false) | |||
215 | , interrupt(Interrupt) | |||
216 | { | |||
217 | } | |||
218 | ||||
219 | ARMInterruptAttr(SourceRange R, ASTContext &Ctx | |||
220 | , unsigned SI | |||
221 | ) | |||
222 | : InheritableAttr(attr::ARMInterrupt, R, SI, false, false) | |||
223 | , interrupt(InterruptType(0)) | |||
224 | { | |||
225 | } | |||
226 | ||||
227 | ARMInterruptAttr *clone(ASTContext &C) const; | |||
228 | void printPretty(raw_ostream &OS, | |||
229 | const PrintingPolicy &Policy) const; | |||
230 | const char *getSpelling() const; | |||
231 | InterruptType getInterrupt() const { | |||
232 | return interrupt; | |||
233 | } | |||
234 | ||||
235 | static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) { | |||
236 | Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val) | |||
237 | .Case("IRQ", ARMInterruptAttr::IRQ) | |||
238 | .Case("FIQ", ARMInterruptAttr::FIQ) | |||
239 | .Case("SWI", ARMInterruptAttr::SWI) | |||
240 | .Case("ABORT", ARMInterruptAttr::ABORT) | |||
241 | .Case("UNDEF", ARMInterruptAttr::UNDEF) | |||
242 | .Case("", ARMInterruptAttr::Generic) | |||
243 | .Default(Optional<InterruptType>()); | |||
244 | if (R) { | |||
245 | Out = *R; | |||
246 | return true; | |||
247 | } | |||
248 | return false; | |||
249 | } | |||
250 | ||||
251 | static const char *ConvertInterruptTypeToStr(InterruptType Val) { | |||
252 | switch(Val) { | |||
253 | case ARMInterruptAttr::IRQ: return "IRQ"; | |||
254 | case ARMInterruptAttr::FIQ: return "FIQ"; | |||
255 | case ARMInterruptAttr::SWI: return "SWI"; | |||
256 | case ARMInterruptAttr::ABORT: return "ABORT"; | |||
257 | case ARMInterruptAttr::UNDEF: return "UNDEF"; | |||
258 | case ARMInterruptAttr::Generic: return ""; | |||
259 | } | |||
260 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 260); | |||
261 | } | |||
262 | ||||
263 | ||||
264 | static bool classof(const Attr *A) { return A->getKind() == attr::ARMInterrupt; } | |||
265 | }; | |||
266 | ||||
267 | class AVRInterruptAttr : public InheritableAttr { | |||
268 | public: | |||
269 | static AVRInterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
270 | auto *A = new (Ctx) AVRInterruptAttr(Loc, Ctx, 0); | |||
271 | A->setImplicit(true); | |||
272 | return A; | |||
273 | } | |||
274 | ||||
275 | AVRInterruptAttr(SourceRange R, ASTContext &Ctx | |||
276 | , unsigned SI | |||
277 | ) | |||
278 | : InheritableAttr(attr::AVRInterrupt, R, SI, false, false) | |||
279 | { | |||
280 | } | |||
281 | ||||
282 | AVRInterruptAttr *clone(ASTContext &C) const; | |||
283 | void printPretty(raw_ostream &OS, | |||
284 | const PrintingPolicy &Policy) const; | |||
285 | const char *getSpelling() const; | |||
286 | ||||
287 | ||||
288 | static bool classof(const Attr *A) { return A->getKind() == attr::AVRInterrupt; } | |||
289 | }; | |||
290 | ||||
291 | class AVRSignalAttr : public InheritableAttr { | |||
292 | public: | |||
293 | static AVRSignalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
294 | auto *A = new (Ctx) AVRSignalAttr(Loc, Ctx, 0); | |||
295 | A->setImplicit(true); | |||
296 | return A; | |||
297 | } | |||
298 | ||||
299 | AVRSignalAttr(SourceRange R, ASTContext &Ctx | |||
300 | , unsigned SI | |||
301 | ) | |||
302 | : InheritableAttr(attr::AVRSignal, R, SI, false, false) | |||
303 | { | |||
304 | } | |||
305 | ||||
306 | AVRSignalAttr *clone(ASTContext &C) const; | |||
307 | void printPretty(raw_ostream &OS, | |||
308 | const PrintingPolicy &Policy) const; | |||
309 | const char *getSpelling() const; | |||
310 | ||||
311 | ||||
312 | static bool classof(const Attr *A) { return A->getKind() == attr::AVRSignal; } | |||
313 | }; | |||
314 | ||||
315 | class AbiTagAttr : public Attr { | |||
316 | unsigned tags_Size; | |||
317 | StringRef *tags_; | |||
318 | ||||
319 | public: | |||
320 | static AbiTagAttr *CreateImplicit(ASTContext &Ctx, StringRef *Tags, unsigned TagsSize, SourceRange Loc = SourceRange()) { | |||
321 | auto *A = new (Ctx) AbiTagAttr(Loc, Ctx, Tags, TagsSize, 0); | |||
322 | A->setImplicit(true); | |||
323 | return A; | |||
324 | } | |||
325 | ||||
326 | AbiTagAttr(SourceRange R, ASTContext &Ctx | |||
327 | , StringRef *Tags, unsigned TagsSize | |||
328 | , unsigned SI | |||
329 | ) | |||
330 | : Attr(attr::AbiTag, R, SI, false) | |||
331 | , tags_Size(TagsSize), tags_(new (Ctx, 16) StringRef[tags_Size]) | |||
332 | { | |||
333 | for (size_t I = 0, E = tags_Size; I != E; | |||
334 | ++I) { | |||
335 | StringRef Ref = Tags[I]; | |||
336 | if (!Ref.empty()) { | |||
337 | char *Mem = new (Ctx, 1) char[Ref.size()]; | |||
338 | std::memcpy(Mem, Ref.data(), Ref.size()); | |||
339 | tags_[I] = StringRef(Mem, Ref.size()); | |||
340 | } | |||
341 | } | |||
342 | } | |||
343 | ||||
344 | AbiTagAttr(SourceRange R, ASTContext &Ctx | |||
345 | , unsigned SI | |||
346 | ) | |||
347 | : Attr(attr::AbiTag, R, SI, false) | |||
348 | , tags_Size(0), tags_(nullptr) | |||
349 | { | |||
350 | } | |||
351 | ||||
352 | AbiTagAttr *clone(ASTContext &C) const; | |||
353 | void printPretty(raw_ostream &OS, | |||
354 | const PrintingPolicy &Policy) const; | |||
355 | const char *getSpelling() const; | |||
356 | typedef StringRef* tags_iterator; | |||
357 | tags_iterator tags_begin() const { return tags_; } | |||
358 | tags_iterator tags_end() const { return tags_ + tags_Size; } | |||
359 | unsigned tags_size() const { return tags_Size; } | |||
360 | llvm::iterator_range<tags_iterator> tags() const { return llvm::make_range(tags_begin(), tags_end()); } | |||
361 | ||||
362 | ||||
363 | ||||
364 | ||||
365 | static bool classof(const Attr *A) { return A->getKind() == attr::AbiTag; } | |||
366 | }; | |||
367 | ||||
368 | class AcquireCapabilityAttr : public InheritableAttr { | |||
369 | unsigned args_Size; | |||
370 | Expr * *args_; | |||
371 | ||||
372 | public: | |||
373 | enum Spelling { | |||
374 | GNU_acquire_capability = 0, | |||
375 | CXX11_clang_acquire_capability = 1, | |||
376 | GNU_acquire_shared_capability = 2, | |||
377 | CXX11_clang_acquire_shared_capability = 3, | |||
378 | GNU_exclusive_lock_function = 4, | |||
379 | GNU_shared_lock_function = 5 | |||
380 | }; | |||
381 | ||||
382 | static AcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
383 | auto *A = new (Ctx) AcquireCapabilityAttr(Loc, Ctx, Args, ArgsSize, S); | |||
384 | A->setImplicit(true); | |||
385 | return A; | |||
386 | } | |||
387 | ||||
388 | AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
389 | , Expr * *Args, unsigned ArgsSize | |||
390 | , unsigned SI | |||
391 | ) | |||
392 | : InheritableAttr(attr::AcquireCapability, R, SI, true, true) | |||
393 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
394 | { | |||
395 | std::copy(Args, Args + args_Size, args_); | |||
396 | } | |||
397 | ||||
398 | AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
399 | , unsigned SI | |||
400 | ) | |||
401 | : InheritableAttr(attr::AcquireCapability, R, SI, true, true) | |||
402 | , args_Size(0), args_(nullptr) | |||
403 | { | |||
404 | } | |||
405 | ||||
406 | AcquireCapabilityAttr *clone(ASTContext &C) const; | |||
407 | void printPretty(raw_ostream &OS, | |||
408 | const PrintingPolicy &Policy) const; | |||
409 | const char *getSpelling() const; | |||
410 | Spelling getSemanticSpelling() const { | |||
411 | switch (SpellingListIndex) { | |||
412 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 412); | |||
413 | case 0: return GNU_acquire_capability; | |||
414 | case 1: return CXX11_clang_acquire_capability; | |||
415 | case 2: return GNU_acquire_shared_capability; | |||
416 | case 3: return CXX11_clang_acquire_shared_capability; | |||
417 | case 4: return GNU_exclusive_lock_function; | |||
418 | case 5: return GNU_shared_lock_function; | |||
419 | } | |||
420 | } | |||
421 | bool isShared() const { return SpellingListIndex == 2 || | |||
422 | SpellingListIndex == 3 || | |||
423 | SpellingListIndex == 5; } | |||
424 | typedef Expr ** args_iterator; | |||
425 | args_iterator args_begin() const { return args_; } | |||
426 | args_iterator args_end() const { return args_ + args_Size; } | |||
427 | unsigned args_size() const { return args_Size; } | |||
428 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
429 | ||||
430 | ||||
431 | ||||
432 | ||||
433 | static bool classof(const Attr *A) { return A->getKind() == attr::AcquireCapability; } | |||
434 | }; | |||
435 | ||||
436 | class AcquiredAfterAttr : public InheritableAttr { | |||
437 | unsigned args_Size; | |||
438 | Expr * *args_; | |||
439 | ||||
440 | public: | |||
441 | static AcquiredAfterAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
442 | auto *A = new (Ctx) AcquiredAfterAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
443 | A->setImplicit(true); | |||
444 | return A; | |||
445 | } | |||
446 | ||||
447 | AcquiredAfterAttr(SourceRange R, ASTContext &Ctx | |||
448 | , Expr * *Args, unsigned ArgsSize | |||
449 | , unsigned SI | |||
450 | ) | |||
451 | : InheritableAttr(attr::AcquiredAfter, R, SI, true, true) | |||
452 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
453 | { | |||
454 | std::copy(Args, Args + args_Size, args_); | |||
455 | } | |||
456 | ||||
457 | AcquiredAfterAttr(SourceRange R, ASTContext &Ctx | |||
458 | , unsigned SI | |||
459 | ) | |||
460 | : InheritableAttr(attr::AcquiredAfter, R, SI, true, true) | |||
461 | , args_Size(0), args_(nullptr) | |||
462 | { | |||
463 | } | |||
464 | ||||
465 | AcquiredAfterAttr *clone(ASTContext &C) const; | |||
466 | void printPretty(raw_ostream &OS, | |||
467 | const PrintingPolicy &Policy) const; | |||
468 | const char *getSpelling() const; | |||
469 | typedef Expr ** args_iterator; | |||
470 | args_iterator args_begin() const { return args_; } | |||
471 | args_iterator args_end() const { return args_ + args_Size; } | |||
472 | unsigned args_size() const { return args_Size; } | |||
473 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
474 | ||||
475 | ||||
476 | ||||
477 | ||||
478 | static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredAfter; } | |||
479 | }; | |||
480 | ||||
481 | class AcquiredBeforeAttr : public InheritableAttr { | |||
482 | unsigned args_Size; | |||
483 | Expr * *args_; | |||
484 | ||||
485 | public: | |||
486 | static AcquiredBeforeAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
487 | auto *A = new (Ctx) AcquiredBeforeAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
488 | A->setImplicit(true); | |||
489 | return A; | |||
490 | } | |||
491 | ||||
492 | AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx | |||
493 | , Expr * *Args, unsigned ArgsSize | |||
494 | , unsigned SI | |||
495 | ) | |||
496 | : InheritableAttr(attr::AcquiredBefore, R, SI, true, true) | |||
497 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
498 | { | |||
499 | std::copy(Args, Args + args_Size, args_); | |||
500 | } | |||
501 | ||||
502 | AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx | |||
503 | , unsigned SI | |||
504 | ) | |||
505 | : InheritableAttr(attr::AcquiredBefore, R, SI, true, true) | |||
506 | , args_Size(0), args_(nullptr) | |||
507 | { | |||
508 | } | |||
509 | ||||
510 | AcquiredBeforeAttr *clone(ASTContext &C) const; | |||
511 | void printPretty(raw_ostream &OS, | |||
512 | const PrintingPolicy &Policy) const; | |||
513 | const char *getSpelling() const; | |||
514 | typedef Expr ** args_iterator; | |||
515 | args_iterator args_begin() const { return args_; } | |||
516 | args_iterator args_end() const { return args_ + args_Size; } | |||
517 | unsigned args_size() const { return args_Size; } | |||
518 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
519 | ||||
520 | ||||
521 | ||||
522 | ||||
523 | static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredBefore; } | |||
524 | }; | |||
525 | ||||
526 | class AddressSpaceAttr : public TypeAttr { | |||
527 | int addressSpace; | |||
528 | ||||
529 | public: | |||
530 | static AddressSpaceAttr *CreateImplicit(ASTContext &Ctx, int AddressSpace, SourceRange Loc = SourceRange()) { | |||
531 | auto *A = new (Ctx) AddressSpaceAttr(Loc, Ctx, AddressSpace, 0); | |||
532 | A->setImplicit(true); | |||
533 | return A; | |||
534 | } | |||
535 | ||||
536 | AddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
537 | , int AddressSpace | |||
538 | , unsigned SI | |||
539 | ) | |||
540 | : TypeAttr(attr::AddressSpace, R, SI, false) | |||
541 | , addressSpace(AddressSpace) | |||
542 | { | |||
543 | } | |||
544 | ||||
545 | AddressSpaceAttr *clone(ASTContext &C) const; | |||
546 | void printPretty(raw_ostream &OS, | |||
547 | const PrintingPolicy &Policy) const; | |||
548 | const char *getSpelling() const; | |||
549 | int getAddressSpace() const { | |||
550 | return addressSpace; | |||
551 | } | |||
552 | ||||
553 | ||||
554 | ||||
555 | static bool classof(const Attr *A) { return A->getKind() == attr::AddressSpace; } | |||
556 | }; | |||
557 | ||||
558 | class AliasAttr : public Attr { | |||
559 | unsigned aliaseeLength; | |||
560 | char *aliasee; | |||
561 | ||||
562 | public: | |||
563 | static AliasAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) { | |||
564 | auto *A = new (Ctx) AliasAttr(Loc, Ctx, Aliasee, 0); | |||
565 | A->setImplicit(true); | |||
566 | return A; | |||
567 | } | |||
568 | ||||
569 | AliasAttr(SourceRange R, ASTContext &Ctx | |||
570 | , llvm::StringRef Aliasee | |||
571 | , unsigned SI | |||
572 | ) | |||
573 | : Attr(attr::Alias, R, SI, false) | |||
574 | , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength]) | |||
575 | { | |||
576 | if (!Aliasee.empty()) | |||
577 | std::memcpy(aliasee, Aliasee.data(), aliaseeLength); | |||
578 | } | |||
579 | ||||
580 | AliasAttr *clone(ASTContext &C) const; | |||
581 | void printPretty(raw_ostream &OS, | |||
582 | const PrintingPolicy &Policy) const; | |||
583 | const char *getSpelling() const; | |||
584 | llvm::StringRef getAliasee() const { | |||
585 | return llvm::StringRef(aliasee, aliaseeLength); | |||
586 | } | |||
587 | unsigned getAliaseeLength() const { | |||
588 | return aliaseeLength; | |||
589 | } | |||
590 | void setAliasee(ASTContext &C, llvm::StringRef S) { | |||
591 | aliaseeLength = S.size(); | |||
592 | this->aliasee = new (C, 1) char [aliaseeLength]; | |||
593 | if (!S.empty()) | |||
594 | std::memcpy(this->aliasee, S.data(), aliaseeLength); | |||
595 | } | |||
596 | ||||
597 | ||||
598 | ||||
599 | static bool classof(const Attr *A) { return A->getKind() == attr::Alias; } | |||
600 | }; | |||
601 | ||||
602 | class AlignMac68kAttr : public InheritableAttr { | |||
603 | public: | |||
604 | static AlignMac68kAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
605 | auto *A = new (Ctx) AlignMac68kAttr(Loc, Ctx, 0); | |||
606 | A->setImplicit(true); | |||
607 | return A; | |||
608 | } | |||
609 | ||||
610 | AlignMac68kAttr(SourceRange R, ASTContext &Ctx | |||
611 | , unsigned SI | |||
612 | ) | |||
613 | : InheritableAttr(attr::AlignMac68k, R, SI, false, false) | |||
614 | { | |||
615 | } | |||
616 | ||||
617 | AlignMac68kAttr *clone(ASTContext &C) const; | |||
618 | void printPretty(raw_ostream &OS, | |||
619 | const PrintingPolicy &Policy) const; | |||
620 | const char *getSpelling() const; | |||
621 | ||||
622 | ||||
623 | static bool classof(const Attr *A) { return A->getKind() == attr::AlignMac68k; } | |||
624 | }; | |||
625 | ||||
626 | class AlignValueAttr : public Attr { | |||
627 | Expr * alignment; | |||
628 | ||||
629 | public: | |||
630 | static AlignValueAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, SourceRange Loc = SourceRange()) { | |||
631 | auto *A = new (Ctx) AlignValueAttr(Loc, Ctx, Alignment, 0); | |||
632 | A->setImplicit(true); | |||
633 | return A; | |||
634 | } | |||
635 | ||||
636 | AlignValueAttr(SourceRange R, ASTContext &Ctx | |||
637 | , Expr * Alignment | |||
638 | , unsigned SI | |||
639 | ) | |||
640 | : Attr(attr::AlignValue, R, SI, false) | |||
641 | , alignment(Alignment) | |||
642 | { | |||
643 | } | |||
644 | ||||
645 | AlignValueAttr *clone(ASTContext &C) const; | |||
646 | void printPretty(raw_ostream &OS, | |||
647 | const PrintingPolicy &Policy) const; | |||
648 | const char *getSpelling() const; | |||
649 | Expr * getAlignment() const { | |||
650 | return alignment; | |||
651 | } | |||
652 | ||||
653 | ||||
654 | ||||
655 | static bool classof(const Attr *A) { return A->getKind() == attr::AlignValue; } | |||
656 | }; | |||
657 | ||||
658 | class AlignedAttr : public InheritableAttr { | |||
659 | bool isalignmentExpr; | |||
660 | union { | |||
661 | Expr *alignmentExpr; | |||
662 | TypeSourceInfo *alignmentType; | |||
663 | }; | |||
664 | ||||
665 | public: | |||
666 | enum Spelling { | |||
667 | GNU_aligned = 0, | |||
668 | CXX11_gnu_aligned = 1, | |||
669 | Declspec_align = 2, | |||
670 | Keyword_alignas = 3, | |||
671 | Keyword_Alignas = 4 | |||
672 | }; | |||
673 | ||||
674 | static AlignedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool IsAlignmentExpr, void *Alignment, SourceRange Loc = SourceRange()) { | |||
675 | auto *A = new (Ctx) AlignedAttr(Loc, Ctx, IsAlignmentExpr, Alignment, S); | |||
676 | A->setImplicit(true); | |||
677 | return A; | |||
678 | } | |||
679 | ||||
680 | AlignedAttr(SourceRange R, ASTContext &Ctx | |||
681 | , bool IsAlignmentExpr, void *Alignment | |||
682 | , unsigned SI | |||
683 | ) | |||
684 | : InheritableAttr(attr::Aligned, R, SI, false, false) | |||
685 | , isalignmentExpr(IsAlignmentExpr) | |||
686 | { | |||
687 | if (isalignmentExpr) | |||
688 | alignmentExpr = reinterpret_cast<Expr *>(Alignment); | |||
689 | else | |||
690 | alignmentType = reinterpret_cast<TypeSourceInfo *>(Alignment); | |||
691 | } | |||
692 | ||||
693 | AlignedAttr(SourceRange R, ASTContext &Ctx | |||
694 | , unsigned SI | |||
695 | ) | |||
696 | : InheritableAttr(attr::Aligned, R, SI, false, false) | |||
697 | , isalignmentExpr(false) | |||
698 | { | |||
699 | } | |||
700 | ||||
701 | AlignedAttr *clone(ASTContext &C) const; | |||
702 | void printPretty(raw_ostream &OS, | |||
703 | const PrintingPolicy &Policy) const; | |||
704 | const char *getSpelling() const; | |||
705 | Spelling getSemanticSpelling() const { | |||
706 | switch (SpellingListIndex) { | |||
707 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 707); | |||
708 | case 0: return GNU_aligned; | |||
709 | case 1: return CXX11_gnu_aligned; | |||
710 | case 2: return Declspec_align; | |||
711 | case 3: return Keyword_alignas; | |||
712 | case 4: return Keyword_Alignas; | |||
713 | } | |||
714 | } | |||
715 | bool isGNU() const { return SpellingListIndex == 0 || | |||
716 | SpellingListIndex == 1; } | |||
717 | bool isC11() const { return SpellingListIndex == 4; } | |||
718 | bool isAlignas() const { return SpellingListIndex == 3 || | |||
719 | SpellingListIndex == 4; } | |||
720 | bool isDeclspec() const { return SpellingListIndex == 2; } | |||
721 | bool isAlignmentDependent() const; | |||
722 | unsigned getAlignment(ASTContext &Ctx) const; | |||
723 | bool isAlignmentExpr() const { | |||
724 | return isalignmentExpr; | |||
725 | } | |||
726 | Expr *getAlignmentExpr() const { | |||
727 | assert(isalignmentExpr)((isalignmentExpr) ? static_cast<void> (0) : __assert_fail ("isalignmentExpr", "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 727, __PRETTY_FUNCTION__)); | |||
728 | return alignmentExpr; | |||
729 | } | |||
730 | TypeSourceInfo *getAlignmentType() const { | |||
731 | assert(!isalignmentExpr)((!isalignmentExpr) ? static_cast<void> (0) : __assert_fail ("!isalignmentExpr", "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 731, __PRETTY_FUNCTION__)); | |||
732 | return alignmentType; | |||
733 | } | |||
734 | ||||
735 | ||||
736 | ||||
737 | static bool classof(const Attr *A) { return A->getKind() == attr::Aligned; } | |||
738 | }; | |||
739 | ||||
740 | class AllocAlignAttr : public InheritableAttr { | |||
741 | ParamIdx paramIndex; | |||
742 | ||||
743 | public: | |||
744 | static AllocAlignAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ParamIndex, SourceRange Loc = SourceRange()) { | |||
745 | auto *A = new (Ctx) AllocAlignAttr(Loc, Ctx, ParamIndex, 0); | |||
746 | A->setImplicit(true); | |||
747 | return A; | |||
748 | } | |||
749 | ||||
750 | AllocAlignAttr(SourceRange R, ASTContext &Ctx | |||
751 | , ParamIdx ParamIndex | |||
752 | , unsigned SI | |||
753 | ) | |||
754 | : InheritableAttr(attr::AllocAlign, R, SI, false, false) | |||
755 | , paramIndex(ParamIndex) | |||
756 | { | |||
757 | } | |||
758 | ||||
759 | AllocAlignAttr *clone(ASTContext &C) const; | |||
760 | void printPretty(raw_ostream &OS, | |||
761 | const PrintingPolicy &Policy) const; | |||
762 | const char *getSpelling() const; | |||
763 | ParamIdx getParamIndex() const { | |||
764 | return paramIndex; | |||
765 | } | |||
766 | ||||
767 | ||||
768 | ||||
769 | static bool classof(const Attr *A) { return A->getKind() == attr::AllocAlign; } | |||
770 | }; | |||
771 | ||||
772 | class AllocSizeAttr : public InheritableAttr { | |||
773 | ParamIdx elemSizeParam; | |||
774 | ||||
775 | ParamIdx numElemsParam; | |||
776 | ||||
777 | public: | |||
778 | static AllocSizeAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ElemSizeParam, ParamIdx NumElemsParam, SourceRange Loc = SourceRange()) { | |||
779 | auto *A = new (Ctx) AllocSizeAttr(Loc, Ctx, ElemSizeParam, NumElemsParam, 0); | |||
780 | A->setImplicit(true); | |||
781 | return A; | |||
782 | } | |||
783 | ||||
784 | AllocSizeAttr(SourceRange R, ASTContext &Ctx | |||
785 | , ParamIdx ElemSizeParam | |||
786 | , ParamIdx NumElemsParam | |||
787 | , unsigned SI | |||
788 | ) | |||
789 | : InheritableAttr(attr::AllocSize, R, SI, false, false) | |||
790 | , elemSizeParam(ElemSizeParam) | |||
791 | , numElemsParam(NumElemsParam) | |||
792 | { | |||
793 | } | |||
794 | ||||
795 | AllocSizeAttr(SourceRange R, ASTContext &Ctx | |||
796 | , ParamIdx ElemSizeParam | |||
797 | , unsigned SI | |||
798 | ) | |||
799 | : InheritableAttr(attr::AllocSize, R, SI, false, false) | |||
800 | , elemSizeParam(ElemSizeParam) | |||
801 | , numElemsParam() | |||
802 | { | |||
803 | } | |||
804 | ||||
805 | AllocSizeAttr *clone(ASTContext &C) const; | |||
806 | void printPretty(raw_ostream &OS, | |||
807 | const PrintingPolicy &Policy) const; | |||
808 | const char *getSpelling() const; | |||
809 | ParamIdx getElemSizeParam() const { | |||
810 | return elemSizeParam; | |||
811 | } | |||
812 | ||||
813 | ParamIdx getNumElemsParam() const { | |||
814 | return numElemsParam; | |||
815 | } | |||
816 | ||||
817 | ||||
818 | ||||
819 | static bool classof(const Attr *A) { return A->getKind() == attr::AllocSize; } | |||
820 | }; | |||
821 | ||||
822 | class AlwaysDestroyAttr : public InheritableAttr { | |||
823 | public: | |||
824 | static AlwaysDestroyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
825 | auto *A = new (Ctx) AlwaysDestroyAttr(Loc, Ctx, 0); | |||
826 | A->setImplicit(true); | |||
827 | return A; | |||
828 | } | |||
829 | ||||
830 | AlwaysDestroyAttr(SourceRange R, ASTContext &Ctx | |||
831 | , unsigned SI | |||
832 | ) | |||
833 | : InheritableAttr(attr::AlwaysDestroy, R, SI, false, false) | |||
834 | { | |||
835 | } | |||
836 | ||||
837 | AlwaysDestroyAttr *clone(ASTContext &C) const; | |||
838 | void printPretty(raw_ostream &OS, | |||
839 | const PrintingPolicy &Policy) const; | |||
840 | const char *getSpelling() const; | |||
841 | ||||
842 | ||||
843 | static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysDestroy; } | |||
844 | }; | |||
845 | ||||
846 | class AlwaysInlineAttr : public InheritableAttr { | |||
847 | public: | |||
848 | enum Spelling { | |||
849 | GNU_always_inline = 0, | |||
850 | CXX11_gnu_always_inline = 1, | |||
851 | Keyword_forceinline = 2 | |||
852 | }; | |||
853 | ||||
854 | static AlwaysInlineAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
855 | auto *A = new (Ctx) AlwaysInlineAttr(Loc, Ctx, S); | |||
856 | A->setImplicit(true); | |||
857 | return A; | |||
858 | } | |||
859 | ||||
860 | AlwaysInlineAttr(SourceRange R, ASTContext &Ctx | |||
861 | , unsigned SI | |||
862 | ) | |||
863 | : InheritableAttr(attr::AlwaysInline, R, SI, false, false) | |||
864 | { | |||
865 | } | |||
866 | ||||
867 | AlwaysInlineAttr *clone(ASTContext &C) const; | |||
868 | void printPretty(raw_ostream &OS, | |||
869 | const PrintingPolicy &Policy) const; | |||
870 | const char *getSpelling() const; | |||
871 | Spelling getSemanticSpelling() const { | |||
872 | switch (SpellingListIndex) { | |||
873 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 873); | |||
874 | case 0: return GNU_always_inline; | |||
875 | case 1: return CXX11_gnu_always_inline; | |||
876 | case 2: return Keyword_forceinline; | |||
877 | } | |||
878 | } | |||
879 | ||||
880 | ||||
881 | static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysInline; } | |||
882 | }; | |||
883 | ||||
884 | class AnalyzerNoReturnAttr : public InheritableAttr { | |||
885 | public: | |||
886 | static AnalyzerNoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
887 | auto *A = new (Ctx) AnalyzerNoReturnAttr(Loc, Ctx, 0); | |||
888 | A->setImplicit(true); | |||
889 | return A; | |||
890 | } | |||
891 | ||||
892 | AnalyzerNoReturnAttr(SourceRange R, ASTContext &Ctx | |||
893 | , unsigned SI | |||
894 | ) | |||
895 | : InheritableAttr(attr::AnalyzerNoReturn, R, SI, false, false) | |||
896 | { | |||
897 | } | |||
898 | ||||
899 | AnalyzerNoReturnAttr *clone(ASTContext &C) const; | |||
900 | void printPretty(raw_ostream &OS, | |||
901 | const PrintingPolicy &Policy) const; | |||
902 | const char *getSpelling() const; | |||
903 | ||||
904 | ||||
905 | static bool classof(const Attr *A) { return A->getKind() == attr::AnalyzerNoReturn; } | |||
906 | }; | |||
907 | ||||
908 | class AnnotateAttr : public InheritableParamAttr { | |||
909 | unsigned annotationLength; | |||
910 | char *annotation; | |||
911 | ||||
912 | public: | |||
913 | static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Annotation, SourceRange Loc = SourceRange()) { | |||
914 | auto *A = new (Ctx) AnnotateAttr(Loc, Ctx, Annotation, 0); | |||
915 | A->setImplicit(true); | |||
916 | return A; | |||
917 | } | |||
918 | ||||
919 | AnnotateAttr(SourceRange R, ASTContext &Ctx | |||
920 | , llvm::StringRef Annotation | |||
921 | , unsigned SI | |||
922 | ) | |||
923 | : InheritableParamAttr(attr::Annotate, R, SI, false, false) | |||
924 | , annotationLength(Annotation.size()),annotation(new (Ctx, 1) char[annotationLength]) | |||
925 | { | |||
926 | if (!Annotation.empty()) | |||
927 | std::memcpy(annotation, Annotation.data(), annotationLength); | |||
928 | } | |||
929 | ||||
930 | AnnotateAttr *clone(ASTContext &C) const; | |||
931 | void printPretty(raw_ostream &OS, | |||
932 | const PrintingPolicy &Policy) const; | |||
933 | const char *getSpelling() const; | |||
934 | llvm::StringRef getAnnotation() const { | |||
935 | return llvm::StringRef(annotation, annotationLength); | |||
936 | } | |||
937 | unsigned getAnnotationLength() const { | |||
938 | return annotationLength; | |||
939 | } | |||
940 | void setAnnotation(ASTContext &C, llvm::StringRef S) { | |||
941 | annotationLength = S.size(); | |||
942 | this->annotation = new (C, 1) char [annotationLength]; | |||
943 | if (!S.empty()) | |||
944 | std::memcpy(this->annotation, S.data(), annotationLength); | |||
945 | } | |||
946 | ||||
947 | ||||
948 | ||||
949 | static bool classof(const Attr *A) { return A->getKind() == attr::Annotate; } | |||
950 | }; | |||
951 | ||||
952 | class AnyX86InterruptAttr : public InheritableAttr { | |||
953 | public: | |||
954 | static AnyX86InterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
955 | auto *A = new (Ctx) AnyX86InterruptAttr(Loc, Ctx, 0); | |||
956 | A->setImplicit(true); | |||
957 | return A; | |||
958 | } | |||
959 | ||||
960 | AnyX86InterruptAttr(SourceRange R, ASTContext &Ctx | |||
961 | , unsigned SI | |||
962 | ) | |||
963 | : InheritableAttr(attr::AnyX86Interrupt, R, SI, false, false) | |||
964 | { | |||
965 | } | |||
966 | ||||
967 | AnyX86InterruptAttr *clone(ASTContext &C) const; | |||
968 | void printPretty(raw_ostream &OS, | |||
969 | const PrintingPolicy &Policy) const; | |||
970 | const char *getSpelling() const; | |||
971 | ||||
972 | ||||
973 | static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86Interrupt; } | |||
974 | }; | |||
975 | ||||
976 | class AnyX86NoCallerSavedRegistersAttr : public InheritableAttr { | |||
977 | public: | |||
978 | static AnyX86NoCallerSavedRegistersAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
979 | auto *A = new (Ctx) AnyX86NoCallerSavedRegistersAttr(Loc, Ctx, 0); | |||
980 | A->setImplicit(true); | |||
981 | return A; | |||
982 | } | |||
983 | ||||
984 | AnyX86NoCallerSavedRegistersAttr(SourceRange R, ASTContext &Ctx | |||
985 | , unsigned SI | |||
986 | ) | |||
987 | : InheritableAttr(attr::AnyX86NoCallerSavedRegisters, R, SI, false, false) | |||
988 | { | |||
989 | } | |||
990 | ||||
991 | AnyX86NoCallerSavedRegistersAttr *clone(ASTContext &C) const; | |||
992 | void printPretty(raw_ostream &OS, | |||
993 | const PrintingPolicy &Policy) const; | |||
994 | const char *getSpelling() const; | |||
995 | ||||
996 | ||||
997 | static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCallerSavedRegisters; } | |||
998 | }; | |||
999 | ||||
1000 | class AnyX86NoCfCheckAttr : public InheritableAttr { | |||
1001 | public: | |||
1002 | static AnyX86NoCfCheckAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1003 | auto *A = new (Ctx) AnyX86NoCfCheckAttr(Loc, Ctx, 0); | |||
1004 | A->setImplicit(true); | |||
1005 | return A; | |||
1006 | } | |||
1007 | ||||
1008 | AnyX86NoCfCheckAttr(SourceRange R, ASTContext &Ctx | |||
1009 | , unsigned SI | |||
1010 | ) | |||
1011 | : InheritableAttr(attr::AnyX86NoCfCheck, R, SI, false, false) | |||
1012 | { | |||
1013 | } | |||
1014 | ||||
1015 | AnyX86NoCfCheckAttr *clone(ASTContext &C) const; | |||
1016 | void printPretty(raw_ostream &OS, | |||
1017 | const PrintingPolicy &Policy) const; | |||
1018 | const char *getSpelling() const; | |||
1019 | ||||
1020 | ||||
1021 | static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCfCheck; } | |||
1022 | }; | |||
1023 | ||||
1024 | class ArcWeakrefUnavailableAttr : public InheritableAttr { | |||
1025 | public: | |||
1026 | static ArcWeakrefUnavailableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1027 | auto *A = new (Ctx) ArcWeakrefUnavailableAttr(Loc, Ctx, 0); | |||
1028 | A->setImplicit(true); | |||
1029 | return A; | |||
1030 | } | |||
1031 | ||||
1032 | ArcWeakrefUnavailableAttr(SourceRange R, ASTContext &Ctx | |||
1033 | , unsigned SI | |||
1034 | ) | |||
1035 | : InheritableAttr(attr::ArcWeakrefUnavailable, R, SI, false, false) | |||
1036 | { | |||
1037 | } | |||
1038 | ||||
1039 | ArcWeakrefUnavailableAttr *clone(ASTContext &C) const; | |||
1040 | void printPretty(raw_ostream &OS, | |||
1041 | const PrintingPolicy &Policy) const; | |||
1042 | const char *getSpelling() const; | |||
1043 | ||||
1044 | ||||
1045 | static bool classof(const Attr *A) { return A->getKind() == attr::ArcWeakrefUnavailable; } | |||
1046 | }; | |||
1047 | ||||
1048 | class ArgumentWithTypeTagAttr : public InheritableAttr { | |||
1049 | IdentifierInfo * argumentKind; | |||
1050 | ||||
1051 | ParamIdx argumentIdx; | |||
1052 | ||||
1053 | ParamIdx typeTagIdx; | |||
1054 | ||||
1055 | bool isPointer; | |||
1056 | ||||
1057 | public: | |||
1058 | enum Spelling { | |||
1059 | GNU_argument_with_type_tag = 0, | |||
1060 | CXX11_clang_argument_with_type_tag = 1, | |||
1061 | C2x_clang_argument_with_type_tag = 2, | |||
1062 | GNU_pointer_with_type_tag = 3, | |||
1063 | CXX11_clang_pointer_with_type_tag = 4, | |||
1064 | C2x_clang_pointer_with_type_tag = 5 | |||
1065 | }; | |||
1066 | ||||
1067 | static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, bool IsPointer, SourceRange Loc = SourceRange()) { | |||
1068 | auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, IsPointer, S); | |||
1069 | A->setImplicit(true); | |||
1070 | return A; | |||
1071 | } | |||
1072 | ||||
1073 | static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, SourceRange Loc = SourceRange()) { | |||
1074 | auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, S); | |||
1075 | A->setImplicit(true); | |||
1076 | return A; | |||
1077 | } | |||
1078 | ||||
1079 | ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx | |||
1080 | , IdentifierInfo * ArgumentKind | |||
1081 | , ParamIdx ArgumentIdx | |||
1082 | , ParamIdx TypeTagIdx | |||
1083 | , bool IsPointer | |||
1084 | , unsigned SI | |||
1085 | ) | |||
1086 | : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false) | |||
1087 | , argumentKind(ArgumentKind) | |||
1088 | , argumentIdx(ArgumentIdx) | |||
1089 | , typeTagIdx(TypeTagIdx) | |||
1090 | , isPointer(IsPointer) | |||
1091 | { | |||
1092 | } | |||
1093 | ||||
1094 | ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx | |||
1095 | , IdentifierInfo * ArgumentKind | |||
1096 | , ParamIdx ArgumentIdx | |||
1097 | , ParamIdx TypeTagIdx | |||
1098 | , unsigned SI | |||
1099 | ) | |||
1100 | : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false) | |||
1101 | , argumentKind(ArgumentKind) | |||
1102 | , argumentIdx(ArgumentIdx) | |||
1103 | , typeTagIdx(TypeTagIdx) | |||
1104 | , isPointer() | |||
1105 | { | |||
1106 | } | |||
1107 | ||||
1108 | ArgumentWithTypeTagAttr *clone(ASTContext &C) const; | |||
1109 | void printPretty(raw_ostream &OS, | |||
1110 | const PrintingPolicy &Policy) const; | |||
1111 | const char *getSpelling() const; | |||
1112 | Spelling getSemanticSpelling() const { | |||
1113 | switch (SpellingListIndex) { | |||
1114 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 1114); | |||
1115 | case 0: return GNU_argument_with_type_tag; | |||
1116 | case 1: return CXX11_clang_argument_with_type_tag; | |||
1117 | case 2: return C2x_clang_argument_with_type_tag; | |||
1118 | case 3: return GNU_pointer_with_type_tag; | |||
1119 | case 4: return CXX11_clang_pointer_with_type_tag; | |||
1120 | case 5: return C2x_clang_pointer_with_type_tag; | |||
1121 | } | |||
1122 | } | |||
1123 | IdentifierInfo * getArgumentKind() const { | |||
1124 | return argumentKind; | |||
1125 | } | |||
1126 | ||||
1127 | ParamIdx getArgumentIdx() const { | |||
1128 | return argumentIdx; | |||
1129 | } | |||
1130 | ||||
1131 | ParamIdx getTypeTagIdx() const { | |||
1132 | return typeTagIdx; | |||
1133 | } | |||
1134 | ||||
1135 | bool getIsPointer() const { | |||
1136 | return isPointer; | |||
1137 | } | |||
1138 | ||||
1139 | ||||
1140 | ||||
1141 | static bool classof(const Attr *A) { return A->getKind() == attr::ArgumentWithTypeTag; } | |||
1142 | }; | |||
1143 | ||||
1144 | class ArtificialAttr : public InheritableAttr { | |||
1145 | public: | |||
1146 | static ArtificialAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1147 | auto *A = new (Ctx) ArtificialAttr(Loc, Ctx, 0); | |||
1148 | A->setImplicit(true); | |||
1149 | return A; | |||
1150 | } | |||
1151 | ||||
1152 | ArtificialAttr(SourceRange R, ASTContext &Ctx | |||
1153 | , unsigned SI | |||
1154 | ) | |||
1155 | : InheritableAttr(attr::Artificial, R, SI, false, false) | |||
1156 | { | |||
1157 | } | |||
1158 | ||||
1159 | ArtificialAttr *clone(ASTContext &C) const; | |||
1160 | void printPretty(raw_ostream &OS, | |||
1161 | const PrintingPolicy &Policy) const; | |||
1162 | const char *getSpelling() const; | |||
1163 | ||||
1164 | ||||
1165 | static bool classof(const Attr *A) { return A->getKind() == attr::Artificial; } | |||
1166 | }; | |||
1167 | ||||
1168 | class AsmLabelAttr : public InheritableAttr { | |||
1169 | unsigned labelLength; | |||
1170 | char *label; | |||
1171 | ||||
1172 | public: | |||
1173 | static AsmLabelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Label, SourceRange Loc = SourceRange()) { | |||
1174 | auto *A = new (Ctx) AsmLabelAttr(Loc, Ctx, Label, 0); | |||
1175 | A->setImplicit(true); | |||
1176 | return A; | |||
1177 | } | |||
1178 | ||||
1179 | AsmLabelAttr(SourceRange R, ASTContext &Ctx | |||
1180 | , llvm::StringRef Label | |||
1181 | , unsigned SI | |||
1182 | ) | |||
1183 | : InheritableAttr(attr::AsmLabel, R, SI, false, false) | |||
1184 | , labelLength(Label.size()),label(new (Ctx, 1) char[labelLength]) | |||
1185 | { | |||
1186 | if (!Label.empty()) | |||
1187 | std::memcpy(label, Label.data(), labelLength); | |||
1188 | } | |||
1189 | ||||
1190 | AsmLabelAttr *clone(ASTContext &C) const; | |||
1191 | void printPretty(raw_ostream &OS, | |||
1192 | const PrintingPolicy &Policy) const; | |||
1193 | const char *getSpelling() const; | |||
1194 | llvm::StringRef getLabel() const { | |||
1195 | return llvm::StringRef(label, labelLength); | |||
1196 | } | |||
1197 | unsigned getLabelLength() const { | |||
1198 | return labelLength; | |||
1199 | } | |||
1200 | void setLabel(ASTContext &C, llvm::StringRef S) { | |||
1201 | labelLength = S.size(); | |||
1202 | this->label = new (C, 1) char [labelLength]; | |||
1203 | if (!S.empty()) | |||
1204 | std::memcpy(this->label, S.data(), labelLength); | |||
1205 | } | |||
1206 | ||||
1207 | ||||
1208 | ||||
1209 | static bool classof(const Attr *A) { return A->getKind() == attr::AsmLabel; } | |||
1210 | }; | |||
1211 | ||||
1212 | class AssertCapabilityAttr : public InheritableAttr { | |||
1213 | unsigned args_Size; | |||
1214 | Expr * *args_; | |||
1215 | ||||
1216 | public: | |||
1217 | enum Spelling { | |||
1218 | GNU_assert_capability = 0, | |||
1219 | CXX11_clang_assert_capability = 1, | |||
1220 | GNU_assert_shared_capability = 2, | |||
1221 | CXX11_clang_assert_shared_capability = 3 | |||
1222 | }; | |||
1223 | ||||
1224 | static AssertCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
1225 | auto *A = new (Ctx) AssertCapabilityAttr(Loc, Ctx, Args, ArgsSize, S); | |||
1226 | A->setImplicit(true); | |||
1227 | return A; | |||
1228 | } | |||
1229 | ||||
1230 | AssertCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
1231 | , Expr * *Args, unsigned ArgsSize | |||
1232 | , unsigned SI | |||
1233 | ) | |||
1234 | : InheritableAttr(attr::AssertCapability, R, SI, true, true) | |||
1235 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
1236 | { | |||
1237 | std::copy(Args, Args + args_Size, args_); | |||
1238 | } | |||
1239 | ||||
1240 | AssertCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
1241 | , unsigned SI | |||
1242 | ) | |||
1243 | : InheritableAttr(attr::AssertCapability, R, SI, true, true) | |||
1244 | , args_Size(0), args_(nullptr) | |||
1245 | { | |||
1246 | } | |||
1247 | ||||
1248 | AssertCapabilityAttr *clone(ASTContext &C) const; | |||
1249 | void printPretty(raw_ostream &OS, | |||
1250 | const PrintingPolicy &Policy) const; | |||
1251 | const char *getSpelling() const; | |||
1252 | Spelling getSemanticSpelling() const { | |||
1253 | switch (SpellingListIndex) { | |||
1254 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 1254); | |||
1255 | case 0: return GNU_assert_capability; | |||
1256 | case 1: return CXX11_clang_assert_capability; | |||
1257 | case 2: return GNU_assert_shared_capability; | |||
1258 | case 3: return CXX11_clang_assert_shared_capability; | |||
1259 | } | |||
1260 | } | |||
1261 | bool isShared() const { return SpellingListIndex == 2 || | |||
1262 | SpellingListIndex == 3; } | |||
1263 | typedef Expr ** args_iterator; | |||
1264 | args_iterator args_begin() const { return args_; } | |||
1265 | args_iterator args_end() const { return args_ + args_Size; } | |||
1266 | unsigned args_size() const { return args_Size; } | |||
1267 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
1268 | ||||
1269 | ||||
1270 | ||||
1271 | ||||
1272 | static bool classof(const Attr *A) { return A->getKind() == attr::AssertCapability; } | |||
1273 | }; | |||
1274 | ||||
1275 | class AssertExclusiveLockAttr : public InheritableAttr { | |||
1276 | unsigned args_Size; | |||
1277 | Expr * *args_; | |||
1278 | ||||
1279 | public: | |||
1280 | static AssertExclusiveLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
1281 | auto *A = new (Ctx) AssertExclusiveLockAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
1282 | A->setImplicit(true); | |||
1283 | return A; | |||
1284 | } | |||
1285 | ||||
1286 | AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx | |||
1287 | , Expr * *Args, unsigned ArgsSize | |||
1288 | , unsigned SI | |||
1289 | ) | |||
1290 | : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true) | |||
1291 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
1292 | { | |||
1293 | std::copy(Args, Args + args_Size, args_); | |||
1294 | } | |||
1295 | ||||
1296 | AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx | |||
1297 | , unsigned SI | |||
1298 | ) | |||
1299 | : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true) | |||
1300 | , args_Size(0), args_(nullptr) | |||
1301 | { | |||
1302 | } | |||
1303 | ||||
1304 | AssertExclusiveLockAttr *clone(ASTContext &C) const; | |||
1305 | void printPretty(raw_ostream &OS, | |||
1306 | const PrintingPolicy &Policy) const; | |||
1307 | const char *getSpelling() const; | |||
1308 | typedef Expr ** args_iterator; | |||
1309 | args_iterator args_begin() const { return args_; } | |||
1310 | args_iterator args_end() const { return args_ + args_Size; } | |||
1311 | unsigned args_size() const { return args_Size; } | |||
1312 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
1313 | ||||
1314 | ||||
1315 | ||||
1316 | ||||
1317 | static bool classof(const Attr *A) { return A->getKind() == attr::AssertExclusiveLock; } | |||
1318 | }; | |||
1319 | ||||
1320 | class AssertSharedLockAttr : public InheritableAttr { | |||
1321 | unsigned args_Size; | |||
1322 | Expr * *args_; | |||
1323 | ||||
1324 | public: | |||
1325 | static AssertSharedLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
1326 | auto *A = new (Ctx) AssertSharedLockAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
1327 | A->setImplicit(true); | |||
1328 | return A; | |||
1329 | } | |||
1330 | ||||
1331 | AssertSharedLockAttr(SourceRange R, ASTContext &Ctx | |||
1332 | , Expr * *Args, unsigned ArgsSize | |||
1333 | , unsigned SI | |||
1334 | ) | |||
1335 | : InheritableAttr(attr::AssertSharedLock, R, SI, true, true) | |||
1336 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
1337 | { | |||
1338 | std::copy(Args, Args + args_Size, args_); | |||
1339 | } | |||
1340 | ||||
1341 | AssertSharedLockAttr(SourceRange R, ASTContext &Ctx | |||
1342 | , unsigned SI | |||
1343 | ) | |||
1344 | : InheritableAttr(attr::AssertSharedLock, R, SI, true, true) | |||
1345 | , args_Size(0), args_(nullptr) | |||
1346 | { | |||
1347 | } | |||
1348 | ||||
1349 | AssertSharedLockAttr *clone(ASTContext &C) const; | |||
1350 | void printPretty(raw_ostream &OS, | |||
1351 | const PrintingPolicy &Policy) const; | |||
1352 | const char *getSpelling() const; | |||
1353 | typedef Expr ** args_iterator; | |||
1354 | args_iterator args_begin() const { return args_; } | |||
1355 | args_iterator args_end() const { return args_ + args_Size; } | |||
1356 | unsigned args_size() const { return args_Size; } | |||
1357 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
1358 | ||||
1359 | ||||
1360 | ||||
1361 | ||||
1362 | static bool classof(const Attr *A) { return A->getKind() == attr::AssertSharedLock; } | |||
1363 | }; | |||
1364 | ||||
1365 | class AssumeAlignedAttr : public InheritableAttr { | |||
1366 | Expr * alignment; | |||
1367 | ||||
1368 | Expr * offset; | |||
1369 | ||||
1370 | public: | |||
1371 | static AssumeAlignedAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, Expr * Offset, SourceRange Loc = SourceRange()) { | |||
1372 | auto *A = new (Ctx) AssumeAlignedAttr(Loc, Ctx, Alignment, Offset, 0); | |||
1373 | A->setImplicit(true); | |||
1374 | return A; | |||
1375 | } | |||
1376 | ||||
1377 | AssumeAlignedAttr(SourceRange R, ASTContext &Ctx | |||
1378 | , Expr * Alignment | |||
1379 | , Expr * Offset | |||
1380 | , unsigned SI | |||
1381 | ) | |||
1382 | : InheritableAttr(attr::AssumeAligned, R, SI, false, false) | |||
1383 | , alignment(Alignment) | |||
1384 | , offset(Offset) | |||
1385 | { | |||
1386 | } | |||
1387 | ||||
1388 | AssumeAlignedAttr(SourceRange R, ASTContext &Ctx | |||
1389 | , Expr * Alignment | |||
1390 | , unsigned SI | |||
1391 | ) | |||
1392 | : InheritableAttr(attr::AssumeAligned, R, SI, false, false) | |||
1393 | , alignment(Alignment) | |||
1394 | , offset() | |||
1395 | { | |||
1396 | } | |||
1397 | ||||
1398 | AssumeAlignedAttr *clone(ASTContext &C) const; | |||
1399 | void printPretty(raw_ostream &OS, | |||
1400 | const PrintingPolicy &Policy) const; | |||
1401 | const char *getSpelling() const; | |||
1402 | Expr * getAlignment() const { | |||
1403 | return alignment; | |||
1404 | } | |||
1405 | ||||
1406 | Expr * getOffset() const { | |||
1407 | return offset; | |||
1408 | } | |||
1409 | ||||
1410 | ||||
1411 | ||||
1412 | static bool classof(const Attr *A) { return A->getKind() == attr::AssumeAligned; } | |||
1413 | }; | |||
1414 | ||||
1415 | class AvailabilityAttr : public InheritableAttr { | |||
1416 | IdentifierInfo * platform; | |||
1417 | ||||
1418 | VersionTuple introduced; | |||
1419 | ||||
1420 | ||||
1421 | VersionTuple deprecated; | |||
1422 | ||||
1423 | ||||
1424 | VersionTuple obsoleted; | |||
1425 | ||||
1426 | ||||
1427 | bool unavailable; | |||
1428 | ||||
1429 | unsigned messageLength; | |||
1430 | char *message; | |||
1431 | ||||
1432 | bool strict; | |||
1433 | ||||
1434 | unsigned replacementLength; | |||
1435 | char *replacement; | |||
1436 | ||||
1437 | int priority; | |||
1438 | ||||
1439 | public: | |||
1440 | static AvailabilityAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool Unavailable, llvm::StringRef Message, bool Strict, llvm::StringRef Replacement, int Priority, SourceRange Loc = SourceRange()) { | |||
1441 | auto *A = new (Ctx) AvailabilityAttr(Loc, Ctx, Platform, Introduced, Deprecated, Obsoleted, Unavailable, Message, Strict, Replacement, Priority, 0); | |||
1442 | A->setImplicit(true); | |||
1443 | return A; | |||
1444 | } | |||
1445 | ||||
1446 | AvailabilityAttr(SourceRange R, ASTContext &Ctx | |||
1447 | , IdentifierInfo * Platform | |||
1448 | , VersionTuple Introduced | |||
1449 | , VersionTuple Deprecated | |||
1450 | , VersionTuple Obsoleted | |||
1451 | , bool Unavailable | |||
1452 | , llvm::StringRef Message | |||
1453 | , bool Strict | |||
1454 | , llvm::StringRef Replacement | |||
1455 | , int Priority | |||
1456 | , unsigned SI | |||
1457 | ) | |||
1458 | : InheritableAttr(attr::Availability, R, SI, false, true) | |||
1459 | , platform(Platform) | |||
1460 | , introduced(Introduced) | |||
1461 | , deprecated(Deprecated) | |||
1462 | , obsoleted(Obsoleted) | |||
1463 | , unavailable(Unavailable) | |||
1464 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
1465 | , strict(Strict) | |||
1466 | , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength]) | |||
1467 | , priority(Priority) | |||
1468 | { | |||
1469 | if (!Message.empty()) | |||
1470 | std::memcpy(message, Message.data(), messageLength); | |||
1471 | if (!Replacement.empty()) | |||
1472 | std::memcpy(replacement, Replacement.data(), replacementLength); | |||
1473 | } | |||
1474 | ||||
1475 | AvailabilityAttr *clone(ASTContext &C) const; | |||
1476 | void printPretty(raw_ostream &OS, | |||
1477 | const PrintingPolicy &Policy) const; | |||
1478 | const char *getSpelling() const; | |||
1479 | IdentifierInfo * getPlatform() const { | |||
1480 | return platform; | |||
1481 | } | |||
1482 | ||||
1483 | VersionTuple getIntroduced() const { | |||
1484 | return introduced; | |||
1485 | } | |||
1486 | void setIntroduced(ASTContext &C, VersionTuple V) { | |||
1487 | introduced = V; | |||
1488 | } | |||
1489 | ||||
1490 | VersionTuple getDeprecated() const { | |||
1491 | return deprecated; | |||
1492 | } | |||
1493 | void setDeprecated(ASTContext &C, VersionTuple V) { | |||
1494 | deprecated = V; | |||
1495 | } | |||
1496 | ||||
1497 | VersionTuple getObsoleted() const { | |||
1498 | return obsoleted; | |||
1499 | } | |||
1500 | void setObsoleted(ASTContext &C, VersionTuple V) { | |||
1501 | obsoleted = V; | |||
1502 | } | |||
1503 | ||||
1504 | bool getUnavailable() const { | |||
1505 | return unavailable; | |||
1506 | } | |||
1507 | ||||
1508 | llvm::StringRef getMessage() const { | |||
1509 | return llvm::StringRef(message, messageLength); | |||
1510 | } | |||
1511 | unsigned getMessageLength() const { | |||
1512 | return messageLength; | |||
1513 | } | |||
1514 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
1515 | messageLength = S.size(); | |||
1516 | this->message = new (C, 1) char [messageLength]; | |||
1517 | if (!S.empty()) | |||
1518 | std::memcpy(this->message, S.data(), messageLength); | |||
1519 | } | |||
1520 | ||||
1521 | bool getStrict() const { | |||
1522 | return strict; | |||
1523 | } | |||
1524 | ||||
1525 | llvm::StringRef getReplacement() const { | |||
1526 | return llvm::StringRef(replacement, replacementLength); | |||
1527 | } | |||
1528 | unsigned getReplacementLength() const { | |||
1529 | return replacementLength; | |||
1530 | } | |||
1531 | void setReplacement(ASTContext &C, llvm::StringRef S) { | |||
1532 | replacementLength = S.size(); | |||
1533 | this->replacement = new (C, 1) char [replacementLength]; | |||
1534 | if (!S.empty()) | |||
1535 | std::memcpy(this->replacement, S.data(), replacementLength); | |||
1536 | } | |||
1537 | ||||
1538 | int getPriority() const { | |||
1539 | return priority; | |||
1540 | } | |||
1541 | ||||
1542 | static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) { | |||
1543 | return llvm::StringSwitch<llvm::StringRef>(Platform) | |||
1544 | .Case("android", "Android") | |||
1545 | .Case("ios", "iOS") | |||
1546 | .Case("macos", "macOS") | |||
1547 | .Case("tvos", "tvOS") | |||
1548 | .Case("watchos", "watchOS") | |||
1549 | .Case("ios_app_extension", "iOS (App Extension)") | |||
1550 | .Case("macos_app_extension", "macOS (App Extension)") | |||
1551 | .Case("tvos_app_extension", "tvOS (App Extension)") | |||
1552 | .Case("watchos_app_extension", "watchOS (App Extension)") | |||
1553 | .Case("swift", "Swift") | |||
1554 | .Default(llvm::StringRef()); | |||
1555 | } | |||
1556 | static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) { | |||
1557 | return llvm::StringSwitch<llvm::StringRef>(Platform) | |||
1558 | .Case("ios", "iOS") | |||
1559 | .Case("macos", "macOS") | |||
1560 | .Case("tvos", "tvOS") | |||
1561 | .Case("watchos", "watchOS") | |||
1562 | .Case("ios_app_extension", "iOSApplicationExtension") | |||
1563 | .Case("macos_app_extension", "macOSApplicationExtension") | |||
1564 | .Case("tvos_app_extension", "tvOSApplicationExtension") | |||
1565 | .Case("watchos_app_extension", "watchOSApplicationExtension") | |||
1566 | .Default(Platform); | |||
1567 | } | |||
1568 | static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) { | |||
1569 | return llvm::StringSwitch<llvm::StringRef>(Platform) | |||
1570 | .Case("iOS", "ios") | |||
1571 | .Case("macOS", "macos") | |||
1572 | .Case("tvOS", "tvos") | |||
1573 | .Case("watchOS", "watchos") | |||
1574 | .Case("iOSApplicationExtension", "ios_app_extension") | |||
1575 | .Case("macOSApplicationExtension", "macos_app_extension") | |||
1576 | .Case("tvOSApplicationExtension", "tvos_app_extension") | |||
1577 | .Case("watchOSApplicationExtension", "watchos_app_extension") | |||
1578 | .Default(Platform); | |||
1579 | } | |||
1580 | ||||
1581 | static bool classof(const Attr *A) { return A->getKind() == attr::Availability; } | |||
1582 | }; | |||
1583 | ||||
1584 | class BlocksAttr : public InheritableAttr { | |||
1585 | public: | |||
1586 | enum BlockType { | |||
1587 | ByRef | |||
1588 | }; | |||
1589 | private: | |||
1590 | BlockType type; | |||
1591 | ||||
1592 | public: | |||
1593 | static BlocksAttr *CreateImplicit(ASTContext &Ctx, BlockType Type, SourceRange Loc = SourceRange()) { | |||
1594 | auto *A = new (Ctx) BlocksAttr(Loc, Ctx, Type, 0); | |||
1595 | A->setImplicit(true); | |||
1596 | return A; | |||
1597 | } | |||
1598 | ||||
1599 | BlocksAttr(SourceRange R, ASTContext &Ctx | |||
1600 | , BlockType Type | |||
1601 | , unsigned SI | |||
1602 | ) | |||
1603 | : InheritableAttr(attr::Blocks, R, SI, false, false) | |||
1604 | , type(Type) | |||
1605 | { | |||
1606 | } | |||
1607 | ||||
1608 | BlocksAttr *clone(ASTContext &C) const; | |||
1609 | void printPretty(raw_ostream &OS, | |||
1610 | const PrintingPolicy &Policy) const; | |||
1611 | const char *getSpelling() const; | |||
1612 | BlockType getType() const { | |||
1613 | return type; | |||
1614 | } | |||
1615 | ||||
1616 | static bool ConvertStrToBlockType(StringRef Val, BlockType &Out) { | |||
1617 | Optional<BlockType> R = llvm::StringSwitch<Optional<BlockType>>(Val) | |||
1618 | .Case("byref", BlocksAttr::ByRef) | |||
1619 | .Default(Optional<BlockType>()); | |||
1620 | if (R) { | |||
1621 | Out = *R; | |||
1622 | return true; | |||
1623 | } | |||
1624 | return false; | |||
1625 | } | |||
1626 | ||||
1627 | static const char *ConvertBlockTypeToStr(BlockType Val) { | |||
1628 | switch(Val) { | |||
1629 | case BlocksAttr::ByRef: return "byref"; | |||
1630 | } | |||
1631 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 1631); | |||
1632 | } | |||
1633 | ||||
1634 | ||||
1635 | static bool classof(const Attr *A) { return A->getKind() == attr::Blocks; } | |||
1636 | }; | |||
1637 | ||||
1638 | class C11NoReturnAttr : public InheritableAttr { | |||
1639 | public: | |||
1640 | static C11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1641 | auto *A = new (Ctx) C11NoReturnAttr(Loc, Ctx, 0); | |||
1642 | A->setImplicit(true); | |||
1643 | return A; | |||
1644 | } | |||
1645 | ||||
1646 | C11NoReturnAttr(SourceRange R, ASTContext &Ctx | |||
1647 | , unsigned SI | |||
1648 | ) | |||
1649 | : InheritableAttr(attr::C11NoReturn, R, SI, false, false) | |||
1650 | { | |||
1651 | } | |||
1652 | ||||
1653 | C11NoReturnAttr *clone(ASTContext &C) const; | |||
1654 | void printPretty(raw_ostream &OS, | |||
1655 | const PrintingPolicy &Policy) const; | |||
1656 | const char *getSpelling() const; | |||
1657 | ||||
1658 | ||||
1659 | static bool classof(const Attr *A) { return A->getKind() == attr::C11NoReturn; } | |||
1660 | }; | |||
1661 | ||||
1662 | class CDeclAttr : public InheritableAttr { | |||
1663 | public: | |||
1664 | static CDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1665 | auto *A = new (Ctx) CDeclAttr(Loc, Ctx, 0); | |||
1666 | A->setImplicit(true); | |||
1667 | return A; | |||
1668 | } | |||
1669 | ||||
1670 | CDeclAttr(SourceRange R, ASTContext &Ctx | |||
1671 | , unsigned SI | |||
1672 | ) | |||
1673 | : InheritableAttr(attr::CDecl, R, SI, false, false) | |||
1674 | { | |||
1675 | } | |||
1676 | ||||
1677 | CDeclAttr *clone(ASTContext &C) const; | |||
1678 | void printPretty(raw_ostream &OS, | |||
1679 | const PrintingPolicy &Policy) const; | |||
1680 | const char *getSpelling() const; | |||
1681 | ||||
1682 | ||||
1683 | static bool classof(const Attr *A) { return A->getKind() == attr::CDecl; } | |||
1684 | }; | |||
1685 | ||||
1686 | class CFAuditedTransferAttr : public InheritableAttr { | |||
1687 | public: | |||
1688 | static CFAuditedTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1689 | auto *A = new (Ctx) CFAuditedTransferAttr(Loc, Ctx, 0); | |||
1690 | A->setImplicit(true); | |||
1691 | return A; | |||
1692 | } | |||
1693 | ||||
1694 | CFAuditedTransferAttr(SourceRange R, ASTContext &Ctx | |||
1695 | , unsigned SI | |||
1696 | ) | |||
1697 | : InheritableAttr(attr::CFAuditedTransfer, R, SI, false, false) | |||
1698 | { | |||
1699 | } | |||
1700 | ||||
1701 | CFAuditedTransferAttr *clone(ASTContext &C) const; | |||
1702 | void printPretty(raw_ostream &OS, | |||
1703 | const PrintingPolicy &Policy) const; | |||
1704 | const char *getSpelling() const; | |||
1705 | ||||
1706 | ||||
1707 | static bool classof(const Attr *A) { return A->getKind() == attr::CFAuditedTransfer; } | |||
1708 | }; | |||
1709 | ||||
1710 | class CFConsumedAttr : public InheritableParamAttr { | |||
1711 | public: | |||
1712 | static CFConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1713 | auto *A = new (Ctx) CFConsumedAttr(Loc, Ctx, 0); | |||
1714 | A->setImplicit(true); | |||
1715 | return A; | |||
1716 | } | |||
1717 | ||||
1718 | CFConsumedAttr(SourceRange R, ASTContext &Ctx | |||
1719 | , unsigned SI | |||
1720 | ) | |||
1721 | : InheritableParamAttr(attr::CFConsumed, R, SI, false, false) | |||
1722 | { | |||
1723 | } | |||
1724 | ||||
1725 | CFConsumedAttr *clone(ASTContext &C) const; | |||
1726 | void printPretty(raw_ostream &OS, | |||
1727 | const PrintingPolicy &Policy) const; | |||
1728 | const char *getSpelling() const; | |||
1729 | ||||
1730 | ||||
1731 | static bool classof(const Attr *A) { return A->getKind() == attr::CFConsumed; } | |||
1732 | }; | |||
1733 | ||||
1734 | class CFReturnsNotRetainedAttr : public InheritableAttr { | |||
1735 | public: | |||
1736 | static CFReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1737 | auto *A = new (Ctx) CFReturnsNotRetainedAttr(Loc, Ctx, 0); | |||
1738 | A->setImplicit(true); | |||
1739 | return A; | |||
1740 | } | |||
1741 | ||||
1742 | CFReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx | |||
1743 | , unsigned SI | |||
1744 | ) | |||
1745 | : InheritableAttr(attr::CFReturnsNotRetained, R, SI, false, false) | |||
1746 | { | |||
1747 | } | |||
1748 | ||||
1749 | CFReturnsNotRetainedAttr *clone(ASTContext &C) const; | |||
1750 | void printPretty(raw_ostream &OS, | |||
1751 | const PrintingPolicy &Policy) const; | |||
1752 | const char *getSpelling() const; | |||
1753 | ||||
1754 | ||||
1755 | static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsNotRetained; } | |||
1756 | }; | |||
1757 | ||||
1758 | class CFReturnsRetainedAttr : public InheritableAttr { | |||
1759 | public: | |||
1760 | static CFReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1761 | auto *A = new (Ctx) CFReturnsRetainedAttr(Loc, Ctx, 0); | |||
1762 | A->setImplicit(true); | |||
1763 | return A; | |||
1764 | } | |||
1765 | ||||
1766 | CFReturnsRetainedAttr(SourceRange R, ASTContext &Ctx | |||
1767 | , unsigned SI | |||
1768 | ) | |||
1769 | : InheritableAttr(attr::CFReturnsRetained, R, SI, false, false) | |||
1770 | { | |||
1771 | } | |||
1772 | ||||
1773 | CFReturnsRetainedAttr *clone(ASTContext &C) const; | |||
1774 | void printPretty(raw_ostream &OS, | |||
1775 | const PrintingPolicy &Policy) const; | |||
1776 | const char *getSpelling() const; | |||
1777 | ||||
1778 | ||||
1779 | static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsRetained; } | |||
1780 | }; | |||
1781 | ||||
1782 | class CFUnknownTransferAttr : public InheritableAttr { | |||
1783 | public: | |||
1784 | static CFUnknownTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1785 | auto *A = new (Ctx) CFUnknownTransferAttr(Loc, Ctx, 0); | |||
1786 | A->setImplicit(true); | |||
1787 | return A; | |||
1788 | } | |||
1789 | ||||
1790 | CFUnknownTransferAttr(SourceRange R, ASTContext &Ctx | |||
1791 | , unsigned SI | |||
1792 | ) | |||
1793 | : InheritableAttr(attr::CFUnknownTransfer, R, SI, false, false) | |||
1794 | { | |||
1795 | } | |||
1796 | ||||
1797 | CFUnknownTransferAttr *clone(ASTContext &C) const; | |||
1798 | void printPretty(raw_ostream &OS, | |||
1799 | const PrintingPolicy &Policy) const; | |||
1800 | const char *getSpelling() const; | |||
1801 | ||||
1802 | ||||
1803 | static bool classof(const Attr *A) { return A->getKind() == attr::CFUnknownTransfer; } | |||
1804 | }; | |||
1805 | ||||
1806 | class CPUDispatchAttr : public InheritableAttr { | |||
1807 | unsigned cpus_Size; | |||
1808 | IdentifierInfo * *cpus_; | |||
1809 | ||||
1810 | public: | |||
1811 | static CPUDispatchAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * *Cpus, unsigned CpusSize, SourceRange Loc = SourceRange()) { | |||
1812 | auto *A = new (Ctx) CPUDispatchAttr(Loc, Ctx, Cpus, CpusSize, 0); | |||
1813 | A->setImplicit(true); | |||
1814 | return A; | |||
1815 | } | |||
1816 | ||||
1817 | CPUDispatchAttr(SourceRange R, ASTContext &Ctx | |||
1818 | , IdentifierInfo * *Cpus, unsigned CpusSize | |||
1819 | , unsigned SI | |||
1820 | ) | |||
1821 | : InheritableAttr(attr::CPUDispatch, R, SI, false, false) | |||
1822 | , cpus_Size(CpusSize), cpus_(new (Ctx, 16) IdentifierInfo *[cpus_Size]) | |||
1823 | { | |||
1824 | std::copy(Cpus, Cpus + cpus_Size, cpus_); | |||
1825 | } | |||
1826 | ||||
1827 | CPUDispatchAttr(SourceRange R, ASTContext &Ctx | |||
1828 | , unsigned SI | |||
1829 | ) | |||
1830 | : InheritableAttr(attr::CPUDispatch, R, SI, false, false) | |||
1831 | , cpus_Size(0), cpus_(nullptr) | |||
1832 | { | |||
1833 | } | |||
1834 | ||||
1835 | CPUDispatchAttr *clone(ASTContext &C) const; | |||
1836 | void printPretty(raw_ostream &OS, | |||
1837 | const PrintingPolicy &Policy) const; | |||
1838 | const char *getSpelling() const; | |||
1839 | typedef IdentifierInfo ** cpus_iterator; | |||
1840 | cpus_iterator cpus_begin() const { return cpus_; } | |||
1841 | cpus_iterator cpus_end() const { return cpus_ + cpus_Size; } | |||
1842 | unsigned cpus_size() const { return cpus_Size; } | |||
1843 | llvm::iterator_range<cpus_iterator> cpus() const { return llvm::make_range(cpus_begin(), cpus_end()); } | |||
1844 | ||||
1845 | ||||
1846 | ||||
1847 | ||||
1848 | static bool classof(const Attr *A) { return A->getKind() == attr::CPUDispatch; } | |||
1849 | }; | |||
1850 | ||||
1851 | class CPUSpecificAttr : public InheritableAttr { | |||
1852 | unsigned cpus_Size; | |||
1853 | IdentifierInfo * *cpus_; | |||
1854 | ||||
1855 | public: | |||
1856 | static CPUSpecificAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * *Cpus, unsigned CpusSize, SourceRange Loc = SourceRange()) { | |||
1857 | auto *A = new (Ctx) CPUSpecificAttr(Loc, Ctx, Cpus, CpusSize, 0); | |||
1858 | A->setImplicit(true); | |||
1859 | return A; | |||
1860 | } | |||
1861 | ||||
1862 | CPUSpecificAttr(SourceRange R, ASTContext &Ctx | |||
1863 | , IdentifierInfo * *Cpus, unsigned CpusSize | |||
1864 | , unsigned SI | |||
1865 | ) | |||
1866 | : InheritableAttr(attr::CPUSpecific, R, SI, false, false) | |||
1867 | , cpus_Size(CpusSize), cpus_(new (Ctx, 16) IdentifierInfo *[cpus_Size]) | |||
1868 | { | |||
1869 | std::copy(Cpus, Cpus + cpus_Size, cpus_); | |||
1870 | } | |||
1871 | ||||
1872 | CPUSpecificAttr(SourceRange R, ASTContext &Ctx | |||
1873 | , unsigned SI | |||
1874 | ) | |||
1875 | : InheritableAttr(attr::CPUSpecific, R, SI, false, false) | |||
1876 | , cpus_Size(0), cpus_(nullptr) | |||
1877 | { | |||
1878 | } | |||
1879 | ||||
1880 | CPUSpecificAttr *clone(ASTContext &C) const; | |||
1881 | void printPretty(raw_ostream &OS, | |||
1882 | const PrintingPolicy &Policy) const; | |||
1883 | const char *getSpelling() const; | |||
1884 | typedef IdentifierInfo ** cpus_iterator; | |||
1885 | cpus_iterator cpus_begin() const { return cpus_; } | |||
1886 | cpus_iterator cpus_end() const { return cpus_ + cpus_Size; } | |||
1887 | unsigned cpus_size() const { return cpus_Size; } | |||
1888 | llvm::iterator_range<cpus_iterator> cpus() const { return llvm::make_range(cpus_begin(), cpus_end()); } | |||
1889 | ||||
1890 | ||||
1891 | ||||
1892 | IdentifierInfo *getCPUName(unsigned Index) const { | |||
1893 | return *(cpus_begin() + Index); | |||
1894 | } | |||
1895 | ||||
1896 | ||||
1897 | static bool classof(const Attr *A) { return A->getKind() == attr::CPUSpecific; } | |||
1898 | }; | |||
1899 | ||||
1900 | class CUDAConstantAttr : public InheritableAttr { | |||
1901 | public: | |||
1902 | static CUDAConstantAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1903 | auto *A = new (Ctx) CUDAConstantAttr(Loc, Ctx, 0); | |||
1904 | A->setImplicit(true); | |||
1905 | return A; | |||
1906 | } | |||
1907 | ||||
1908 | CUDAConstantAttr(SourceRange R, ASTContext &Ctx | |||
1909 | , unsigned SI | |||
1910 | ) | |||
1911 | : InheritableAttr(attr::CUDAConstant, R, SI, false, false) | |||
1912 | { | |||
1913 | } | |||
1914 | ||||
1915 | CUDAConstantAttr *clone(ASTContext &C) const; | |||
1916 | void printPretty(raw_ostream &OS, | |||
1917 | const PrintingPolicy &Policy) const; | |||
1918 | const char *getSpelling() const; | |||
1919 | ||||
1920 | ||||
1921 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAConstant; } | |||
1922 | }; | |||
1923 | ||||
1924 | class CUDADeviceAttr : public InheritableAttr { | |||
1925 | public: | |||
1926 | static CUDADeviceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1927 | auto *A = new (Ctx) CUDADeviceAttr(Loc, Ctx, 0); | |||
1928 | A->setImplicit(true); | |||
1929 | return A; | |||
1930 | } | |||
1931 | ||||
1932 | CUDADeviceAttr(SourceRange R, ASTContext &Ctx | |||
1933 | , unsigned SI | |||
1934 | ) | |||
1935 | : InheritableAttr(attr::CUDADevice, R, SI, false, false) | |||
1936 | { | |||
1937 | } | |||
1938 | ||||
1939 | CUDADeviceAttr *clone(ASTContext &C) const; | |||
1940 | void printPretty(raw_ostream &OS, | |||
1941 | const PrintingPolicy &Policy) const; | |||
1942 | const char *getSpelling() const; | |||
1943 | ||||
1944 | ||||
1945 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDADevice; } | |||
1946 | }; | |||
1947 | ||||
1948 | class CUDAGlobalAttr : public InheritableAttr { | |||
1949 | public: | |||
1950 | static CUDAGlobalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1951 | auto *A = new (Ctx) CUDAGlobalAttr(Loc, Ctx, 0); | |||
1952 | A->setImplicit(true); | |||
1953 | return A; | |||
1954 | } | |||
1955 | ||||
1956 | CUDAGlobalAttr(SourceRange R, ASTContext &Ctx | |||
1957 | , unsigned SI | |||
1958 | ) | |||
1959 | : InheritableAttr(attr::CUDAGlobal, R, SI, false, false) | |||
1960 | { | |||
1961 | } | |||
1962 | ||||
1963 | CUDAGlobalAttr *clone(ASTContext &C) const; | |||
1964 | void printPretty(raw_ostream &OS, | |||
1965 | const PrintingPolicy &Policy) const; | |||
1966 | const char *getSpelling() const; | |||
1967 | ||||
1968 | ||||
1969 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAGlobal; } | |||
1970 | }; | |||
1971 | ||||
1972 | class CUDAHostAttr : public InheritableAttr { | |||
1973 | public: | |||
1974 | static CUDAHostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1975 | auto *A = new (Ctx) CUDAHostAttr(Loc, Ctx, 0); | |||
1976 | A->setImplicit(true); | |||
1977 | return A; | |||
1978 | } | |||
1979 | ||||
1980 | CUDAHostAttr(SourceRange R, ASTContext &Ctx | |||
1981 | , unsigned SI | |||
1982 | ) | |||
1983 | : InheritableAttr(attr::CUDAHost, R, SI, false, false) | |||
1984 | { | |||
1985 | } | |||
1986 | ||||
1987 | CUDAHostAttr *clone(ASTContext &C) const; | |||
1988 | void printPretty(raw_ostream &OS, | |||
1989 | const PrintingPolicy &Policy) const; | |||
1990 | const char *getSpelling() const; | |||
1991 | ||||
1992 | ||||
1993 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAHost; } | |||
1994 | }; | |||
1995 | ||||
1996 | class CUDAInvalidTargetAttr : public InheritableAttr { | |||
1997 | public: | |||
1998 | static CUDAInvalidTargetAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
1999 | auto *A = new (Ctx) CUDAInvalidTargetAttr(Loc, Ctx, 0); | |||
2000 | A->setImplicit(true); | |||
2001 | return A; | |||
2002 | } | |||
2003 | ||||
2004 | CUDAInvalidTargetAttr(SourceRange R, ASTContext &Ctx | |||
2005 | , unsigned SI | |||
2006 | ) | |||
2007 | : InheritableAttr(attr::CUDAInvalidTarget, R, SI, false, false) | |||
2008 | { | |||
2009 | } | |||
2010 | ||||
2011 | CUDAInvalidTargetAttr *clone(ASTContext &C) const; | |||
2012 | void printPretty(raw_ostream &OS, | |||
2013 | const PrintingPolicy &Policy) const; | |||
2014 | const char *getSpelling() const; | |||
2015 | ||||
2016 | ||||
2017 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAInvalidTarget; } | |||
2018 | }; | |||
2019 | ||||
2020 | class CUDALaunchBoundsAttr : public InheritableAttr { | |||
2021 | Expr * maxThreads; | |||
2022 | ||||
2023 | Expr * minBlocks; | |||
2024 | ||||
2025 | public: | |||
2026 | static CUDALaunchBoundsAttr *CreateImplicit(ASTContext &Ctx, Expr * MaxThreads, Expr * MinBlocks, SourceRange Loc = SourceRange()) { | |||
2027 | auto *A = new (Ctx) CUDALaunchBoundsAttr(Loc, Ctx, MaxThreads, MinBlocks, 0); | |||
2028 | A->setImplicit(true); | |||
2029 | return A; | |||
2030 | } | |||
2031 | ||||
2032 | CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx | |||
2033 | , Expr * MaxThreads | |||
2034 | , Expr * MinBlocks | |||
2035 | , unsigned SI | |||
2036 | ) | |||
2037 | : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false) | |||
2038 | , maxThreads(MaxThreads) | |||
2039 | , minBlocks(MinBlocks) | |||
2040 | { | |||
2041 | } | |||
2042 | ||||
2043 | CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx | |||
2044 | , Expr * MaxThreads | |||
2045 | , unsigned SI | |||
2046 | ) | |||
2047 | : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false) | |||
2048 | , maxThreads(MaxThreads) | |||
2049 | , minBlocks() | |||
2050 | { | |||
2051 | } | |||
2052 | ||||
2053 | CUDALaunchBoundsAttr *clone(ASTContext &C) const; | |||
2054 | void printPretty(raw_ostream &OS, | |||
2055 | const PrintingPolicy &Policy) const; | |||
2056 | const char *getSpelling() const; | |||
2057 | Expr * getMaxThreads() const { | |||
2058 | return maxThreads; | |||
2059 | } | |||
2060 | ||||
2061 | Expr * getMinBlocks() const { | |||
2062 | return minBlocks; | |||
2063 | } | |||
2064 | ||||
2065 | ||||
2066 | ||||
2067 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDALaunchBounds; } | |||
2068 | }; | |||
2069 | ||||
2070 | class CUDASharedAttr : public InheritableAttr { | |||
2071 | public: | |||
2072 | static CUDASharedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2073 | auto *A = new (Ctx) CUDASharedAttr(Loc, Ctx, 0); | |||
2074 | A->setImplicit(true); | |||
2075 | return A; | |||
2076 | } | |||
2077 | ||||
2078 | CUDASharedAttr(SourceRange R, ASTContext &Ctx | |||
2079 | , unsigned SI | |||
2080 | ) | |||
2081 | : InheritableAttr(attr::CUDAShared, R, SI, false, false) | |||
2082 | { | |||
2083 | } | |||
2084 | ||||
2085 | CUDASharedAttr *clone(ASTContext &C) const; | |||
2086 | void printPretty(raw_ostream &OS, | |||
2087 | const PrintingPolicy &Policy) const; | |||
2088 | const char *getSpelling() const; | |||
2089 | ||||
2090 | ||||
2091 | static bool classof(const Attr *A) { return A->getKind() == attr::CUDAShared; } | |||
2092 | }; | |||
2093 | ||||
2094 | class CXX11NoReturnAttr : public InheritableAttr { | |||
2095 | public: | |||
2096 | static CXX11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2097 | auto *A = new (Ctx) CXX11NoReturnAttr(Loc, Ctx, 0); | |||
2098 | A->setImplicit(true); | |||
2099 | return A; | |||
2100 | } | |||
2101 | ||||
2102 | CXX11NoReturnAttr(SourceRange R, ASTContext &Ctx | |||
2103 | , unsigned SI | |||
2104 | ) | |||
2105 | : InheritableAttr(attr::CXX11NoReturn, R, SI, false, false) | |||
2106 | { | |||
2107 | } | |||
2108 | ||||
2109 | CXX11NoReturnAttr *clone(ASTContext &C) const; | |||
2110 | void printPretty(raw_ostream &OS, | |||
2111 | const PrintingPolicy &Policy) const; | |||
2112 | const char *getSpelling() const; | |||
2113 | ||||
2114 | ||||
2115 | static bool classof(const Attr *A) { return A->getKind() == attr::CXX11NoReturn; } | |||
2116 | }; | |||
2117 | ||||
2118 | class CallableWhenAttr : public InheritableAttr { | |||
2119 | public: | |||
2120 | enum ConsumedState { | |||
2121 | Unknown, | |||
2122 | Consumed, | |||
2123 | Unconsumed | |||
2124 | }; | |||
2125 | private: | |||
2126 | unsigned callableStates_Size; | |||
2127 | ConsumedState *callableStates_; | |||
2128 | ||||
2129 | public: | |||
2130 | static CallableWhenAttr *CreateImplicit(ASTContext &Ctx, ConsumedState *CallableStates, unsigned CallableStatesSize, SourceRange Loc = SourceRange()) { | |||
2131 | auto *A = new (Ctx) CallableWhenAttr(Loc, Ctx, CallableStates, CallableStatesSize, 0); | |||
2132 | A->setImplicit(true); | |||
2133 | return A; | |||
2134 | } | |||
2135 | ||||
2136 | CallableWhenAttr(SourceRange R, ASTContext &Ctx | |||
2137 | , ConsumedState *CallableStates, unsigned CallableStatesSize | |||
2138 | , unsigned SI | |||
2139 | ) | |||
2140 | : InheritableAttr(attr::CallableWhen, R, SI, false, false) | |||
2141 | , callableStates_Size(CallableStatesSize), callableStates_(new (Ctx, 16) ConsumedState[callableStates_Size]) | |||
2142 | { | |||
2143 | std::copy(CallableStates, CallableStates + callableStates_Size, callableStates_); | |||
2144 | } | |||
2145 | ||||
2146 | CallableWhenAttr(SourceRange R, ASTContext &Ctx | |||
2147 | , unsigned SI | |||
2148 | ) | |||
2149 | : InheritableAttr(attr::CallableWhen, R, SI, false, false) | |||
2150 | , callableStates_Size(0), callableStates_(nullptr) | |||
2151 | { | |||
2152 | } | |||
2153 | ||||
2154 | CallableWhenAttr *clone(ASTContext &C) const; | |||
2155 | void printPretty(raw_ostream &OS, | |||
2156 | const PrintingPolicy &Policy) const; | |||
2157 | const char *getSpelling() const; | |||
2158 | typedef ConsumedState* callableStates_iterator; | |||
2159 | callableStates_iterator callableStates_begin() const { return callableStates_; } | |||
2160 | callableStates_iterator callableStates_end() const { return callableStates_ + callableStates_Size; } | |||
2161 | unsigned callableStates_size() const { return callableStates_Size; } | |||
2162 | llvm::iterator_range<callableStates_iterator> callableStates() const { return llvm::make_range(callableStates_begin(), callableStates_end()); } | |||
2163 | ||||
2164 | ||||
2165 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
2166 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
2167 | .Case("unknown", CallableWhenAttr::Unknown) | |||
2168 | .Case("consumed", CallableWhenAttr::Consumed) | |||
2169 | .Case("unconsumed", CallableWhenAttr::Unconsumed) | |||
2170 | .Default(Optional<ConsumedState>()); | |||
2171 | if (R) { | |||
2172 | Out = *R; | |||
2173 | return true; | |||
2174 | } | |||
2175 | return false; | |||
2176 | } | |||
2177 | ||||
2178 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
2179 | switch(Val) { | |||
2180 | case CallableWhenAttr::Unknown: return "unknown"; | |||
2181 | case CallableWhenAttr::Consumed: return "consumed"; | |||
2182 | case CallableWhenAttr::Unconsumed: return "unconsumed"; | |||
2183 | } | |||
2184 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 2184); | |||
2185 | } | |||
2186 | ||||
2187 | ||||
2188 | static bool classof(const Attr *A) { return A->getKind() == attr::CallableWhen; } | |||
2189 | }; | |||
2190 | ||||
2191 | class CallbackAttr : public InheritableAttr { | |||
2192 | unsigned encoding_Size; | |||
2193 | int *encoding_; | |||
2194 | ||||
2195 | public: | |||
2196 | static CallbackAttr *CreateImplicit(ASTContext &Ctx, int *Encoding, unsigned EncodingSize, SourceRange Loc = SourceRange()) { | |||
2197 | auto *A = new (Ctx) CallbackAttr(Loc, Ctx, Encoding, EncodingSize, 0); | |||
2198 | A->setImplicit(true); | |||
2199 | return A; | |||
2200 | } | |||
2201 | ||||
2202 | CallbackAttr(SourceRange R, ASTContext &Ctx | |||
2203 | , int *Encoding, unsigned EncodingSize | |||
2204 | , unsigned SI | |||
2205 | ) | |||
2206 | : InheritableAttr(attr::Callback, R, SI, false, false) | |||
2207 | , encoding_Size(EncodingSize), encoding_(new (Ctx, 16) int[encoding_Size]) | |||
2208 | { | |||
2209 | std::copy(Encoding, Encoding + encoding_Size, encoding_); | |||
2210 | } | |||
2211 | ||||
2212 | CallbackAttr(SourceRange R, ASTContext &Ctx | |||
2213 | , unsigned SI | |||
2214 | ) | |||
2215 | : InheritableAttr(attr::Callback, R, SI, false, false) | |||
2216 | , encoding_Size(0), encoding_(nullptr) | |||
2217 | { | |||
2218 | } | |||
2219 | ||||
2220 | CallbackAttr *clone(ASTContext &C) const; | |||
2221 | void printPretty(raw_ostream &OS, | |||
2222 | const PrintingPolicy &Policy) const; | |||
2223 | const char *getSpelling() const; | |||
2224 | typedef int* encoding_iterator; | |||
2225 | encoding_iterator encoding_begin() const { return encoding_; } | |||
2226 | encoding_iterator encoding_end() const { return encoding_ + encoding_Size; } | |||
2227 | unsigned encoding_size() const { return encoding_Size; } | |||
2228 | llvm::iterator_range<encoding_iterator> encoding() const { return llvm::make_range(encoding_begin(), encoding_end()); } | |||
2229 | ||||
2230 | ||||
2231 | ||||
2232 | ||||
2233 | static bool classof(const Attr *A) { return A->getKind() == attr::Callback; } | |||
2234 | }; | |||
2235 | ||||
2236 | class CapabilityAttr : public InheritableAttr { | |||
2237 | unsigned nameLength; | |||
2238 | char *name; | |||
2239 | ||||
2240 | public: | |||
2241 | enum Spelling { | |||
2242 | GNU_capability = 0, | |||
2243 | CXX11_clang_capability = 1, | |||
2244 | GNU_shared_capability = 2, | |||
2245 | CXX11_clang_shared_capability = 3 | |||
2246 | }; | |||
2247 | ||||
2248 | static CapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
2249 | auto *A = new (Ctx) CapabilityAttr(Loc, Ctx, Name, S); | |||
2250 | A->setImplicit(true); | |||
2251 | return A; | |||
2252 | } | |||
2253 | ||||
2254 | CapabilityAttr(SourceRange R, ASTContext &Ctx | |||
2255 | , llvm::StringRef Name | |||
2256 | , unsigned SI | |||
2257 | ) | |||
2258 | : InheritableAttr(attr::Capability, R, SI, false, false) | |||
2259 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
2260 | { | |||
2261 | if (!Name.empty()) | |||
2262 | std::memcpy(name, Name.data(), nameLength); | |||
2263 | } | |||
2264 | ||||
2265 | CapabilityAttr *clone(ASTContext &C) const; | |||
2266 | void printPretty(raw_ostream &OS, | |||
2267 | const PrintingPolicy &Policy) const; | |||
2268 | const char *getSpelling() const; | |||
2269 | Spelling getSemanticSpelling() const { | |||
2270 | switch (SpellingListIndex) { | |||
2271 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 2271); | |||
2272 | case 0: return GNU_capability; | |||
2273 | case 1: return CXX11_clang_capability; | |||
2274 | case 2: return GNU_shared_capability; | |||
2275 | case 3: return CXX11_clang_shared_capability; | |||
2276 | } | |||
2277 | } | |||
2278 | bool isShared() const { return SpellingListIndex == 2 || | |||
2279 | SpellingListIndex == 3; } | |||
2280 | llvm::StringRef getName() const { | |||
2281 | return llvm::StringRef(name, nameLength); | |||
2282 | } | |||
2283 | unsigned getNameLength() const { | |||
2284 | return nameLength; | |||
2285 | } | |||
2286 | void setName(ASTContext &C, llvm::StringRef S) { | |||
2287 | nameLength = S.size(); | |||
2288 | this->name = new (C, 1) char [nameLength]; | |||
2289 | if (!S.empty()) | |||
2290 | std::memcpy(this->name, S.data(), nameLength); | |||
2291 | } | |||
2292 | ||||
2293 | ||||
2294 | bool isMutex() const { return getName().equals_lower("mutex"); } | |||
2295 | bool isRole() const { return getName().equals_lower("role"); } | |||
2296 | ||||
2297 | ||||
2298 | static bool classof(const Attr *A) { return A->getKind() == attr::Capability; } | |||
2299 | }; | |||
2300 | ||||
2301 | class CapturedRecordAttr : public InheritableAttr { | |||
2302 | public: | |||
2303 | static CapturedRecordAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2304 | auto *A = new (Ctx) CapturedRecordAttr(Loc, Ctx, 0); | |||
2305 | A->setImplicit(true); | |||
| ||||
2306 | return A; | |||
2307 | } | |||
2308 | ||||
2309 | CapturedRecordAttr(SourceRange R, ASTContext &Ctx | |||
2310 | , unsigned SI | |||
2311 | ) | |||
2312 | : InheritableAttr(attr::CapturedRecord, R, SI, false, false) | |||
2313 | { | |||
2314 | } | |||
2315 | ||||
2316 | CapturedRecordAttr *clone(ASTContext &C) const; | |||
2317 | void printPretty(raw_ostream &OS, | |||
2318 | const PrintingPolicy &Policy) const; | |||
2319 | const char *getSpelling() const; | |||
2320 | ||||
2321 | ||||
2322 | static bool classof(const Attr *A) { return A->getKind() == attr::CapturedRecord; } | |||
2323 | }; | |||
2324 | ||||
2325 | class CarriesDependencyAttr : public InheritableParamAttr { | |||
2326 | public: | |||
2327 | static CarriesDependencyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2328 | auto *A = new (Ctx) CarriesDependencyAttr(Loc, Ctx, 0); | |||
2329 | A->setImplicit(true); | |||
2330 | return A; | |||
2331 | } | |||
2332 | ||||
2333 | CarriesDependencyAttr(SourceRange R, ASTContext &Ctx | |||
2334 | , unsigned SI | |||
2335 | ) | |||
2336 | : InheritableParamAttr(attr::CarriesDependency, R, SI, false, false) | |||
2337 | { | |||
2338 | } | |||
2339 | ||||
2340 | CarriesDependencyAttr *clone(ASTContext &C) const; | |||
2341 | void printPretty(raw_ostream &OS, | |||
2342 | const PrintingPolicy &Policy) const; | |||
2343 | const char *getSpelling() const; | |||
2344 | ||||
2345 | ||||
2346 | static bool classof(const Attr *A) { return A->getKind() == attr::CarriesDependency; } | |||
2347 | }; | |||
2348 | ||||
2349 | class CleanupAttr : public InheritableAttr { | |||
2350 | FunctionDecl * functionDecl; | |||
2351 | ||||
2352 | public: | |||
2353 | static CleanupAttr *CreateImplicit(ASTContext &Ctx, FunctionDecl * FunctionDecl, SourceRange Loc = SourceRange()) { | |||
2354 | auto *A = new (Ctx) CleanupAttr(Loc, Ctx, FunctionDecl, 0); | |||
2355 | A->setImplicit(true); | |||
2356 | return A; | |||
2357 | } | |||
2358 | ||||
2359 | CleanupAttr(SourceRange R, ASTContext &Ctx | |||
2360 | , FunctionDecl * FunctionDecl | |||
2361 | , unsigned SI | |||
2362 | ) | |||
2363 | : InheritableAttr(attr::Cleanup, R, SI, false, false) | |||
2364 | , functionDecl(FunctionDecl) | |||
2365 | { | |||
2366 | } | |||
2367 | ||||
2368 | CleanupAttr *clone(ASTContext &C) const; | |||
2369 | void printPretty(raw_ostream &OS, | |||
2370 | const PrintingPolicy &Policy) const; | |||
2371 | const char *getSpelling() const; | |||
2372 | FunctionDecl * getFunctionDecl() const { | |||
2373 | return functionDecl; | |||
2374 | } | |||
2375 | ||||
2376 | ||||
2377 | ||||
2378 | static bool classof(const Attr *A) { return A->getKind() == attr::Cleanup; } | |||
2379 | }; | |||
2380 | ||||
2381 | class CodeSegAttr : public InheritableAttr { | |||
2382 | unsigned nameLength; | |||
2383 | char *name; | |||
2384 | ||||
2385 | public: | |||
2386 | static CodeSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
2387 | auto *A = new (Ctx) CodeSegAttr(Loc, Ctx, Name, 0); | |||
2388 | A->setImplicit(true); | |||
2389 | return A; | |||
2390 | } | |||
2391 | ||||
2392 | CodeSegAttr(SourceRange R, ASTContext &Ctx | |||
2393 | , llvm::StringRef Name | |||
2394 | , unsigned SI | |||
2395 | ) | |||
2396 | : InheritableAttr(attr::CodeSeg, R, SI, false, false) | |||
2397 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
2398 | { | |||
2399 | if (!Name.empty()) | |||
2400 | std::memcpy(name, Name.data(), nameLength); | |||
2401 | } | |||
2402 | ||||
2403 | CodeSegAttr *clone(ASTContext &C) const; | |||
2404 | void printPretty(raw_ostream &OS, | |||
2405 | const PrintingPolicy &Policy) const; | |||
2406 | const char *getSpelling() const; | |||
2407 | llvm::StringRef getName() const { | |||
2408 | return llvm::StringRef(name, nameLength); | |||
2409 | } | |||
2410 | unsigned getNameLength() const { | |||
2411 | return nameLength; | |||
2412 | } | |||
2413 | void setName(ASTContext &C, llvm::StringRef S) { | |||
2414 | nameLength = S.size(); | |||
2415 | this->name = new (C, 1) char [nameLength]; | |||
2416 | if (!S.empty()) | |||
2417 | std::memcpy(this->name, S.data(), nameLength); | |||
2418 | } | |||
2419 | ||||
2420 | ||||
2421 | ||||
2422 | static bool classof(const Attr *A) { return A->getKind() == attr::CodeSeg; } | |||
2423 | }; | |||
2424 | ||||
2425 | class ColdAttr : public InheritableAttr { | |||
2426 | public: | |||
2427 | static ColdAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2428 | auto *A = new (Ctx) ColdAttr(Loc, Ctx, 0); | |||
2429 | A->setImplicit(true); | |||
2430 | return A; | |||
2431 | } | |||
2432 | ||||
2433 | ColdAttr(SourceRange R, ASTContext &Ctx | |||
2434 | , unsigned SI | |||
2435 | ) | |||
2436 | : InheritableAttr(attr::Cold, R, SI, false, false) | |||
2437 | { | |||
2438 | } | |||
2439 | ||||
2440 | ColdAttr *clone(ASTContext &C) const; | |||
2441 | void printPretty(raw_ostream &OS, | |||
2442 | const PrintingPolicy &Policy) const; | |||
2443 | const char *getSpelling() const; | |||
2444 | ||||
2445 | ||||
2446 | static bool classof(const Attr *A) { return A->getKind() == attr::Cold; } | |||
2447 | }; | |||
2448 | ||||
2449 | class CommonAttr : public InheritableAttr { | |||
2450 | public: | |||
2451 | static CommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2452 | auto *A = new (Ctx) CommonAttr(Loc, Ctx, 0); | |||
2453 | A->setImplicit(true); | |||
2454 | return A; | |||
2455 | } | |||
2456 | ||||
2457 | CommonAttr(SourceRange R, ASTContext &Ctx | |||
2458 | , unsigned SI | |||
2459 | ) | |||
2460 | : InheritableAttr(attr::Common, R, SI, false, false) | |||
2461 | { | |||
2462 | } | |||
2463 | ||||
2464 | CommonAttr *clone(ASTContext &C) const; | |||
2465 | void printPretty(raw_ostream &OS, | |||
2466 | const PrintingPolicy &Policy) const; | |||
2467 | const char *getSpelling() const; | |||
2468 | ||||
2469 | ||||
2470 | static bool classof(const Attr *A) { return A->getKind() == attr::Common; } | |||
2471 | }; | |||
2472 | ||||
2473 | class ConstAttr : public InheritableAttr { | |||
2474 | public: | |||
2475 | static ConstAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2476 | auto *A = new (Ctx) ConstAttr(Loc, Ctx, 0); | |||
2477 | A->setImplicit(true); | |||
2478 | return A; | |||
2479 | } | |||
2480 | ||||
2481 | ConstAttr(SourceRange R, ASTContext &Ctx | |||
2482 | , unsigned SI | |||
2483 | ) | |||
2484 | : InheritableAttr(attr::Const, R, SI, false, false) | |||
2485 | { | |||
2486 | } | |||
2487 | ||||
2488 | ConstAttr *clone(ASTContext &C) const; | |||
2489 | void printPretty(raw_ostream &OS, | |||
2490 | const PrintingPolicy &Policy) const; | |||
2491 | const char *getSpelling() const; | |||
2492 | ||||
2493 | ||||
2494 | static bool classof(const Attr *A) { return A->getKind() == attr::Const; } | |||
2495 | }; | |||
2496 | ||||
2497 | class ConstructorAttr : public InheritableAttr { | |||
2498 | int priority; | |||
2499 | ||||
2500 | public: | |||
2501 | static ConstructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) { | |||
2502 | auto *A = new (Ctx) ConstructorAttr(Loc, Ctx, Priority, 0); | |||
2503 | A->setImplicit(true); | |||
2504 | return A; | |||
2505 | } | |||
2506 | ||||
2507 | ConstructorAttr(SourceRange R, ASTContext &Ctx | |||
2508 | , int Priority | |||
2509 | , unsigned SI | |||
2510 | ) | |||
2511 | : InheritableAttr(attr::Constructor, R, SI, false, false) | |||
2512 | , priority(Priority) | |||
2513 | { | |||
2514 | } | |||
2515 | ||||
2516 | ConstructorAttr(SourceRange R, ASTContext &Ctx | |||
2517 | , unsigned SI | |||
2518 | ) | |||
2519 | : InheritableAttr(attr::Constructor, R, SI, false, false) | |||
2520 | , priority() | |||
2521 | { | |||
2522 | } | |||
2523 | ||||
2524 | ConstructorAttr *clone(ASTContext &C) const; | |||
2525 | void printPretty(raw_ostream &OS, | |||
2526 | const PrintingPolicy &Policy) const; | |||
2527 | const char *getSpelling() const; | |||
2528 | int getPriority() const { | |||
2529 | return priority; | |||
2530 | } | |||
2531 | ||||
2532 | static const int DefaultPriority = 65535; | |||
2533 | ||||
2534 | ||||
2535 | ||||
2536 | static bool classof(const Attr *A) { return A->getKind() == attr::Constructor; } | |||
2537 | }; | |||
2538 | ||||
2539 | class ConsumableAttr : public InheritableAttr { | |||
2540 | public: | |||
2541 | enum ConsumedState { | |||
2542 | Unknown, | |||
2543 | Consumed, | |||
2544 | Unconsumed | |||
2545 | }; | |||
2546 | private: | |||
2547 | ConsumedState defaultState; | |||
2548 | ||||
2549 | public: | |||
2550 | static ConsumableAttr *CreateImplicit(ASTContext &Ctx, ConsumedState DefaultState, SourceRange Loc = SourceRange()) { | |||
2551 | auto *A = new (Ctx) ConsumableAttr(Loc, Ctx, DefaultState, 0); | |||
2552 | A->setImplicit(true); | |||
2553 | return A; | |||
2554 | } | |||
2555 | ||||
2556 | ConsumableAttr(SourceRange R, ASTContext &Ctx | |||
2557 | , ConsumedState DefaultState | |||
2558 | , unsigned SI | |||
2559 | ) | |||
2560 | : InheritableAttr(attr::Consumable, R, SI, false, false) | |||
2561 | , defaultState(DefaultState) | |||
2562 | { | |||
2563 | } | |||
2564 | ||||
2565 | ConsumableAttr *clone(ASTContext &C) const; | |||
2566 | void printPretty(raw_ostream &OS, | |||
2567 | const PrintingPolicy &Policy) const; | |||
2568 | const char *getSpelling() const; | |||
2569 | ConsumedState getDefaultState() const { | |||
2570 | return defaultState; | |||
2571 | } | |||
2572 | ||||
2573 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
2574 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
2575 | .Case("unknown", ConsumableAttr::Unknown) | |||
2576 | .Case("consumed", ConsumableAttr::Consumed) | |||
2577 | .Case("unconsumed", ConsumableAttr::Unconsumed) | |||
2578 | .Default(Optional<ConsumedState>()); | |||
2579 | if (R) { | |||
2580 | Out = *R; | |||
2581 | return true; | |||
2582 | } | |||
2583 | return false; | |||
2584 | } | |||
2585 | ||||
2586 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
2587 | switch(Val) { | |||
2588 | case ConsumableAttr::Unknown: return "unknown"; | |||
2589 | case ConsumableAttr::Consumed: return "consumed"; | |||
2590 | case ConsumableAttr::Unconsumed: return "unconsumed"; | |||
2591 | } | |||
2592 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 2592); | |||
2593 | } | |||
2594 | ||||
2595 | ||||
2596 | static bool classof(const Attr *A) { return A->getKind() == attr::Consumable; } | |||
2597 | }; | |||
2598 | ||||
2599 | class ConsumableAutoCastAttr : public InheritableAttr { | |||
2600 | public: | |||
2601 | static ConsumableAutoCastAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2602 | auto *A = new (Ctx) ConsumableAutoCastAttr(Loc, Ctx, 0); | |||
2603 | A->setImplicit(true); | |||
2604 | return A; | |||
2605 | } | |||
2606 | ||||
2607 | ConsumableAutoCastAttr(SourceRange R, ASTContext &Ctx | |||
2608 | , unsigned SI | |||
2609 | ) | |||
2610 | : InheritableAttr(attr::ConsumableAutoCast, R, SI, false, false) | |||
2611 | { | |||
2612 | } | |||
2613 | ||||
2614 | ConsumableAutoCastAttr *clone(ASTContext &C) const; | |||
2615 | void printPretty(raw_ostream &OS, | |||
2616 | const PrintingPolicy &Policy) const; | |||
2617 | const char *getSpelling() const; | |||
2618 | ||||
2619 | ||||
2620 | static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableAutoCast; } | |||
2621 | }; | |||
2622 | ||||
2623 | class ConsumableSetOnReadAttr : public InheritableAttr { | |||
2624 | public: | |||
2625 | static ConsumableSetOnReadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2626 | auto *A = new (Ctx) ConsumableSetOnReadAttr(Loc, Ctx, 0); | |||
2627 | A->setImplicit(true); | |||
2628 | return A; | |||
2629 | } | |||
2630 | ||||
2631 | ConsumableSetOnReadAttr(SourceRange R, ASTContext &Ctx | |||
2632 | , unsigned SI | |||
2633 | ) | |||
2634 | : InheritableAttr(attr::ConsumableSetOnRead, R, SI, false, false) | |||
2635 | { | |||
2636 | } | |||
2637 | ||||
2638 | ConsumableSetOnReadAttr *clone(ASTContext &C) const; | |||
2639 | void printPretty(raw_ostream &OS, | |||
2640 | const PrintingPolicy &Policy) const; | |||
2641 | const char *getSpelling() const; | |||
2642 | ||||
2643 | ||||
2644 | static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableSetOnRead; } | |||
2645 | }; | |||
2646 | ||||
2647 | class ConvergentAttr : public InheritableAttr { | |||
2648 | public: | |||
2649 | static ConvergentAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2650 | auto *A = new (Ctx) ConvergentAttr(Loc, Ctx, 0); | |||
2651 | A->setImplicit(true); | |||
2652 | return A; | |||
2653 | } | |||
2654 | ||||
2655 | ConvergentAttr(SourceRange R, ASTContext &Ctx | |||
2656 | , unsigned SI | |||
2657 | ) | |||
2658 | : InheritableAttr(attr::Convergent, R, SI, false, false) | |||
2659 | { | |||
2660 | } | |||
2661 | ||||
2662 | ConvergentAttr *clone(ASTContext &C) const; | |||
2663 | void printPretty(raw_ostream &OS, | |||
2664 | const PrintingPolicy &Policy) const; | |||
2665 | const char *getSpelling() const; | |||
2666 | ||||
2667 | ||||
2668 | static bool classof(const Attr *A) { return A->getKind() == attr::Convergent; } | |||
2669 | }; | |||
2670 | ||||
2671 | class DLLExportAttr : public InheritableAttr { | |||
2672 | public: | |||
2673 | static DLLExportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2674 | auto *A = new (Ctx) DLLExportAttr(Loc, Ctx, 0); | |||
2675 | A->setImplicit(true); | |||
2676 | return A; | |||
2677 | } | |||
2678 | ||||
2679 | DLLExportAttr(SourceRange R, ASTContext &Ctx | |||
2680 | , unsigned SI | |||
2681 | ) | |||
2682 | : InheritableAttr(attr::DLLExport, R, SI, false, false) | |||
2683 | { | |||
2684 | } | |||
2685 | ||||
2686 | DLLExportAttr *clone(ASTContext &C) const; | |||
2687 | void printPretty(raw_ostream &OS, | |||
2688 | const PrintingPolicy &Policy) const; | |||
2689 | const char *getSpelling() const; | |||
2690 | ||||
2691 | ||||
2692 | static bool classof(const Attr *A) { return A->getKind() == attr::DLLExport; } | |||
2693 | }; | |||
2694 | ||||
2695 | class DLLExportStaticLocalAttr : public InheritableAttr { | |||
2696 | public: | |||
2697 | static DLLExportStaticLocalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2698 | auto *A = new (Ctx) DLLExportStaticLocalAttr(Loc, Ctx, 0); | |||
2699 | A->setImplicit(true); | |||
2700 | return A; | |||
2701 | } | |||
2702 | ||||
2703 | DLLExportStaticLocalAttr(SourceRange R, ASTContext &Ctx | |||
2704 | , unsigned SI | |||
2705 | ) | |||
2706 | : InheritableAttr(attr::DLLExportStaticLocal, R, SI, false, false) | |||
2707 | { | |||
2708 | } | |||
2709 | ||||
2710 | DLLExportStaticLocalAttr *clone(ASTContext &C) const; | |||
2711 | void printPretty(raw_ostream &OS, | |||
2712 | const PrintingPolicy &Policy) const; | |||
2713 | const char *getSpelling() const; | |||
2714 | ||||
2715 | ||||
2716 | static bool classof(const Attr *A) { return A->getKind() == attr::DLLExportStaticLocal; } | |||
2717 | }; | |||
2718 | ||||
2719 | class DLLImportAttr : public InheritableAttr { | |||
2720 | public: | |||
2721 | static DLLImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2722 | auto *A = new (Ctx) DLLImportAttr(Loc, Ctx, 0); | |||
2723 | A->setImplicit(true); | |||
2724 | return A; | |||
2725 | } | |||
2726 | ||||
2727 | DLLImportAttr(SourceRange R, ASTContext &Ctx | |||
2728 | , unsigned SI | |||
2729 | ) | |||
2730 | : InheritableAttr(attr::DLLImport, R, SI, false, false) | |||
2731 | { | |||
2732 | } | |||
2733 | ||||
2734 | DLLImportAttr *clone(ASTContext &C) const; | |||
2735 | void printPretty(raw_ostream &OS, | |||
2736 | const PrintingPolicy &Policy) const; | |||
2737 | const char *getSpelling() const; | |||
2738 | ||||
2739 | private: | |||
2740 | bool PropagatedToBaseTemplate = false; | |||
2741 | ||||
2742 | public: | |||
2743 | void setPropagatedToBaseTemplate() { PropagatedToBaseTemplate = true; } | |||
2744 | bool wasPropagatedToBaseTemplate() { return PropagatedToBaseTemplate; } | |||
2745 | ||||
2746 | ||||
2747 | static bool classof(const Attr *A) { return A->getKind() == attr::DLLImport; } | |||
2748 | }; | |||
2749 | ||||
2750 | class DLLImportStaticLocalAttr : public InheritableAttr { | |||
2751 | public: | |||
2752 | static DLLImportStaticLocalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
2753 | auto *A = new (Ctx) DLLImportStaticLocalAttr(Loc, Ctx, 0); | |||
2754 | A->setImplicit(true); | |||
2755 | return A; | |||
2756 | } | |||
2757 | ||||
2758 | DLLImportStaticLocalAttr(SourceRange R, ASTContext &Ctx | |||
2759 | , unsigned SI | |||
2760 | ) | |||
2761 | : InheritableAttr(attr::DLLImportStaticLocal, R, SI, false, false) | |||
2762 | { | |||
2763 | } | |||
2764 | ||||
2765 | DLLImportStaticLocalAttr *clone(ASTContext &C) const; | |||
2766 | void printPretty(raw_ostream &OS, | |||
2767 | const PrintingPolicy &Policy) const; | |||
2768 | const char *getSpelling() const; | |||
2769 | ||||
2770 | ||||
2771 | static bool classof(const Attr *A) { return A->getKind() == attr::DLLImportStaticLocal; } | |||
2772 | }; | |||
2773 | ||||
2774 | class DeprecatedAttr : public InheritableAttr { | |||
2775 | unsigned messageLength; | |||
2776 | char *message; | |||
2777 | ||||
2778 | unsigned replacementLength; | |||
2779 | char *replacement; | |||
2780 | ||||
2781 | public: | |||
2782 | static DeprecatedAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) { | |||
2783 | auto *A = new (Ctx) DeprecatedAttr(Loc, Ctx, Message, Replacement, 0); | |||
2784 | A->setImplicit(true); | |||
2785 | return A; | |||
2786 | } | |||
2787 | ||||
2788 | DeprecatedAttr(SourceRange R, ASTContext &Ctx | |||
2789 | , llvm::StringRef Message | |||
2790 | , llvm::StringRef Replacement | |||
2791 | , unsigned SI | |||
2792 | ) | |||
2793 | : InheritableAttr(attr::Deprecated, R, SI, false, false) | |||
2794 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
2795 | , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength]) | |||
2796 | { | |||
2797 | if (!Message.empty()) | |||
2798 | std::memcpy(message, Message.data(), messageLength); | |||
2799 | if (!Replacement.empty()) | |||
2800 | std::memcpy(replacement, Replacement.data(), replacementLength); | |||
2801 | } | |||
2802 | ||||
2803 | DeprecatedAttr(SourceRange R, ASTContext &Ctx | |||
2804 | , unsigned SI | |||
2805 | ) | |||
2806 | : InheritableAttr(attr::Deprecated, R, SI, false, false) | |||
2807 | , messageLength(0),message(nullptr) | |||
2808 | , replacementLength(0),replacement(nullptr) | |||
2809 | { | |||
2810 | } | |||
2811 | ||||
2812 | DeprecatedAttr *clone(ASTContext &C) const; | |||
2813 | void printPretty(raw_ostream &OS, | |||
2814 | const PrintingPolicy &Policy) const; | |||
2815 | const char *getSpelling() const; | |||
2816 | llvm::StringRef getMessage() const { | |||
2817 | return llvm::StringRef(message, messageLength); | |||
2818 | } | |||
2819 | unsigned getMessageLength() const { | |||
2820 | return messageLength; | |||
2821 | } | |||
2822 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
2823 | messageLength = S.size(); | |||
2824 | this->message = new (C, 1) char [messageLength]; | |||
2825 | if (!S.empty()) | |||
2826 | std::memcpy(this->message, S.data(), messageLength); | |||
2827 | } | |||
2828 | ||||
2829 | llvm::StringRef getReplacement() const { | |||
2830 | return llvm::StringRef(replacement, replacementLength); | |||
2831 | } | |||
2832 | unsigned getReplacementLength() const { | |||
2833 | return replacementLength; | |||
2834 | } | |||
2835 | void setReplacement(ASTContext &C, llvm::StringRef S) { | |||
2836 | replacementLength = S.size(); | |||
2837 | this->replacement = new (C, 1) char [replacementLength]; | |||
2838 | if (!S.empty()) | |||
2839 | std::memcpy(this->replacement, S.data(), replacementLength); | |||
2840 | } | |||
2841 | ||||
2842 | ||||
2843 | ||||
2844 | static bool classof(const Attr *A) { return A->getKind() == attr::Deprecated; } | |||
2845 | }; | |||
2846 | ||||
2847 | class DestructorAttr : public InheritableAttr { | |||
2848 | int priority; | |||
2849 | ||||
2850 | public: | |||
2851 | static DestructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) { | |||
2852 | auto *A = new (Ctx) DestructorAttr(Loc, Ctx, Priority, 0); | |||
2853 | A->setImplicit(true); | |||
2854 | return A; | |||
2855 | } | |||
2856 | ||||
2857 | DestructorAttr(SourceRange R, ASTContext &Ctx | |||
2858 | , int Priority | |||
2859 | , unsigned SI | |||
2860 | ) | |||
2861 | : InheritableAttr(attr::Destructor, R, SI, false, false) | |||
2862 | , priority(Priority) | |||
2863 | { | |||
2864 | } | |||
2865 | ||||
2866 | DestructorAttr(SourceRange R, ASTContext &Ctx | |||
2867 | , unsigned SI | |||
2868 | ) | |||
2869 | : InheritableAttr(attr::Destructor, R, SI, false, false) | |||
2870 | , priority() | |||
2871 | { | |||
2872 | } | |||
2873 | ||||
2874 | DestructorAttr *clone(ASTContext &C) const; | |||
2875 | void printPretty(raw_ostream &OS, | |||
2876 | const PrintingPolicy &Policy) const; | |||
2877 | const char *getSpelling() const; | |||
2878 | int getPriority() const { | |||
2879 | return priority; | |||
2880 | } | |||
2881 | ||||
2882 | static const int DefaultPriority = 65535; | |||
2883 | ||||
2884 | ||||
2885 | ||||
2886 | static bool classof(const Attr *A) { return A->getKind() == attr::Destructor; } | |||
2887 | }; | |||
2888 | ||||
2889 | class DiagnoseIfAttr : public InheritableAttr { | |||
2890 | Expr * cond; | |||
2891 | ||||
2892 | unsigned messageLength; | |||
2893 | char *message; | |||
2894 | ||||
2895 | public: | |||
2896 | enum DiagnosticType { | |||
2897 | DT_Error, | |||
2898 | DT_Warning | |||
2899 | }; | |||
2900 | private: | |||
2901 | DiagnosticType diagnosticType; | |||
2902 | ||||
2903 | bool argDependent; | |||
2904 | ||||
2905 | NamedDecl * parent; | |||
2906 | ||||
2907 | public: | |||
2908 | static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, bool ArgDependent, NamedDecl * Parent, SourceRange Loc = SourceRange()) { | |||
2909 | auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, ArgDependent, Parent, 0); | |||
2910 | A->setImplicit(true); | |||
2911 | return A; | |||
2912 | } | |||
2913 | ||||
2914 | static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, SourceRange Loc = SourceRange()) { | |||
2915 | auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, 0); | |||
2916 | A->setImplicit(true); | |||
2917 | return A; | |||
2918 | } | |||
2919 | ||||
2920 | DiagnoseIfAttr(SourceRange R, ASTContext &Ctx | |||
2921 | , Expr * Cond | |||
2922 | , llvm::StringRef Message | |||
2923 | , DiagnosticType DiagnosticType | |||
2924 | , bool ArgDependent | |||
2925 | , NamedDecl * Parent | |||
2926 | , unsigned SI | |||
2927 | ) | |||
2928 | : InheritableAttr(attr::DiagnoseIf, R, SI, true, true) | |||
2929 | , cond(Cond) | |||
2930 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
2931 | , diagnosticType(DiagnosticType) | |||
2932 | , argDependent(ArgDependent) | |||
2933 | , parent(Parent) | |||
2934 | { | |||
2935 | if (!Message.empty()) | |||
2936 | std::memcpy(message, Message.data(), messageLength); | |||
2937 | } | |||
2938 | ||||
2939 | DiagnoseIfAttr(SourceRange R, ASTContext &Ctx | |||
2940 | , Expr * Cond | |||
2941 | , llvm::StringRef Message | |||
2942 | , DiagnosticType DiagnosticType | |||
2943 | , unsigned SI | |||
2944 | ) | |||
2945 | : InheritableAttr(attr::DiagnoseIf, R, SI, true, true) | |||
2946 | , cond(Cond) | |||
2947 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
2948 | , diagnosticType(DiagnosticType) | |||
2949 | , argDependent() | |||
2950 | , parent() | |||
2951 | { | |||
2952 | if (!Message.empty()) | |||
2953 | std::memcpy(message, Message.data(), messageLength); | |||
2954 | } | |||
2955 | ||||
2956 | DiagnoseIfAttr *clone(ASTContext &C) const; | |||
2957 | void printPretty(raw_ostream &OS, | |||
2958 | const PrintingPolicy &Policy) const; | |||
2959 | const char *getSpelling() const; | |||
2960 | Expr * getCond() const { | |||
2961 | return cond; | |||
2962 | } | |||
2963 | ||||
2964 | llvm::StringRef getMessage() const { | |||
2965 | return llvm::StringRef(message, messageLength); | |||
2966 | } | |||
2967 | unsigned getMessageLength() const { | |||
2968 | return messageLength; | |||
2969 | } | |||
2970 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
2971 | messageLength = S.size(); | |||
2972 | this->message = new (C, 1) char [messageLength]; | |||
2973 | if (!S.empty()) | |||
2974 | std::memcpy(this->message, S.data(), messageLength); | |||
2975 | } | |||
2976 | ||||
2977 | DiagnosticType getDiagnosticType() const { | |||
2978 | return diagnosticType; | |||
2979 | } | |||
2980 | ||||
2981 | static bool ConvertStrToDiagnosticType(StringRef Val, DiagnosticType &Out) { | |||
2982 | Optional<DiagnosticType> R = llvm::StringSwitch<Optional<DiagnosticType>>(Val) | |||
2983 | .Case("error", DiagnoseIfAttr::DT_Error) | |||
2984 | .Case("warning", DiagnoseIfAttr::DT_Warning) | |||
2985 | .Default(Optional<DiagnosticType>()); | |||
2986 | if (R) { | |||
2987 | Out = *R; | |||
2988 | return true; | |||
2989 | } | |||
2990 | return false; | |||
2991 | } | |||
2992 | ||||
2993 | static const char *ConvertDiagnosticTypeToStr(DiagnosticType Val) { | |||
2994 | switch(Val) { | |||
2995 | case DiagnoseIfAttr::DT_Error: return "error"; | |||
2996 | case DiagnoseIfAttr::DT_Warning: return "warning"; | |||
2997 | } | |||
2998 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 2998); | |||
2999 | } | |||
3000 | bool getArgDependent() const { | |||
3001 | return argDependent; | |||
3002 | } | |||
3003 | ||||
3004 | NamedDecl * getParent() const { | |||
3005 | return parent; | |||
3006 | } | |||
3007 | ||||
3008 | ||||
3009 | bool isError() const { return diagnosticType == DT_Error; } | |||
3010 | bool isWarning() const { return diagnosticType == DT_Warning; } | |||
3011 | ||||
3012 | ||||
3013 | static bool classof(const Attr *A) { return A->getKind() == attr::DiagnoseIf; } | |||
3014 | }; | |||
3015 | ||||
3016 | class DisableTailCallsAttr : public InheritableAttr { | |||
3017 | public: | |||
3018 | static DisableTailCallsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3019 | auto *A = new (Ctx) DisableTailCallsAttr(Loc, Ctx, 0); | |||
3020 | A->setImplicit(true); | |||
3021 | return A; | |||
3022 | } | |||
3023 | ||||
3024 | DisableTailCallsAttr(SourceRange R, ASTContext &Ctx | |||
3025 | , unsigned SI | |||
3026 | ) | |||
3027 | : InheritableAttr(attr::DisableTailCalls, R, SI, false, false) | |||
3028 | { | |||
3029 | } | |||
3030 | ||||
3031 | DisableTailCallsAttr *clone(ASTContext &C) const; | |||
3032 | void printPretty(raw_ostream &OS, | |||
3033 | const PrintingPolicy &Policy) const; | |||
3034 | const char *getSpelling() const; | |||
3035 | ||||
3036 | ||||
3037 | static bool classof(const Attr *A) { return A->getKind() == attr::DisableTailCalls; } | |||
3038 | }; | |||
3039 | ||||
3040 | class EmptyBasesAttr : public InheritableAttr { | |||
3041 | public: | |||
3042 | static EmptyBasesAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3043 | auto *A = new (Ctx) EmptyBasesAttr(Loc, Ctx, 0); | |||
3044 | A->setImplicit(true); | |||
3045 | return A; | |||
3046 | } | |||
3047 | ||||
3048 | EmptyBasesAttr(SourceRange R, ASTContext &Ctx | |||
3049 | , unsigned SI | |||
3050 | ) | |||
3051 | : InheritableAttr(attr::EmptyBases, R, SI, false, false) | |||
3052 | { | |||
3053 | } | |||
3054 | ||||
3055 | EmptyBasesAttr *clone(ASTContext &C) const; | |||
3056 | void printPretty(raw_ostream &OS, | |||
3057 | const PrintingPolicy &Policy) const; | |||
3058 | const char *getSpelling() const; | |||
3059 | ||||
3060 | ||||
3061 | static bool classof(const Attr *A) { return A->getKind() == attr::EmptyBases; } | |||
3062 | }; | |||
3063 | ||||
3064 | class EnableIfAttr : public InheritableAttr { | |||
3065 | Expr * cond; | |||
3066 | ||||
3067 | unsigned messageLength; | |||
3068 | char *message; | |||
3069 | ||||
3070 | public: | |||
3071 | static EnableIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, SourceRange Loc = SourceRange()) { | |||
3072 | auto *A = new (Ctx) EnableIfAttr(Loc, Ctx, Cond, Message, 0); | |||
3073 | A->setImplicit(true); | |||
3074 | return A; | |||
3075 | } | |||
3076 | ||||
3077 | EnableIfAttr(SourceRange R, ASTContext &Ctx | |||
3078 | , Expr * Cond | |||
3079 | , llvm::StringRef Message | |||
3080 | , unsigned SI | |||
3081 | ) | |||
3082 | : InheritableAttr(attr::EnableIf, R, SI, false, false) | |||
3083 | , cond(Cond) | |||
3084 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
3085 | { | |||
3086 | if (!Message.empty()) | |||
3087 | std::memcpy(message, Message.data(), messageLength); | |||
3088 | } | |||
3089 | ||||
3090 | EnableIfAttr *clone(ASTContext &C) const; | |||
3091 | void printPretty(raw_ostream &OS, | |||
3092 | const PrintingPolicy &Policy) const; | |||
3093 | const char *getSpelling() const; | |||
3094 | Expr * getCond() const { | |||
3095 | return cond; | |||
3096 | } | |||
3097 | ||||
3098 | llvm::StringRef getMessage() const { | |||
3099 | return llvm::StringRef(message, messageLength); | |||
3100 | } | |||
3101 | unsigned getMessageLength() const { | |||
3102 | return messageLength; | |||
3103 | } | |||
3104 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
3105 | messageLength = S.size(); | |||
3106 | this->message = new (C, 1) char [messageLength]; | |||
3107 | if (!S.empty()) | |||
3108 | std::memcpy(this->message, S.data(), messageLength); | |||
3109 | } | |||
3110 | ||||
3111 | ||||
3112 | ||||
3113 | static bool classof(const Attr *A) { return A->getKind() == attr::EnableIf; } | |||
3114 | }; | |||
3115 | ||||
3116 | class EnumExtensibilityAttr : public InheritableAttr { | |||
3117 | public: | |||
3118 | enum Kind { | |||
3119 | Closed, | |||
3120 | Open | |||
3121 | }; | |||
3122 | private: | |||
3123 | Kind extensibility; | |||
3124 | ||||
3125 | public: | |||
3126 | static EnumExtensibilityAttr *CreateImplicit(ASTContext &Ctx, Kind Extensibility, SourceRange Loc = SourceRange()) { | |||
3127 | auto *A = new (Ctx) EnumExtensibilityAttr(Loc, Ctx, Extensibility, 0); | |||
3128 | A->setImplicit(true); | |||
3129 | return A; | |||
3130 | } | |||
3131 | ||||
3132 | EnumExtensibilityAttr(SourceRange R, ASTContext &Ctx | |||
3133 | , Kind Extensibility | |||
3134 | , unsigned SI | |||
3135 | ) | |||
3136 | : InheritableAttr(attr::EnumExtensibility, R, SI, false, false) | |||
3137 | , extensibility(Extensibility) | |||
3138 | { | |||
3139 | } | |||
3140 | ||||
3141 | EnumExtensibilityAttr *clone(ASTContext &C) const; | |||
3142 | void printPretty(raw_ostream &OS, | |||
3143 | const PrintingPolicy &Policy) const; | |||
3144 | const char *getSpelling() const; | |||
3145 | Kind getExtensibility() const { | |||
3146 | return extensibility; | |||
3147 | } | |||
3148 | ||||
3149 | static bool ConvertStrToKind(StringRef Val, Kind &Out) { | |||
3150 | Optional<Kind> R = llvm::StringSwitch<Optional<Kind>>(Val) | |||
3151 | .Case("closed", EnumExtensibilityAttr::Closed) | |||
3152 | .Case("open", EnumExtensibilityAttr::Open) | |||
3153 | .Default(Optional<Kind>()); | |||
3154 | if (R) { | |||
3155 | Out = *R; | |||
3156 | return true; | |||
3157 | } | |||
3158 | return false; | |||
3159 | } | |||
3160 | ||||
3161 | static const char *ConvertKindToStr(Kind Val) { | |||
3162 | switch(Val) { | |||
3163 | case EnumExtensibilityAttr::Closed: return "closed"; | |||
3164 | case EnumExtensibilityAttr::Open: return "open"; | |||
3165 | } | |||
3166 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 3166); | |||
3167 | } | |||
3168 | ||||
3169 | ||||
3170 | static bool classof(const Attr *A) { return A->getKind() == attr::EnumExtensibility; } | |||
3171 | }; | |||
3172 | ||||
3173 | class ExcludeFromExplicitInstantiationAttr : public InheritableAttr { | |||
3174 | public: | |||
3175 | static ExcludeFromExplicitInstantiationAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3176 | auto *A = new (Ctx) ExcludeFromExplicitInstantiationAttr(Loc, Ctx, 0); | |||
3177 | A->setImplicit(true); | |||
3178 | return A; | |||
3179 | } | |||
3180 | ||||
3181 | ExcludeFromExplicitInstantiationAttr(SourceRange R, ASTContext &Ctx | |||
3182 | , unsigned SI | |||
3183 | ) | |||
3184 | : InheritableAttr(attr::ExcludeFromExplicitInstantiation, R, SI, false, false) | |||
3185 | { | |||
3186 | } | |||
3187 | ||||
3188 | ExcludeFromExplicitInstantiationAttr *clone(ASTContext &C) const; | |||
3189 | void printPretty(raw_ostream &OS, | |||
3190 | const PrintingPolicy &Policy) const; | |||
3191 | const char *getSpelling() const; | |||
3192 | ||||
3193 | ||||
3194 | static bool classof(const Attr *A) { return A->getKind() == attr::ExcludeFromExplicitInstantiation; } | |||
3195 | }; | |||
3196 | ||||
3197 | class ExclusiveTrylockFunctionAttr : public InheritableAttr { | |||
3198 | Expr * successValue; | |||
3199 | ||||
3200 | unsigned args_Size; | |||
3201 | Expr * *args_; | |||
3202 | ||||
3203 | public: | |||
3204 | static ExclusiveTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
3205 | auto *A = new (Ctx) ExclusiveTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0); | |||
3206 | A->setImplicit(true); | |||
3207 | return A; | |||
3208 | } | |||
3209 | ||||
3210 | ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx | |||
3211 | , Expr * SuccessValue | |||
3212 | , Expr * *Args, unsigned ArgsSize | |||
3213 | , unsigned SI | |||
3214 | ) | |||
3215 | : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true) | |||
3216 | , successValue(SuccessValue) | |||
3217 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
3218 | { | |||
3219 | std::copy(Args, Args + args_Size, args_); | |||
3220 | } | |||
3221 | ||||
3222 | ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx | |||
3223 | , Expr * SuccessValue | |||
3224 | , unsigned SI | |||
3225 | ) | |||
3226 | : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true) | |||
3227 | , successValue(SuccessValue) | |||
3228 | , args_Size(0), args_(nullptr) | |||
3229 | { | |||
3230 | } | |||
3231 | ||||
3232 | ExclusiveTrylockFunctionAttr *clone(ASTContext &C) const; | |||
3233 | void printPretty(raw_ostream &OS, | |||
3234 | const PrintingPolicy &Policy) const; | |||
3235 | const char *getSpelling() const; | |||
3236 | Expr * getSuccessValue() const { | |||
3237 | return successValue; | |||
3238 | } | |||
3239 | ||||
3240 | typedef Expr ** args_iterator; | |||
3241 | args_iterator args_begin() const { return args_; } | |||
3242 | args_iterator args_end() const { return args_ + args_Size; } | |||
3243 | unsigned args_size() const { return args_Size; } | |||
3244 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
3245 | ||||
3246 | ||||
3247 | ||||
3248 | ||||
3249 | static bool classof(const Attr *A) { return A->getKind() == attr::ExclusiveTrylockFunction; } | |||
3250 | }; | |||
3251 | ||||
3252 | class ExternalSourceSymbolAttr : public InheritableAttr { | |||
3253 | unsigned languageLength; | |||
3254 | char *language; | |||
3255 | ||||
3256 | unsigned definedInLength; | |||
3257 | char *definedIn; | |||
3258 | ||||
3259 | bool generatedDeclaration; | |||
3260 | ||||
3261 | public: | |||
3262 | static ExternalSourceSymbolAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Language, llvm::StringRef DefinedIn, bool GeneratedDeclaration, SourceRange Loc = SourceRange()) { | |||
3263 | auto *A = new (Ctx) ExternalSourceSymbolAttr(Loc, Ctx, Language, DefinedIn, GeneratedDeclaration, 0); | |||
3264 | A->setImplicit(true); | |||
3265 | return A; | |||
3266 | } | |||
3267 | ||||
3268 | ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx | |||
3269 | , llvm::StringRef Language | |||
3270 | , llvm::StringRef DefinedIn | |||
3271 | , bool GeneratedDeclaration | |||
3272 | , unsigned SI | |||
3273 | ) | |||
3274 | : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false) | |||
3275 | , languageLength(Language.size()),language(new (Ctx, 1) char[languageLength]) | |||
3276 | , definedInLength(DefinedIn.size()),definedIn(new (Ctx, 1) char[definedInLength]) | |||
3277 | , generatedDeclaration(GeneratedDeclaration) | |||
3278 | { | |||
3279 | if (!Language.empty()) | |||
3280 | std::memcpy(language, Language.data(), languageLength); | |||
3281 | if (!DefinedIn.empty()) | |||
3282 | std::memcpy(definedIn, DefinedIn.data(), definedInLength); | |||
3283 | } | |||
3284 | ||||
3285 | ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx | |||
3286 | , unsigned SI | |||
3287 | ) | |||
3288 | : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false) | |||
3289 | , languageLength(0),language(nullptr) | |||
3290 | , definedInLength(0),definedIn(nullptr) | |||
3291 | , generatedDeclaration() | |||
3292 | { | |||
3293 | } | |||
3294 | ||||
3295 | ExternalSourceSymbolAttr *clone(ASTContext &C) const; | |||
3296 | void printPretty(raw_ostream &OS, | |||
3297 | const PrintingPolicy &Policy) const; | |||
3298 | const char *getSpelling() const; | |||
3299 | llvm::StringRef getLanguage() const { | |||
3300 | return llvm::StringRef(language, languageLength); | |||
3301 | } | |||
3302 | unsigned getLanguageLength() const { | |||
3303 | return languageLength; | |||
3304 | } | |||
3305 | void setLanguage(ASTContext &C, llvm::StringRef S) { | |||
3306 | languageLength = S.size(); | |||
3307 | this->language = new (C, 1) char [languageLength]; | |||
3308 | if (!S.empty()) | |||
3309 | std::memcpy(this->language, S.data(), languageLength); | |||
3310 | } | |||
3311 | ||||
3312 | llvm::StringRef getDefinedIn() const { | |||
3313 | return llvm::StringRef(definedIn, definedInLength); | |||
3314 | } | |||
3315 | unsigned getDefinedInLength() const { | |||
3316 | return definedInLength; | |||
3317 | } | |||
3318 | void setDefinedIn(ASTContext &C, llvm::StringRef S) { | |||
3319 | definedInLength = S.size(); | |||
3320 | this->definedIn = new (C, 1) char [definedInLength]; | |||
3321 | if (!S.empty()) | |||
3322 | std::memcpy(this->definedIn, S.data(), definedInLength); | |||
3323 | } | |||
3324 | ||||
3325 | bool getGeneratedDeclaration() const { | |||
3326 | return generatedDeclaration; | |||
3327 | } | |||
3328 | ||||
3329 | ||||
3330 | ||||
3331 | static bool classof(const Attr *A) { return A->getKind() == attr::ExternalSourceSymbol; } | |||
3332 | }; | |||
3333 | ||||
3334 | class FallThroughAttr : public StmtAttr { | |||
3335 | public: | |||
3336 | static FallThroughAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3337 | auto *A = new (Ctx) FallThroughAttr(Loc, Ctx, 0); | |||
3338 | A->setImplicit(true); | |||
3339 | return A; | |||
3340 | } | |||
3341 | ||||
3342 | FallThroughAttr(SourceRange R, ASTContext &Ctx | |||
3343 | , unsigned SI | |||
3344 | ) | |||
3345 | : StmtAttr(attr::FallThrough, R, SI, false) | |||
3346 | { | |||
3347 | } | |||
3348 | ||||
3349 | FallThroughAttr *clone(ASTContext &C) const; | |||
3350 | void printPretty(raw_ostream &OS, | |||
3351 | const PrintingPolicy &Policy) const; | |||
3352 | const char *getSpelling() const; | |||
3353 | ||||
3354 | ||||
3355 | static bool classof(const Attr *A) { return A->getKind() == attr::FallThrough; } | |||
3356 | }; | |||
3357 | ||||
3358 | class FastCallAttr : public InheritableAttr { | |||
3359 | public: | |||
3360 | static FastCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3361 | auto *A = new (Ctx) FastCallAttr(Loc, Ctx, 0); | |||
3362 | A->setImplicit(true); | |||
3363 | return A; | |||
3364 | } | |||
3365 | ||||
3366 | FastCallAttr(SourceRange R, ASTContext &Ctx | |||
3367 | , unsigned SI | |||
3368 | ) | |||
3369 | : InheritableAttr(attr::FastCall, R, SI, false, false) | |||
3370 | { | |||
3371 | } | |||
3372 | ||||
3373 | FastCallAttr *clone(ASTContext &C) const; | |||
3374 | void printPretty(raw_ostream &OS, | |||
3375 | const PrintingPolicy &Policy) const; | |||
3376 | const char *getSpelling() const; | |||
3377 | ||||
3378 | ||||
3379 | static bool classof(const Attr *A) { return A->getKind() == attr::FastCall; } | |||
3380 | }; | |||
3381 | ||||
3382 | class FinalAttr : public InheritableAttr { | |||
3383 | public: | |||
3384 | enum Spelling { | |||
3385 | Keyword_final = 0, | |||
3386 | Keyword_sealed = 1 | |||
3387 | }; | |||
3388 | ||||
3389 | static FinalAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
3390 | auto *A = new (Ctx) FinalAttr(Loc, Ctx, S); | |||
3391 | A->setImplicit(true); | |||
3392 | return A; | |||
3393 | } | |||
3394 | ||||
3395 | FinalAttr(SourceRange R, ASTContext &Ctx | |||
3396 | , unsigned SI | |||
3397 | ) | |||
3398 | : InheritableAttr(attr::Final, R, SI, false, false) | |||
3399 | { | |||
3400 | } | |||
3401 | ||||
3402 | FinalAttr *clone(ASTContext &C) const; | |||
3403 | void printPretty(raw_ostream &OS, | |||
3404 | const PrintingPolicy &Policy) const; | |||
3405 | const char *getSpelling() const; | |||
3406 | Spelling getSemanticSpelling() const { | |||
3407 | switch (SpellingListIndex) { | |||
3408 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 3408); | |||
3409 | case 0: return Keyword_final; | |||
3410 | case 1: return Keyword_sealed; | |||
3411 | } | |||
3412 | } | |||
3413 | bool isSpelledAsSealed() const { return SpellingListIndex == 1; } | |||
3414 | ||||
3415 | ||||
3416 | static bool classof(const Attr *A) { return A->getKind() == attr::Final; } | |||
3417 | }; | |||
3418 | ||||
3419 | class FlagEnumAttr : public InheritableAttr { | |||
3420 | public: | |||
3421 | static FlagEnumAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3422 | auto *A = new (Ctx) FlagEnumAttr(Loc, Ctx, 0); | |||
3423 | A->setImplicit(true); | |||
3424 | return A; | |||
3425 | } | |||
3426 | ||||
3427 | FlagEnumAttr(SourceRange R, ASTContext &Ctx | |||
3428 | , unsigned SI | |||
3429 | ) | |||
3430 | : InheritableAttr(attr::FlagEnum, R, SI, false, false) | |||
3431 | { | |||
3432 | } | |||
3433 | ||||
3434 | FlagEnumAttr *clone(ASTContext &C) const; | |||
3435 | void printPretty(raw_ostream &OS, | |||
3436 | const PrintingPolicy &Policy) const; | |||
3437 | const char *getSpelling() const; | |||
3438 | ||||
3439 | ||||
3440 | static bool classof(const Attr *A) { return A->getKind() == attr::FlagEnum; } | |||
3441 | }; | |||
3442 | ||||
3443 | class FlattenAttr : public InheritableAttr { | |||
3444 | public: | |||
3445 | static FlattenAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3446 | auto *A = new (Ctx) FlattenAttr(Loc, Ctx, 0); | |||
3447 | A->setImplicit(true); | |||
3448 | return A; | |||
3449 | } | |||
3450 | ||||
3451 | FlattenAttr(SourceRange R, ASTContext &Ctx | |||
3452 | , unsigned SI | |||
3453 | ) | |||
3454 | : InheritableAttr(attr::Flatten, R, SI, false, false) | |||
3455 | { | |||
3456 | } | |||
3457 | ||||
3458 | FlattenAttr *clone(ASTContext &C) const; | |||
3459 | void printPretty(raw_ostream &OS, | |||
3460 | const PrintingPolicy &Policy) const; | |||
3461 | const char *getSpelling() const; | |||
3462 | ||||
3463 | ||||
3464 | static bool classof(const Attr *A) { return A->getKind() == attr::Flatten; } | |||
3465 | }; | |||
3466 | ||||
3467 | class FormatAttr : public InheritableAttr { | |||
3468 | IdentifierInfo * type; | |||
3469 | ||||
3470 | int formatIdx; | |||
3471 | ||||
3472 | int firstArg; | |||
3473 | ||||
3474 | public: | |||
3475 | static FormatAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Type, int FormatIdx, int FirstArg, SourceRange Loc = SourceRange()) { | |||
3476 | auto *A = new (Ctx) FormatAttr(Loc, Ctx, Type, FormatIdx, FirstArg, 0); | |||
3477 | A->setImplicit(true); | |||
3478 | return A; | |||
3479 | } | |||
3480 | ||||
3481 | FormatAttr(SourceRange R, ASTContext &Ctx | |||
3482 | , IdentifierInfo * Type | |||
3483 | , int FormatIdx | |||
3484 | , int FirstArg | |||
3485 | , unsigned SI | |||
3486 | ) | |||
3487 | : InheritableAttr(attr::Format, R, SI, false, false) | |||
3488 | , type(Type) | |||
3489 | , formatIdx(FormatIdx) | |||
3490 | , firstArg(FirstArg) | |||
3491 | { | |||
3492 | } | |||
3493 | ||||
3494 | FormatAttr *clone(ASTContext &C) const; | |||
3495 | void printPretty(raw_ostream &OS, | |||
3496 | const PrintingPolicy &Policy) const; | |||
3497 | const char *getSpelling() const; | |||
3498 | IdentifierInfo * getType() const { | |||
3499 | return type; | |||
3500 | } | |||
3501 | ||||
3502 | int getFormatIdx() const { | |||
3503 | return formatIdx; | |||
3504 | } | |||
3505 | ||||
3506 | int getFirstArg() const { | |||
3507 | return firstArg; | |||
3508 | } | |||
3509 | ||||
3510 | ||||
3511 | ||||
3512 | static bool classof(const Attr *A) { return A->getKind() == attr::Format; } | |||
3513 | }; | |||
3514 | ||||
3515 | class FormatArgAttr : public InheritableAttr { | |||
3516 | ParamIdx formatIdx; | |||
3517 | ||||
3518 | public: | |||
3519 | static FormatArgAttr *CreateImplicit(ASTContext &Ctx, ParamIdx FormatIdx, SourceRange Loc = SourceRange()) { | |||
3520 | auto *A = new (Ctx) FormatArgAttr(Loc, Ctx, FormatIdx, 0); | |||
3521 | A->setImplicit(true); | |||
3522 | return A; | |||
3523 | } | |||
3524 | ||||
3525 | FormatArgAttr(SourceRange R, ASTContext &Ctx | |||
3526 | , ParamIdx FormatIdx | |||
3527 | , unsigned SI | |||
3528 | ) | |||
3529 | : InheritableAttr(attr::FormatArg, R, SI, false, false) | |||
3530 | , formatIdx(FormatIdx) | |||
3531 | { | |||
3532 | } | |||
3533 | ||||
3534 | FormatArgAttr *clone(ASTContext &C) const; | |||
3535 | void printPretty(raw_ostream &OS, | |||
3536 | const PrintingPolicy &Policy) const; | |||
3537 | const char *getSpelling() const; | |||
3538 | ParamIdx getFormatIdx() const { | |||
3539 | return formatIdx; | |||
3540 | } | |||
3541 | ||||
3542 | ||||
3543 | ||||
3544 | static bool classof(const Attr *A) { return A->getKind() == attr::FormatArg; } | |||
3545 | }; | |||
3546 | ||||
3547 | class GNUInlineAttr : public InheritableAttr { | |||
3548 | public: | |||
3549 | static GNUInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3550 | auto *A = new (Ctx) GNUInlineAttr(Loc, Ctx, 0); | |||
3551 | A->setImplicit(true); | |||
3552 | return A; | |||
3553 | } | |||
3554 | ||||
3555 | GNUInlineAttr(SourceRange R, ASTContext &Ctx | |||
3556 | , unsigned SI | |||
3557 | ) | |||
3558 | : InheritableAttr(attr::GNUInline, R, SI, false, false) | |||
3559 | { | |||
3560 | } | |||
3561 | ||||
3562 | GNUInlineAttr *clone(ASTContext &C) const; | |||
3563 | void printPretty(raw_ostream &OS, | |||
3564 | const PrintingPolicy &Policy) const; | |||
3565 | const char *getSpelling() const; | |||
3566 | ||||
3567 | ||||
3568 | static bool classof(const Attr *A) { return A->getKind() == attr::GNUInline; } | |||
3569 | }; | |||
3570 | ||||
3571 | class GuardedByAttr : public InheritableAttr { | |||
3572 | Expr * arg; | |||
3573 | ||||
3574 | public: | |||
3575 | static GuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) { | |||
3576 | auto *A = new (Ctx) GuardedByAttr(Loc, Ctx, Arg, 0); | |||
3577 | A->setImplicit(true); | |||
3578 | return A; | |||
3579 | } | |||
3580 | ||||
3581 | GuardedByAttr(SourceRange R, ASTContext &Ctx | |||
3582 | , Expr * Arg | |||
3583 | , unsigned SI | |||
3584 | ) | |||
3585 | : InheritableAttr(attr::GuardedBy, R, SI, true, true) | |||
3586 | , arg(Arg) | |||
3587 | { | |||
3588 | } | |||
3589 | ||||
3590 | GuardedByAttr *clone(ASTContext &C) const; | |||
3591 | void printPretty(raw_ostream &OS, | |||
3592 | const PrintingPolicy &Policy) const; | |||
3593 | const char *getSpelling() const; | |||
3594 | Expr * getArg() const { | |||
3595 | return arg; | |||
3596 | } | |||
3597 | ||||
3598 | ||||
3599 | ||||
3600 | static bool classof(const Attr *A) { return A->getKind() == attr::GuardedBy; } | |||
3601 | }; | |||
3602 | ||||
3603 | class GuardedVarAttr : public InheritableAttr { | |||
3604 | public: | |||
3605 | static GuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3606 | auto *A = new (Ctx) GuardedVarAttr(Loc, Ctx, 0); | |||
3607 | A->setImplicit(true); | |||
3608 | return A; | |||
3609 | } | |||
3610 | ||||
3611 | GuardedVarAttr(SourceRange R, ASTContext &Ctx | |||
3612 | , unsigned SI | |||
3613 | ) | |||
3614 | : InheritableAttr(attr::GuardedVar, R, SI, false, false) | |||
3615 | { | |||
3616 | } | |||
3617 | ||||
3618 | GuardedVarAttr *clone(ASTContext &C) const; | |||
3619 | void printPretty(raw_ostream &OS, | |||
3620 | const PrintingPolicy &Policy) const; | |||
3621 | const char *getSpelling() const; | |||
3622 | ||||
3623 | ||||
3624 | static bool classof(const Attr *A) { return A->getKind() == attr::GuardedVar; } | |||
3625 | }; | |||
3626 | ||||
3627 | class HotAttr : public InheritableAttr { | |||
3628 | public: | |||
3629 | static HotAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3630 | auto *A = new (Ctx) HotAttr(Loc, Ctx, 0); | |||
3631 | A->setImplicit(true); | |||
3632 | return A; | |||
3633 | } | |||
3634 | ||||
3635 | HotAttr(SourceRange R, ASTContext &Ctx | |||
3636 | , unsigned SI | |||
3637 | ) | |||
3638 | : InheritableAttr(attr::Hot, R, SI, false, false) | |||
3639 | { | |||
3640 | } | |||
3641 | ||||
3642 | HotAttr *clone(ASTContext &C) const; | |||
3643 | void printPretty(raw_ostream &OS, | |||
3644 | const PrintingPolicy &Policy) const; | |||
3645 | const char *getSpelling() const; | |||
3646 | ||||
3647 | ||||
3648 | static bool classof(const Attr *A) { return A->getKind() == attr::Hot; } | |||
3649 | }; | |||
3650 | ||||
3651 | class IBActionAttr : public InheritableAttr { | |||
3652 | public: | |||
3653 | static IBActionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3654 | auto *A = new (Ctx) IBActionAttr(Loc, Ctx, 0); | |||
3655 | A->setImplicit(true); | |||
3656 | return A; | |||
3657 | } | |||
3658 | ||||
3659 | IBActionAttr(SourceRange R, ASTContext &Ctx | |||
3660 | , unsigned SI | |||
3661 | ) | |||
3662 | : InheritableAttr(attr::IBAction, R, SI, false, false) | |||
3663 | { | |||
3664 | } | |||
3665 | ||||
3666 | IBActionAttr *clone(ASTContext &C) const; | |||
3667 | void printPretty(raw_ostream &OS, | |||
3668 | const PrintingPolicy &Policy) const; | |||
3669 | const char *getSpelling() const; | |||
3670 | ||||
3671 | ||||
3672 | static bool classof(const Attr *A) { return A->getKind() == attr::IBAction; } | |||
3673 | }; | |||
3674 | ||||
3675 | class IBOutletAttr : public InheritableAttr { | |||
3676 | public: | |||
3677 | static IBOutletAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3678 | auto *A = new (Ctx) IBOutletAttr(Loc, Ctx, 0); | |||
3679 | A->setImplicit(true); | |||
3680 | return A; | |||
3681 | } | |||
3682 | ||||
3683 | IBOutletAttr(SourceRange R, ASTContext &Ctx | |||
3684 | , unsigned SI | |||
3685 | ) | |||
3686 | : InheritableAttr(attr::IBOutlet, R, SI, false, false) | |||
3687 | { | |||
3688 | } | |||
3689 | ||||
3690 | IBOutletAttr *clone(ASTContext &C) const; | |||
3691 | void printPretty(raw_ostream &OS, | |||
3692 | const PrintingPolicy &Policy) const; | |||
3693 | const char *getSpelling() const; | |||
3694 | ||||
3695 | ||||
3696 | static bool classof(const Attr *A) { return A->getKind() == attr::IBOutlet; } | |||
3697 | }; | |||
3698 | ||||
3699 | class IBOutletCollectionAttr : public InheritableAttr { | |||
3700 | TypeSourceInfo * interface_; | |||
3701 | ||||
3702 | public: | |||
3703 | static IBOutletCollectionAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * Interface, SourceRange Loc = SourceRange()) { | |||
3704 | auto *A = new (Ctx) IBOutletCollectionAttr(Loc, Ctx, Interface, 0); | |||
3705 | A->setImplicit(true); | |||
3706 | return A; | |||
3707 | } | |||
3708 | ||||
3709 | IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx | |||
3710 | , TypeSourceInfo * Interface | |||
3711 | , unsigned SI | |||
3712 | ) | |||
3713 | : InheritableAttr(attr::IBOutletCollection, R, SI, false, false) | |||
3714 | , interface_(Interface) | |||
3715 | { | |||
3716 | } | |||
3717 | ||||
3718 | IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx | |||
3719 | , unsigned SI | |||
3720 | ) | |||
3721 | : InheritableAttr(attr::IBOutletCollection, R, SI, false, false) | |||
3722 | , interface_() | |||
3723 | { | |||
3724 | } | |||
3725 | ||||
3726 | IBOutletCollectionAttr *clone(ASTContext &C) const; | |||
3727 | void printPretty(raw_ostream &OS, | |||
3728 | const PrintingPolicy &Policy) const; | |||
3729 | const char *getSpelling() const; | |||
3730 | QualType getInterface() const { | |||
3731 | return interface_->getType(); | |||
3732 | } TypeSourceInfo * getInterfaceLoc() const { | |||
3733 | return interface_; | |||
3734 | } | |||
3735 | ||||
3736 | ||||
3737 | ||||
3738 | static bool classof(const Attr *A) { return A->getKind() == attr::IBOutletCollection; } | |||
3739 | }; | |||
3740 | ||||
3741 | class IFuncAttr : public Attr { | |||
3742 | unsigned resolverLength; | |||
3743 | char *resolver; | |||
3744 | ||||
3745 | public: | |||
3746 | static IFuncAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Resolver, SourceRange Loc = SourceRange()) { | |||
3747 | auto *A = new (Ctx) IFuncAttr(Loc, Ctx, Resolver, 0); | |||
3748 | A->setImplicit(true); | |||
3749 | return A; | |||
3750 | } | |||
3751 | ||||
3752 | IFuncAttr(SourceRange R, ASTContext &Ctx | |||
3753 | , llvm::StringRef Resolver | |||
3754 | , unsigned SI | |||
3755 | ) | |||
3756 | : Attr(attr::IFunc, R, SI, false) | |||
3757 | , resolverLength(Resolver.size()),resolver(new (Ctx, 1) char[resolverLength]) | |||
3758 | { | |||
3759 | if (!Resolver.empty()) | |||
3760 | std::memcpy(resolver, Resolver.data(), resolverLength); | |||
3761 | } | |||
3762 | ||||
3763 | IFuncAttr *clone(ASTContext &C) const; | |||
3764 | void printPretty(raw_ostream &OS, | |||
3765 | const PrintingPolicy &Policy) const; | |||
3766 | const char *getSpelling() const; | |||
3767 | llvm::StringRef getResolver() const { | |||
3768 | return llvm::StringRef(resolver, resolverLength); | |||
3769 | } | |||
3770 | unsigned getResolverLength() const { | |||
3771 | return resolverLength; | |||
3772 | } | |||
3773 | void setResolver(ASTContext &C, llvm::StringRef S) { | |||
3774 | resolverLength = S.size(); | |||
3775 | this->resolver = new (C, 1) char [resolverLength]; | |||
3776 | if (!S.empty()) | |||
3777 | std::memcpy(this->resolver, S.data(), resolverLength); | |||
3778 | } | |||
3779 | ||||
3780 | ||||
3781 | ||||
3782 | static bool classof(const Attr *A) { return A->getKind() == attr::IFunc; } | |||
3783 | }; | |||
3784 | ||||
3785 | class InitPriorityAttr : public InheritableAttr { | |||
3786 | unsigned priority; | |||
3787 | ||||
3788 | public: | |||
3789 | static InitPriorityAttr *CreateImplicit(ASTContext &Ctx, unsigned Priority, SourceRange Loc = SourceRange()) { | |||
3790 | auto *A = new (Ctx) InitPriorityAttr(Loc, Ctx, Priority, 0); | |||
3791 | A->setImplicit(true); | |||
3792 | return A; | |||
3793 | } | |||
3794 | ||||
3795 | InitPriorityAttr(SourceRange R, ASTContext &Ctx | |||
3796 | , unsigned Priority | |||
3797 | , unsigned SI | |||
3798 | ) | |||
3799 | : InheritableAttr(attr::InitPriority, R, SI, false, false) | |||
3800 | , priority(Priority) | |||
3801 | { | |||
3802 | } | |||
3803 | ||||
3804 | InitPriorityAttr *clone(ASTContext &C) const; | |||
3805 | void printPretty(raw_ostream &OS, | |||
3806 | const PrintingPolicy &Policy) const; | |||
3807 | const char *getSpelling() const; | |||
3808 | unsigned getPriority() const { | |||
3809 | return priority; | |||
3810 | } | |||
3811 | ||||
3812 | ||||
3813 | ||||
3814 | static bool classof(const Attr *A) { return A->getKind() == attr::InitPriority; } | |||
3815 | }; | |||
3816 | ||||
3817 | class InitSegAttr : public Attr { | |||
3818 | unsigned sectionLength; | |||
3819 | char *section; | |||
3820 | ||||
3821 | public: | |||
3822 | static InitSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Section, SourceRange Loc = SourceRange()) { | |||
3823 | auto *A = new (Ctx) InitSegAttr(Loc, Ctx, Section, 0); | |||
3824 | A->setImplicit(true); | |||
3825 | return A; | |||
3826 | } | |||
3827 | ||||
3828 | InitSegAttr(SourceRange R, ASTContext &Ctx | |||
3829 | , llvm::StringRef Section | |||
3830 | , unsigned SI | |||
3831 | ) | |||
3832 | : Attr(attr::InitSeg, R, SI, false) | |||
3833 | , sectionLength(Section.size()),section(new (Ctx, 1) char[sectionLength]) | |||
3834 | { | |||
3835 | if (!Section.empty()) | |||
3836 | std::memcpy(section, Section.data(), sectionLength); | |||
3837 | } | |||
3838 | ||||
3839 | InitSegAttr *clone(ASTContext &C) const; | |||
3840 | void printPretty(raw_ostream &OS, | |||
3841 | const PrintingPolicy &Policy) const; | |||
3842 | const char *getSpelling() const; | |||
3843 | llvm::StringRef getSection() const { | |||
3844 | return llvm::StringRef(section, sectionLength); | |||
3845 | } | |||
3846 | unsigned getSectionLength() const { | |||
3847 | return sectionLength; | |||
3848 | } | |||
3849 | void setSection(ASTContext &C, llvm::StringRef S) { | |||
3850 | sectionLength = S.size(); | |||
3851 | this->section = new (C, 1) char [sectionLength]; | |||
3852 | if (!S.empty()) | |||
3853 | std::memcpy(this->section, S.data(), sectionLength); | |||
3854 | } | |||
3855 | ||||
3856 | ||||
3857 | void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const { | |||
3858 | OS << " (" << getSection() << ')'; | |||
3859 | } | |||
3860 | ||||
3861 | ||||
3862 | static bool classof(const Attr *A) { return A->getKind() == attr::InitSeg; } | |||
3863 | }; | |||
3864 | ||||
3865 | class IntelOclBiccAttr : public InheritableAttr { | |||
3866 | public: | |||
3867 | static IntelOclBiccAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3868 | auto *A = new (Ctx) IntelOclBiccAttr(Loc, Ctx, 0); | |||
3869 | A->setImplicit(true); | |||
3870 | return A; | |||
3871 | } | |||
3872 | ||||
3873 | IntelOclBiccAttr(SourceRange R, ASTContext &Ctx | |||
3874 | , unsigned SI | |||
3875 | ) | |||
3876 | : InheritableAttr(attr::IntelOclBicc, R, SI, false, false) | |||
3877 | { | |||
3878 | } | |||
3879 | ||||
3880 | IntelOclBiccAttr *clone(ASTContext &C) const; | |||
3881 | void printPretty(raw_ostream &OS, | |||
3882 | const PrintingPolicy &Policy) const; | |||
3883 | const char *getSpelling() const; | |||
3884 | ||||
3885 | ||||
3886 | static bool classof(const Attr *A) { return A->getKind() == attr::IntelOclBicc; } | |||
3887 | }; | |||
3888 | ||||
3889 | class InternalLinkageAttr : public InheritableAttr { | |||
3890 | public: | |||
3891 | static InternalLinkageAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3892 | auto *A = new (Ctx) InternalLinkageAttr(Loc, Ctx, 0); | |||
3893 | A->setImplicit(true); | |||
3894 | return A; | |||
3895 | } | |||
3896 | ||||
3897 | InternalLinkageAttr(SourceRange R, ASTContext &Ctx | |||
3898 | , unsigned SI | |||
3899 | ) | |||
3900 | : InheritableAttr(attr::InternalLinkage, R, SI, false, false) | |||
3901 | { | |||
3902 | } | |||
3903 | ||||
3904 | InternalLinkageAttr *clone(ASTContext &C) const; | |||
3905 | void printPretty(raw_ostream &OS, | |||
3906 | const PrintingPolicy &Policy) const; | |||
3907 | const char *getSpelling() const; | |||
3908 | ||||
3909 | ||||
3910 | static bool classof(const Attr *A) { return A->getKind() == attr::InternalLinkage; } | |||
3911 | }; | |||
3912 | ||||
3913 | class LTOVisibilityPublicAttr : public InheritableAttr { | |||
3914 | public: | |||
3915 | static LTOVisibilityPublicAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3916 | auto *A = new (Ctx) LTOVisibilityPublicAttr(Loc, Ctx, 0); | |||
3917 | A->setImplicit(true); | |||
3918 | return A; | |||
3919 | } | |||
3920 | ||||
3921 | LTOVisibilityPublicAttr(SourceRange R, ASTContext &Ctx | |||
3922 | , unsigned SI | |||
3923 | ) | |||
3924 | : InheritableAttr(attr::LTOVisibilityPublic, R, SI, false, false) | |||
3925 | { | |||
3926 | } | |||
3927 | ||||
3928 | LTOVisibilityPublicAttr *clone(ASTContext &C) const; | |||
3929 | void printPretty(raw_ostream &OS, | |||
3930 | const PrintingPolicy &Policy) const; | |||
3931 | const char *getSpelling() const; | |||
3932 | ||||
3933 | ||||
3934 | static bool classof(const Attr *A) { return A->getKind() == attr::LTOVisibilityPublic; } | |||
3935 | }; | |||
3936 | ||||
3937 | class LayoutVersionAttr : public InheritableAttr { | |||
3938 | unsigned version; | |||
3939 | ||||
3940 | public: | |||
3941 | static LayoutVersionAttr *CreateImplicit(ASTContext &Ctx, unsigned Version, SourceRange Loc = SourceRange()) { | |||
3942 | auto *A = new (Ctx) LayoutVersionAttr(Loc, Ctx, Version, 0); | |||
3943 | A->setImplicit(true); | |||
3944 | return A; | |||
3945 | } | |||
3946 | ||||
3947 | LayoutVersionAttr(SourceRange R, ASTContext &Ctx | |||
3948 | , unsigned Version | |||
3949 | , unsigned SI | |||
3950 | ) | |||
3951 | : InheritableAttr(attr::LayoutVersion, R, SI, false, false) | |||
3952 | , version(Version) | |||
3953 | { | |||
3954 | } | |||
3955 | ||||
3956 | LayoutVersionAttr *clone(ASTContext &C) const; | |||
3957 | void printPretty(raw_ostream &OS, | |||
3958 | const PrintingPolicy &Policy) const; | |||
3959 | const char *getSpelling() const; | |||
3960 | unsigned getVersion() const { | |||
3961 | return version; | |||
3962 | } | |||
3963 | ||||
3964 | ||||
3965 | ||||
3966 | static bool classof(const Attr *A) { return A->getKind() == attr::LayoutVersion; } | |||
3967 | }; | |||
3968 | ||||
3969 | class LifetimeBoundAttr : public InheritableAttr { | |||
3970 | public: | |||
3971 | static LifetimeBoundAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
3972 | auto *A = new (Ctx) LifetimeBoundAttr(Loc, Ctx, 0); | |||
3973 | A->setImplicit(true); | |||
3974 | return A; | |||
3975 | } | |||
3976 | ||||
3977 | LifetimeBoundAttr(SourceRange R, ASTContext &Ctx | |||
3978 | , unsigned SI | |||
3979 | ) | |||
3980 | : InheritableAttr(attr::LifetimeBound, R, SI, false, false) | |||
3981 | { | |||
3982 | } | |||
3983 | ||||
3984 | LifetimeBoundAttr *clone(ASTContext &C) const; | |||
3985 | void printPretty(raw_ostream &OS, | |||
3986 | const PrintingPolicy &Policy) const; | |||
3987 | const char *getSpelling() const; | |||
3988 | ||||
3989 | ||||
3990 | static bool classof(const Attr *A) { return A->getKind() == attr::LifetimeBound; } | |||
3991 | }; | |||
3992 | ||||
3993 | class LockReturnedAttr : public InheritableAttr { | |||
3994 | Expr * arg; | |||
3995 | ||||
3996 | public: | |||
3997 | static LockReturnedAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) { | |||
3998 | auto *A = new (Ctx) LockReturnedAttr(Loc, Ctx, Arg, 0); | |||
3999 | A->setImplicit(true); | |||
4000 | return A; | |||
4001 | } | |||
4002 | ||||
4003 | LockReturnedAttr(SourceRange R, ASTContext &Ctx | |||
4004 | , Expr * Arg | |||
4005 | , unsigned SI | |||
4006 | ) | |||
4007 | : InheritableAttr(attr::LockReturned, R, SI, true, false) | |||
4008 | , arg(Arg) | |||
4009 | { | |||
4010 | } | |||
4011 | ||||
4012 | LockReturnedAttr *clone(ASTContext &C) const; | |||
4013 | void printPretty(raw_ostream &OS, | |||
4014 | const PrintingPolicy &Policy) const; | |||
4015 | const char *getSpelling() const; | |||
4016 | Expr * getArg() const { | |||
4017 | return arg; | |||
4018 | } | |||
4019 | ||||
4020 | ||||
4021 | ||||
4022 | static bool classof(const Attr *A) { return A->getKind() == attr::LockReturned; } | |||
4023 | }; | |||
4024 | ||||
4025 | class LocksExcludedAttr : public InheritableAttr { | |||
4026 | unsigned args_Size; | |||
4027 | Expr * *args_; | |||
4028 | ||||
4029 | public: | |||
4030 | static LocksExcludedAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
4031 | auto *A = new (Ctx) LocksExcludedAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
4032 | A->setImplicit(true); | |||
4033 | return A; | |||
4034 | } | |||
4035 | ||||
4036 | LocksExcludedAttr(SourceRange R, ASTContext &Ctx | |||
4037 | , Expr * *Args, unsigned ArgsSize | |||
4038 | , unsigned SI | |||
4039 | ) | |||
4040 | : InheritableAttr(attr::LocksExcluded, R, SI, true, true) | |||
4041 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
4042 | { | |||
4043 | std::copy(Args, Args + args_Size, args_); | |||
4044 | } | |||
4045 | ||||
4046 | LocksExcludedAttr(SourceRange R, ASTContext &Ctx | |||
4047 | , unsigned SI | |||
4048 | ) | |||
4049 | : InheritableAttr(attr::LocksExcluded, R, SI, true, true) | |||
4050 | , args_Size(0), args_(nullptr) | |||
4051 | { | |||
4052 | } | |||
4053 | ||||
4054 | LocksExcludedAttr *clone(ASTContext &C) const; | |||
4055 | void printPretty(raw_ostream &OS, | |||
4056 | const PrintingPolicy &Policy) const; | |||
4057 | const char *getSpelling() const; | |||
4058 | typedef Expr ** args_iterator; | |||
4059 | args_iterator args_begin() const { return args_; } | |||
4060 | args_iterator args_end() const { return args_ + args_Size; } | |||
4061 | unsigned args_size() const { return args_Size; } | |||
4062 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
4063 | ||||
4064 | ||||
4065 | ||||
4066 | ||||
4067 | static bool classof(const Attr *A) { return A->getKind() == attr::LocksExcluded; } | |||
4068 | }; | |||
4069 | ||||
4070 | class LoopHintAttr : public Attr { | |||
4071 | public: | |||
4072 | enum OptionType { | |||
4073 | Vectorize, | |||
4074 | VectorizeWidth, | |||
4075 | Interleave, | |||
4076 | InterleaveCount, | |||
4077 | Unroll, | |||
4078 | UnrollCount, | |||
4079 | UnrollAndJam, | |||
4080 | UnrollAndJamCount, | |||
4081 | PipelineDisabled, | |||
4082 | PipelineInitiationInterval, | |||
4083 | Distribute | |||
4084 | }; | |||
4085 | private: | |||
4086 | OptionType option; | |||
4087 | ||||
4088 | public: | |||
4089 | enum LoopHintState { | |||
4090 | Enable, | |||
4091 | Disable, | |||
4092 | Numeric, | |||
4093 | AssumeSafety, | |||
4094 | Full | |||
4095 | }; | |||
4096 | private: | |||
4097 | LoopHintState state; | |||
4098 | ||||
4099 | Expr * value; | |||
4100 | ||||
4101 | public: | |||
4102 | enum Spelling { | |||
4103 | Pragma_clang_loop = 0, | |||
4104 | Pragma_unroll = 1, | |||
4105 | Pragma_nounroll = 2, | |||
4106 | Pragma_unroll_and_jam = 3, | |||
4107 | Pragma_nounroll_and_jam = 4 | |||
4108 | }; | |||
4109 | ||||
4110 | static LoopHintAttr *CreateImplicit(ASTContext &Ctx, Spelling S, OptionType Option, LoopHintState State, Expr * Value, SourceRange Loc = SourceRange()) { | |||
4111 | auto *A = new (Ctx) LoopHintAttr(Loc, Ctx, Option, State, Value, S); | |||
4112 | A->setImplicit(true); | |||
4113 | return A; | |||
4114 | } | |||
4115 | ||||
4116 | LoopHintAttr(SourceRange R, ASTContext &Ctx | |||
4117 | , OptionType Option | |||
4118 | , LoopHintState State | |||
4119 | , Expr * Value | |||
4120 | , unsigned SI | |||
4121 | ) | |||
4122 | : Attr(attr::LoopHint, R, SI, false) | |||
4123 | , option(Option) | |||
4124 | , state(State) | |||
4125 | , value(Value) | |||
4126 | { | |||
4127 | } | |||
4128 | ||||
4129 | LoopHintAttr *clone(ASTContext &C) const; | |||
4130 | void printPretty(raw_ostream &OS, | |||
4131 | const PrintingPolicy &Policy) const; | |||
4132 | const char *getSpelling() const; | |||
4133 | Spelling getSemanticSpelling() const { | |||
4134 | switch (SpellingListIndex) { | |||
4135 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4135); | |||
4136 | case 0: return Pragma_clang_loop; | |||
4137 | case 1: return Pragma_unroll; | |||
4138 | case 2: return Pragma_nounroll; | |||
4139 | case 3: return Pragma_unroll_and_jam; | |||
4140 | case 4: return Pragma_nounroll_and_jam; | |||
4141 | } | |||
4142 | } | |||
4143 | OptionType getOption() const { | |||
4144 | return option; | |||
4145 | } | |||
4146 | ||||
4147 | static bool ConvertStrToOptionType(StringRef Val, OptionType &Out) { | |||
4148 | Optional<OptionType> R = llvm::StringSwitch<Optional<OptionType>>(Val) | |||
4149 | .Case("vectorize", LoopHintAttr::Vectorize) | |||
4150 | .Case("vectorize_width", LoopHintAttr::VectorizeWidth) | |||
4151 | .Case("interleave", LoopHintAttr::Interleave) | |||
4152 | .Case("interleave_count", LoopHintAttr::InterleaveCount) | |||
4153 | .Case("unroll", LoopHintAttr::Unroll) | |||
4154 | .Case("unroll_count", LoopHintAttr::UnrollCount) | |||
4155 | .Case("unroll_and_jam", LoopHintAttr::UnrollAndJam) | |||
4156 | .Case("unroll_and_jam_count", LoopHintAttr::UnrollAndJamCount) | |||
4157 | .Case("pipeline", LoopHintAttr::PipelineDisabled) | |||
4158 | .Case("pipeline_initiation_interval", LoopHintAttr::PipelineInitiationInterval) | |||
4159 | .Case("distribute", LoopHintAttr::Distribute) | |||
4160 | .Default(Optional<OptionType>()); | |||
4161 | if (R) { | |||
4162 | Out = *R; | |||
4163 | return true; | |||
4164 | } | |||
4165 | return false; | |||
4166 | } | |||
4167 | ||||
4168 | static const char *ConvertOptionTypeToStr(OptionType Val) { | |||
4169 | switch(Val) { | |||
4170 | case LoopHintAttr::Vectorize: return "vectorize"; | |||
4171 | case LoopHintAttr::VectorizeWidth: return "vectorize_width"; | |||
4172 | case LoopHintAttr::Interleave: return "interleave"; | |||
4173 | case LoopHintAttr::InterleaveCount: return "interleave_count"; | |||
4174 | case LoopHintAttr::Unroll: return "unroll"; | |||
4175 | case LoopHintAttr::UnrollCount: return "unroll_count"; | |||
4176 | case LoopHintAttr::UnrollAndJam: return "unroll_and_jam"; | |||
4177 | case LoopHintAttr::UnrollAndJamCount: return "unroll_and_jam_count"; | |||
4178 | case LoopHintAttr::PipelineDisabled: return "pipeline"; | |||
4179 | case LoopHintAttr::PipelineInitiationInterval: return "pipeline_initiation_interval"; | |||
4180 | case LoopHintAttr::Distribute: return "distribute"; | |||
4181 | } | |||
4182 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4182); | |||
4183 | } | |||
4184 | LoopHintState getState() const { | |||
4185 | return state; | |||
4186 | } | |||
4187 | ||||
4188 | static bool ConvertStrToLoopHintState(StringRef Val, LoopHintState &Out) { | |||
4189 | Optional<LoopHintState> R = llvm::StringSwitch<Optional<LoopHintState>>(Val) | |||
4190 | .Case("enable", LoopHintAttr::Enable) | |||
4191 | .Case("disable", LoopHintAttr::Disable) | |||
4192 | .Case("numeric", LoopHintAttr::Numeric) | |||
4193 | .Case("assume_safety", LoopHintAttr::AssumeSafety) | |||
4194 | .Case("full", LoopHintAttr::Full) | |||
4195 | .Default(Optional<LoopHintState>()); | |||
4196 | if (R) { | |||
4197 | Out = *R; | |||
4198 | return true; | |||
4199 | } | |||
4200 | return false; | |||
4201 | } | |||
4202 | ||||
4203 | static const char *ConvertLoopHintStateToStr(LoopHintState Val) { | |||
4204 | switch(Val) { | |||
4205 | case LoopHintAttr::Enable: return "enable"; | |||
4206 | case LoopHintAttr::Disable: return "disable"; | |||
4207 | case LoopHintAttr::Numeric: return "numeric"; | |||
4208 | case LoopHintAttr::AssumeSafety: return "assume_safety"; | |||
4209 | case LoopHintAttr::Full: return "full"; | |||
4210 | } | |||
4211 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4211); | |||
4212 | } | |||
4213 | Expr * getValue() const { | |||
4214 | return value; | |||
4215 | } | |||
4216 | ||||
4217 | ||||
4218 | static const char *getOptionName(int Option) { | |||
4219 | switch(Option) { | |||
4220 | case Vectorize: return "vectorize"; | |||
4221 | case VectorizeWidth: return "vectorize_width"; | |||
4222 | case Interleave: return "interleave"; | |||
4223 | case InterleaveCount: return "interleave_count"; | |||
4224 | case Unroll: return "unroll"; | |||
4225 | case UnrollCount: return "unroll_count"; | |||
4226 | case UnrollAndJam: return "unroll_and_jam"; | |||
4227 | case UnrollAndJamCount: return "unroll_and_jam_count"; | |||
4228 | case PipelineDisabled: return "pipeline"; | |||
4229 | case PipelineInitiationInterval: return "pipeline_initiation_interval"; | |||
4230 | case Distribute: return "distribute"; | |||
4231 | } | |||
4232 | llvm_unreachable("Unhandled LoopHint option.")::llvm::llvm_unreachable_internal("Unhandled LoopHint option." , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4232); | |||
4233 | } | |||
4234 | ||||
4235 | void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const { | |||
4236 | unsigned SpellingIndex = getSpellingListIndex(); | |||
4237 | // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or | |||
4238 | // "nounroll" is already emitted as the pragma name. | |||
4239 | if (SpellingIndex == Pragma_nounroll || SpellingIndex == Pragma_nounroll_and_jam) | |||
4240 | return; | |||
4241 | else if (SpellingIndex == Pragma_unroll || SpellingIndex == Pragma_unroll_and_jam) { | |||
4242 | OS << ' ' << getValueString(Policy); | |||
4243 | return; | |||
4244 | } | |||
4245 | ||||
4246 | assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling")((SpellingIndex == Pragma_clang_loop && "Unexpected spelling" ) ? static_cast<void> (0) : __assert_fail ("SpellingIndex == Pragma_clang_loop && \"Unexpected spelling\"" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4246, __PRETTY_FUNCTION__)); | |||
4247 | OS << ' ' << getOptionName(option) << getValueString(Policy); | |||
4248 | } | |||
4249 | ||||
4250 | // Return a string containing the loop hint argument including the | |||
4251 | // enclosing parentheses. | |||
4252 | std::string getValueString(const PrintingPolicy &Policy) const { | |||
4253 | std::string ValueName; | |||
4254 | llvm::raw_string_ostream OS(ValueName); | |||
4255 | OS << "("; | |||
4256 | if (state == Numeric) | |||
4257 | value->printPretty(OS, nullptr, Policy); | |||
4258 | else if (state == Enable) | |||
4259 | OS << "enable"; | |||
4260 | else if (state == Full) | |||
4261 | OS << "full"; | |||
4262 | else if (state == AssumeSafety) | |||
4263 | OS << "assume_safety"; | |||
4264 | else | |||
4265 | OS << "disable"; | |||
4266 | OS << ")"; | |||
4267 | return OS.str(); | |||
4268 | } | |||
4269 | ||||
4270 | // Return a string suitable for identifying this attribute in diagnostics. | |||
4271 | std::string getDiagnosticName(const PrintingPolicy &Policy) const { | |||
4272 | unsigned SpellingIndex = getSpellingListIndex(); | |||
4273 | if (SpellingIndex == Pragma_nounroll) | |||
4274 | return "#pragma nounroll"; | |||
4275 | else if (SpellingIndex == Pragma_unroll) | |||
4276 | return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : ""); | |||
4277 | else if (SpellingIndex == Pragma_nounroll_and_jam) | |||
4278 | return "#pragma nounroll_and_jam"; | |||
4279 | else if (SpellingIndex == Pragma_unroll_and_jam) | |||
4280 | return "#pragma unroll_and_jam" + | |||
4281 | (option == UnrollAndJamCount ? getValueString(Policy) : ""); | |||
4282 | ||||
4283 | assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling")((SpellingIndex == Pragma_clang_loop && "Unexpected spelling" ) ? static_cast<void> (0) : __assert_fail ("SpellingIndex == Pragma_clang_loop && \"Unexpected spelling\"" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4283, __PRETTY_FUNCTION__)); | |||
4284 | return getOptionName(option) + getValueString(Policy); | |||
4285 | } | |||
4286 | ||||
4287 | ||||
4288 | static bool classof(const Attr *A) { return A->getKind() == attr::LoopHint; } | |||
4289 | }; | |||
4290 | ||||
4291 | class MIGServerRoutineAttr : public InheritableAttr { | |||
4292 | public: | |||
4293 | static MIGServerRoutineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4294 | auto *A = new (Ctx) MIGServerRoutineAttr(Loc, Ctx, 0); | |||
4295 | A->setImplicit(true); | |||
4296 | return A; | |||
4297 | } | |||
4298 | ||||
4299 | MIGServerRoutineAttr(SourceRange R, ASTContext &Ctx | |||
4300 | , unsigned SI | |||
4301 | ) | |||
4302 | : InheritableAttr(attr::MIGServerRoutine, R, SI, false, false) | |||
4303 | { | |||
4304 | } | |||
4305 | ||||
4306 | MIGServerRoutineAttr *clone(ASTContext &C) const; | |||
4307 | void printPretty(raw_ostream &OS, | |||
4308 | const PrintingPolicy &Policy) const; | |||
4309 | const char *getSpelling() const; | |||
4310 | ||||
4311 | ||||
4312 | static bool classof(const Attr *A) { return A->getKind() == attr::MIGServerRoutine; } | |||
4313 | }; | |||
4314 | ||||
4315 | class MSABIAttr : public InheritableAttr { | |||
4316 | public: | |||
4317 | static MSABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4318 | auto *A = new (Ctx) MSABIAttr(Loc, Ctx, 0); | |||
4319 | A->setImplicit(true); | |||
4320 | return A; | |||
4321 | } | |||
4322 | ||||
4323 | MSABIAttr(SourceRange R, ASTContext &Ctx | |||
4324 | , unsigned SI | |||
4325 | ) | |||
4326 | : InheritableAttr(attr::MSABI, R, SI, false, false) | |||
4327 | { | |||
4328 | } | |||
4329 | ||||
4330 | MSABIAttr *clone(ASTContext &C) const; | |||
4331 | void printPretty(raw_ostream &OS, | |||
4332 | const PrintingPolicy &Policy) const; | |||
4333 | const char *getSpelling() const; | |||
4334 | ||||
4335 | ||||
4336 | static bool classof(const Attr *A) { return A->getKind() == attr::MSABI; } | |||
4337 | }; | |||
4338 | ||||
4339 | class MSAllocatorAttr : public InheritableAttr { | |||
4340 | public: | |||
4341 | static MSAllocatorAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4342 | auto *A = new (Ctx) MSAllocatorAttr(Loc, Ctx, 0); | |||
4343 | A->setImplicit(true); | |||
4344 | return A; | |||
4345 | } | |||
4346 | ||||
4347 | MSAllocatorAttr(SourceRange R, ASTContext &Ctx | |||
4348 | , unsigned SI | |||
4349 | ) | |||
4350 | : InheritableAttr(attr::MSAllocator, R, SI, false, false) | |||
4351 | { | |||
4352 | } | |||
4353 | ||||
4354 | MSAllocatorAttr *clone(ASTContext &C) const; | |||
4355 | void printPretty(raw_ostream &OS, | |||
4356 | const PrintingPolicy &Policy) const; | |||
4357 | const char *getSpelling() const; | |||
4358 | ||||
4359 | ||||
4360 | static bool classof(const Attr *A) { return A->getKind() == attr::MSAllocator; } | |||
4361 | }; | |||
4362 | ||||
4363 | class MSInheritanceAttr : public InheritableAttr { | |||
4364 | bool bestCase; | |||
4365 | ||||
4366 | public: | |||
4367 | enum Spelling { | |||
4368 | Keyword_single_inheritance = 0, | |||
4369 | Keyword_multiple_inheritance = 1, | |||
4370 | Keyword_virtual_inheritance = 2, | |||
4371 | Keyword_unspecified_inheritance = 3 | |||
4372 | }; | |||
4373 | ||||
4374 | static MSInheritanceAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool BestCase, SourceRange Loc = SourceRange()) { | |||
4375 | auto *A = new (Ctx) MSInheritanceAttr(Loc, Ctx, BestCase, S); | |||
4376 | A->setImplicit(true); | |||
4377 | return A; | |||
4378 | } | |||
4379 | ||||
4380 | static MSInheritanceAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
4381 | auto *A = new (Ctx) MSInheritanceAttr(Loc, Ctx, S); | |||
4382 | A->setImplicit(true); | |||
4383 | return A; | |||
4384 | } | |||
4385 | ||||
4386 | MSInheritanceAttr(SourceRange R, ASTContext &Ctx | |||
4387 | , bool BestCase | |||
4388 | , unsigned SI | |||
4389 | ) | |||
4390 | : InheritableAttr(attr::MSInheritance, R, SI, false, false) | |||
4391 | , bestCase(BestCase) | |||
4392 | { | |||
4393 | } | |||
4394 | ||||
4395 | MSInheritanceAttr(SourceRange R, ASTContext &Ctx | |||
4396 | , unsigned SI | |||
4397 | ) | |||
4398 | : InheritableAttr(attr::MSInheritance, R, SI, false, false) | |||
4399 | , bestCase() | |||
4400 | { | |||
4401 | } | |||
4402 | ||||
4403 | MSInheritanceAttr *clone(ASTContext &C) const; | |||
4404 | void printPretty(raw_ostream &OS, | |||
4405 | const PrintingPolicy &Policy) const; | |||
4406 | const char *getSpelling() const; | |||
4407 | Spelling getSemanticSpelling() const { | |||
4408 | switch (SpellingListIndex) { | |||
4409 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4409); | |||
4410 | case 0: return Keyword_single_inheritance; | |||
4411 | case 1: return Keyword_multiple_inheritance; | |||
4412 | case 2: return Keyword_virtual_inheritance; | |||
4413 | case 3: return Keyword_unspecified_inheritance; | |||
4414 | } | |||
4415 | } | |||
4416 | bool getBestCase() const { | |||
4417 | return bestCase; | |||
4418 | } | |||
4419 | ||||
4420 | static const bool DefaultBestCase = true; | |||
4421 | ||||
4422 | ||||
4423 | static bool hasVBPtrOffsetField(Spelling Inheritance) { | |||
4424 | return Inheritance == Keyword_unspecified_inheritance; | |||
4425 | } | |||
4426 | ||||
4427 | // Only member pointers to functions need a this adjustment, since it can be | |||
4428 | // combined with the field offset for data pointers. | |||
4429 | static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) { | |||
4430 | return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance; | |||
4431 | } | |||
4432 | ||||
4433 | static bool hasVBTableOffsetField(Spelling Inheritance) { | |||
4434 | return Inheritance >= Keyword_virtual_inheritance; | |||
4435 | } | |||
4436 | ||||
4437 | static bool hasOnlyOneField(bool IsMemberFunction, | |||
4438 | Spelling Inheritance) { | |||
4439 | if (IsMemberFunction) | |||
4440 | return Inheritance <= Keyword_single_inheritance; | |||
4441 | return Inheritance <= Keyword_multiple_inheritance; | |||
4442 | } | |||
4443 | ||||
4444 | ||||
4445 | static bool classof(const Attr *A) { return A->getKind() == attr::MSInheritance; } | |||
4446 | }; | |||
4447 | ||||
4448 | class MSNoVTableAttr : public InheritableAttr { | |||
4449 | public: | |||
4450 | static MSNoVTableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4451 | auto *A = new (Ctx) MSNoVTableAttr(Loc, Ctx, 0); | |||
4452 | A->setImplicit(true); | |||
4453 | return A; | |||
4454 | } | |||
4455 | ||||
4456 | MSNoVTableAttr(SourceRange R, ASTContext &Ctx | |||
4457 | , unsigned SI | |||
4458 | ) | |||
4459 | : InheritableAttr(attr::MSNoVTable, R, SI, false, false) | |||
4460 | { | |||
4461 | } | |||
4462 | ||||
4463 | MSNoVTableAttr *clone(ASTContext &C) const; | |||
4464 | void printPretty(raw_ostream &OS, | |||
4465 | const PrintingPolicy &Policy) const; | |||
4466 | const char *getSpelling() const; | |||
4467 | ||||
4468 | ||||
4469 | static bool classof(const Attr *A) { return A->getKind() == attr::MSNoVTable; } | |||
4470 | }; | |||
4471 | ||||
4472 | class MSP430InterruptAttr : public InheritableAttr { | |||
4473 | unsigned number; | |||
4474 | ||||
4475 | public: | |||
4476 | static MSP430InterruptAttr *CreateImplicit(ASTContext &Ctx, unsigned Number, SourceRange Loc = SourceRange()) { | |||
4477 | auto *A = new (Ctx) MSP430InterruptAttr(Loc, Ctx, Number, 0); | |||
4478 | A->setImplicit(true); | |||
4479 | return A; | |||
4480 | } | |||
4481 | ||||
4482 | MSP430InterruptAttr(SourceRange R, ASTContext &Ctx | |||
4483 | , unsigned Number | |||
4484 | , unsigned SI | |||
4485 | ) | |||
4486 | : InheritableAttr(attr::MSP430Interrupt, R, SI, false, false) | |||
4487 | , number(Number) | |||
4488 | { | |||
4489 | } | |||
4490 | ||||
4491 | MSP430InterruptAttr *clone(ASTContext &C) const; | |||
4492 | void printPretty(raw_ostream &OS, | |||
4493 | const PrintingPolicy &Policy) const; | |||
4494 | const char *getSpelling() const; | |||
4495 | unsigned getNumber() const { | |||
4496 | return number; | |||
4497 | } | |||
4498 | ||||
4499 | ||||
4500 | ||||
4501 | static bool classof(const Attr *A) { return A->getKind() == attr::MSP430Interrupt; } | |||
4502 | }; | |||
4503 | ||||
4504 | class MSStructAttr : public InheritableAttr { | |||
4505 | public: | |||
4506 | static MSStructAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4507 | auto *A = new (Ctx) MSStructAttr(Loc, Ctx, 0); | |||
4508 | A->setImplicit(true); | |||
4509 | return A; | |||
4510 | } | |||
4511 | ||||
4512 | MSStructAttr(SourceRange R, ASTContext &Ctx | |||
4513 | , unsigned SI | |||
4514 | ) | |||
4515 | : InheritableAttr(attr::MSStruct, R, SI, false, false) | |||
4516 | { | |||
4517 | } | |||
4518 | ||||
4519 | MSStructAttr *clone(ASTContext &C) const; | |||
4520 | void printPretty(raw_ostream &OS, | |||
4521 | const PrintingPolicy &Policy) const; | |||
4522 | const char *getSpelling() const; | |||
4523 | ||||
4524 | ||||
4525 | static bool classof(const Attr *A) { return A->getKind() == attr::MSStruct; } | |||
4526 | }; | |||
4527 | ||||
4528 | class MSVtorDispAttr : public InheritableAttr { | |||
4529 | unsigned vdm; | |||
4530 | ||||
4531 | public: | |||
4532 | static MSVtorDispAttr *CreateImplicit(ASTContext &Ctx, unsigned Vdm, SourceRange Loc = SourceRange()) { | |||
4533 | auto *A = new (Ctx) MSVtorDispAttr(Loc, Ctx, Vdm, 0); | |||
4534 | A->setImplicit(true); | |||
4535 | return A; | |||
4536 | } | |||
4537 | ||||
4538 | MSVtorDispAttr(SourceRange R, ASTContext &Ctx | |||
4539 | , unsigned Vdm | |||
4540 | , unsigned SI | |||
4541 | ) | |||
4542 | : InheritableAttr(attr::MSVtorDisp, R, SI, false, false) | |||
4543 | , vdm(Vdm) | |||
4544 | { | |||
4545 | } | |||
4546 | ||||
4547 | MSVtorDispAttr *clone(ASTContext &C) const; | |||
4548 | void printPretty(raw_ostream &OS, | |||
4549 | const PrintingPolicy &Policy) const; | |||
4550 | const char *getSpelling() const; | |||
4551 | unsigned getVdm() const { | |||
4552 | return vdm; | |||
4553 | } | |||
4554 | ||||
4555 | ||||
4556 | enum Mode { | |||
4557 | Never, | |||
4558 | ForVBaseOverride, | |||
4559 | ForVFTable | |||
4560 | }; | |||
4561 | ||||
4562 | Mode getVtorDispMode() const { return Mode(vdm); } | |||
4563 | ||||
4564 | ||||
4565 | static bool classof(const Attr *A) { return A->getKind() == attr::MSVtorDisp; } | |||
4566 | }; | |||
4567 | ||||
4568 | class MaxFieldAlignmentAttr : public InheritableAttr { | |||
4569 | unsigned alignment; | |||
4570 | ||||
4571 | public: | |||
4572 | static MaxFieldAlignmentAttr *CreateImplicit(ASTContext &Ctx, unsigned Alignment, SourceRange Loc = SourceRange()) { | |||
4573 | auto *A = new (Ctx) MaxFieldAlignmentAttr(Loc, Ctx, Alignment, 0); | |||
4574 | A->setImplicit(true); | |||
4575 | return A; | |||
4576 | } | |||
4577 | ||||
4578 | MaxFieldAlignmentAttr(SourceRange R, ASTContext &Ctx | |||
4579 | , unsigned Alignment | |||
4580 | , unsigned SI | |||
4581 | ) | |||
4582 | : InheritableAttr(attr::MaxFieldAlignment, R, SI, false, false) | |||
4583 | , alignment(Alignment) | |||
4584 | { | |||
4585 | } | |||
4586 | ||||
4587 | MaxFieldAlignmentAttr *clone(ASTContext &C) const; | |||
4588 | void printPretty(raw_ostream &OS, | |||
4589 | const PrintingPolicy &Policy) const; | |||
4590 | const char *getSpelling() const; | |||
4591 | unsigned getAlignment() const { | |||
4592 | return alignment; | |||
4593 | } | |||
4594 | ||||
4595 | ||||
4596 | ||||
4597 | static bool classof(const Attr *A) { return A->getKind() == attr::MaxFieldAlignment; } | |||
4598 | }; | |||
4599 | ||||
4600 | class MayAliasAttr : public InheritableAttr { | |||
4601 | public: | |||
4602 | static MayAliasAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4603 | auto *A = new (Ctx) MayAliasAttr(Loc, Ctx, 0); | |||
4604 | A->setImplicit(true); | |||
4605 | return A; | |||
4606 | } | |||
4607 | ||||
4608 | MayAliasAttr(SourceRange R, ASTContext &Ctx | |||
4609 | , unsigned SI | |||
4610 | ) | |||
4611 | : InheritableAttr(attr::MayAlias, R, SI, false, false) | |||
4612 | { | |||
4613 | } | |||
4614 | ||||
4615 | MayAliasAttr *clone(ASTContext &C) const; | |||
4616 | void printPretty(raw_ostream &OS, | |||
4617 | const PrintingPolicy &Policy) const; | |||
4618 | const char *getSpelling() const; | |||
4619 | ||||
4620 | ||||
4621 | static bool classof(const Attr *A) { return A->getKind() == attr::MayAlias; } | |||
4622 | }; | |||
4623 | ||||
4624 | class MicroMipsAttr : public InheritableAttr { | |||
4625 | public: | |||
4626 | static MicroMipsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4627 | auto *A = new (Ctx) MicroMipsAttr(Loc, Ctx, 0); | |||
4628 | A->setImplicit(true); | |||
4629 | return A; | |||
4630 | } | |||
4631 | ||||
4632 | MicroMipsAttr(SourceRange R, ASTContext &Ctx | |||
4633 | , unsigned SI | |||
4634 | ) | |||
4635 | : InheritableAttr(attr::MicroMips, R, SI, false, false) | |||
4636 | { | |||
4637 | } | |||
4638 | ||||
4639 | MicroMipsAttr *clone(ASTContext &C) const; | |||
4640 | void printPretty(raw_ostream &OS, | |||
4641 | const PrintingPolicy &Policy) const; | |||
4642 | const char *getSpelling() const; | |||
4643 | ||||
4644 | ||||
4645 | static bool classof(const Attr *A) { return A->getKind() == attr::MicroMips; } | |||
4646 | }; | |||
4647 | ||||
4648 | class MinSizeAttr : public InheritableAttr { | |||
4649 | public: | |||
4650 | static MinSizeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4651 | auto *A = new (Ctx) MinSizeAttr(Loc, Ctx, 0); | |||
4652 | A->setImplicit(true); | |||
4653 | return A; | |||
4654 | } | |||
4655 | ||||
4656 | MinSizeAttr(SourceRange R, ASTContext &Ctx | |||
4657 | , unsigned SI | |||
4658 | ) | |||
4659 | : InheritableAttr(attr::MinSize, R, SI, false, false) | |||
4660 | { | |||
4661 | } | |||
4662 | ||||
4663 | MinSizeAttr *clone(ASTContext &C) const; | |||
4664 | void printPretty(raw_ostream &OS, | |||
4665 | const PrintingPolicy &Policy) const; | |||
4666 | const char *getSpelling() const; | |||
4667 | ||||
4668 | ||||
4669 | static bool classof(const Attr *A) { return A->getKind() == attr::MinSize; } | |||
4670 | }; | |||
4671 | ||||
4672 | class MinVectorWidthAttr : public InheritableAttr { | |||
4673 | unsigned vectorWidth; | |||
4674 | ||||
4675 | public: | |||
4676 | static MinVectorWidthAttr *CreateImplicit(ASTContext &Ctx, unsigned VectorWidth, SourceRange Loc = SourceRange()) { | |||
4677 | auto *A = new (Ctx) MinVectorWidthAttr(Loc, Ctx, VectorWidth, 0); | |||
4678 | A->setImplicit(true); | |||
4679 | return A; | |||
4680 | } | |||
4681 | ||||
4682 | MinVectorWidthAttr(SourceRange R, ASTContext &Ctx | |||
4683 | , unsigned VectorWidth | |||
4684 | , unsigned SI | |||
4685 | ) | |||
4686 | : InheritableAttr(attr::MinVectorWidth, R, SI, false, false) | |||
4687 | , vectorWidth(VectorWidth) | |||
4688 | { | |||
4689 | } | |||
4690 | ||||
4691 | MinVectorWidthAttr *clone(ASTContext &C) const; | |||
4692 | void printPretty(raw_ostream &OS, | |||
4693 | const PrintingPolicy &Policy) const; | |||
4694 | const char *getSpelling() const; | |||
4695 | unsigned getVectorWidth() const { | |||
4696 | return vectorWidth; | |||
4697 | } | |||
4698 | ||||
4699 | ||||
4700 | ||||
4701 | static bool classof(const Attr *A) { return A->getKind() == attr::MinVectorWidth; } | |||
4702 | }; | |||
4703 | ||||
4704 | class Mips16Attr : public InheritableAttr { | |||
4705 | public: | |||
4706 | static Mips16Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4707 | auto *A = new (Ctx) Mips16Attr(Loc, Ctx, 0); | |||
4708 | A->setImplicit(true); | |||
4709 | return A; | |||
4710 | } | |||
4711 | ||||
4712 | Mips16Attr(SourceRange R, ASTContext &Ctx | |||
4713 | , unsigned SI | |||
4714 | ) | |||
4715 | : InheritableAttr(attr::Mips16, R, SI, false, false) | |||
4716 | { | |||
4717 | } | |||
4718 | ||||
4719 | Mips16Attr *clone(ASTContext &C) const; | |||
4720 | void printPretty(raw_ostream &OS, | |||
4721 | const PrintingPolicy &Policy) const; | |||
4722 | const char *getSpelling() const; | |||
4723 | ||||
4724 | ||||
4725 | static bool classof(const Attr *A) { return A->getKind() == attr::Mips16; } | |||
4726 | }; | |||
4727 | ||||
4728 | class MipsInterruptAttr : public InheritableAttr { | |||
4729 | public: | |||
4730 | enum InterruptType { | |||
4731 | sw0, | |||
4732 | sw1, | |||
4733 | hw0, | |||
4734 | hw1, | |||
4735 | hw2, | |||
4736 | hw3, | |||
4737 | hw4, | |||
4738 | hw5, | |||
4739 | eic | |||
4740 | }; | |||
4741 | private: | |||
4742 | InterruptType interrupt; | |||
4743 | ||||
4744 | public: | |||
4745 | static MipsInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) { | |||
4746 | auto *A = new (Ctx) MipsInterruptAttr(Loc, Ctx, Interrupt, 0); | |||
4747 | A->setImplicit(true); | |||
4748 | return A; | |||
4749 | } | |||
4750 | ||||
4751 | MipsInterruptAttr(SourceRange R, ASTContext &Ctx | |||
4752 | , InterruptType Interrupt | |||
4753 | , unsigned SI | |||
4754 | ) | |||
4755 | : InheritableAttr(attr::MipsInterrupt, R, SI, false, false) | |||
4756 | , interrupt(Interrupt) | |||
4757 | { | |||
4758 | } | |||
4759 | ||||
4760 | MipsInterruptAttr *clone(ASTContext &C) const; | |||
4761 | void printPretty(raw_ostream &OS, | |||
4762 | const PrintingPolicy &Policy) const; | |||
4763 | const char *getSpelling() const; | |||
4764 | InterruptType getInterrupt() const { | |||
4765 | return interrupt; | |||
4766 | } | |||
4767 | ||||
4768 | static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) { | |||
4769 | Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val) | |||
4770 | .Case("vector=sw0", MipsInterruptAttr::sw0) | |||
4771 | .Case("vector=sw1", MipsInterruptAttr::sw1) | |||
4772 | .Case("vector=hw0", MipsInterruptAttr::hw0) | |||
4773 | .Case("vector=hw1", MipsInterruptAttr::hw1) | |||
4774 | .Case("vector=hw2", MipsInterruptAttr::hw2) | |||
4775 | .Case("vector=hw3", MipsInterruptAttr::hw3) | |||
4776 | .Case("vector=hw4", MipsInterruptAttr::hw4) | |||
4777 | .Case("vector=hw5", MipsInterruptAttr::hw5) | |||
4778 | .Case("eic", MipsInterruptAttr::eic) | |||
4779 | .Case("", MipsInterruptAttr::eic) | |||
4780 | .Default(Optional<InterruptType>()); | |||
4781 | if (R) { | |||
4782 | Out = *R; | |||
4783 | return true; | |||
4784 | } | |||
4785 | return false; | |||
4786 | } | |||
4787 | ||||
4788 | static const char *ConvertInterruptTypeToStr(InterruptType Val) { | |||
4789 | switch(Val) { | |||
4790 | case MipsInterruptAttr::sw0: return "vector=sw0"; | |||
4791 | case MipsInterruptAttr::sw1: return "vector=sw1"; | |||
4792 | case MipsInterruptAttr::hw0: return "vector=hw0"; | |||
4793 | case MipsInterruptAttr::hw1: return "vector=hw1"; | |||
4794 | case MipsInterruptAttr::hw2: return "vector=hw2"; | |||
4795 | case MipsInterruptAttr::hw3: return "vector=hw3"; | |||
4796 | case MipsInterruptAttr::hw4: return "vector=hw4"; | |||
4797 | case MipsInterruptAttr::hw5: return "vector=hw5"; | |||
4798 | case MipsInterruptAttr::eic: return "eic"; | |||
4799 | } | |||
4800 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4800); | |||
4801 | } | |||
4802 | ||||
4803 | ||||
4804 | static bool classof(const Attr *A) { return A->getKind() == attr::MipsInterrupt; } | |||
4805 | }; | |||
4806 | ||||
4807 | class MipsLongCallAttr : public InheritableAttr { | |||
4808 | public: | |||
4809 | enum Spelling { | |||
4810 | GNU_long_call = 0, | |||
4811 | CXX11_gnu_long_call = 1, | |||
4812 | GNU_far = 2, | |||
4813 | CXX11_gnu_far = 3 | |||
4814 | }; | |||
4815 | ||||
4816 | static MipsLongCallAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
4817 | auto *A = new (Ctx) MipsLongCallAttr(Loc, Ctx, S); | |||
4818 | A->setImplicit(true); | |||
4819 | return A; | |||
4820 | } | |||
4821 | ||||
4822 | MipsLongCallAttr(SourceRange R, ASTContext &Ctx | |||
4823 | , unsigned SI | |||
4824 | ) | |||
4825 | : InheritableAttr(attr::MipsLongCall, R, SI, false, false) | |||
4826 | { | |||
4827 | } | |||
4828 | ||||
4829 | MipsLongCallAttr *clone(ASTContext &C) const; | |||
4830 | void printPretty(raw_ostream &OS, | |||
4831 | const PrintingPolicy &Policy) const; | |||
4832 | const char *getSpelling() const; | |||
4833 | Spelling getSemanticSpelling() const { | |||
4834 | switch (SpellingListIndex) { | |||
4835 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4835); | |||
4836 | case 0: return GNU_long_call; | |||
4837 | case 1: return CXX11_gnu_long_call; | |||
4838 | case 2: return GNU_far; | |||
4839 | case 3: return CXX11_gnu_far; | |||
4840 | } | |||
4841 | } | |||
4842 | ||||
4843 | ||||
4844 | static bool classof(const Attr *A) { return A->getKind() == attr::MipsLongCall; } | |||
4845 | }; | |||
4846 | ||||
4847 | class MipsShortCallAttr : public InheritableAttr { | |||
4848 | public: | |||
4849 | enum Spelling { | |||
4850 | GNU_short_call = 0, | |||
4851 | CXX11_gnu_short_call = 1, | |||
4852 | GNU_near = 2, | |||
4853 | CXX11_gnu_near = 3 | |||
4854 | }; | |||
4855 | ||||
4856 | static MipsShortCallAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
4857 | auto *A = new (Ctx) MipsShortCallAttr(Loc, Ctx, S); | |||
4858 | A->setImplicit(true); | |||
4859 | return A; | |||
4860 | } | |||
4861 | ||||
4862 | MipsShortCallAttr(SourceRange R, ASTContext &Ctx | |||
4863 | , unsigned SI | |||
4864 | ) | |||
4865 | : InheritableAttr(attr::MipsShortCall, R, SI, false, false) | |||
4866 | { | |||
4867 | } | |||
4868 | ||||
4869 | MipsShortCallAttr *clone(ASTContext &C) const; | |||
4870 | void printPretty(raw_ostream &OS, | |||
4871 | const PrintingPolicy &Policy) const; | |||
4872 | const char *getSpelling() const; | |||
4873 | Spelling getSemanticSpelling() const { | |||
4874 | switch (SpellingListIndex) { | |||
4875 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 4875); | |||
4876 | case 0: return GNU_short_call; | |||
4877 | case 1: return CXX11_gnu_short_call; | |||
4878 | case 2: return GNU_near; | |||
4879 | case 3: return CXX11_gnu_near; | |||
4880 | } | |||
4881 | } | |||
4882 | ||||
4883 | ||||
4884 | static bool classof(const Attr *A) { return A->getKind() == attr::MipsShortCall; } | |||
4885 | }; | |||
4886 | ||||
4887 | class ModeAttr : public Attr { | |||
4888 | IdentifierInfo * mode; | |||
4889 | ||||
4890 | public: | |||
4891 | static ModeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Mode, SourceRange Loc = SourceRange()) { | |||
4892 | auto *A = new (Ctx) ModeAttr(Loc, Ctx, Mode, 0); | |||
4893 | A->setImplicit(true); | |||
4894 | return A; | |||
4895 | } | |||
4896 | ||||
4897 | ModeAttr(SourceRange R, ASTContext &Ctx | |||
4898 | , IdentifierInfo * Mode | |||
4899 | , unsigned SI | |||
4900 | ) | |||
4901 | : Attr(attr::Mode, R, SI, false) | |||
4902 | , mode(Mode) | |||
4903 | { | |||
4904 | } | |||
4905 | ||||
4906 | ModeAttr *clone(ASTContext &C) const; | |||
4907 | void printPretty(raw_ostream &OS, | |||
4908 | const PrintingPolicy &Policy) const; | |||
4909 | const char *getSpelling() const; | |||
4910 | IdentifierInfo * getMode() const { | |||
4911 | return mode; | |||
4912 | } | |||
4913 | ||||
4914 | ||||
4915 | ||||
4916 | static bool classof(const Attr *A) { return A->getKind() == attr::Mode; } | |||
4917 | }; | |||
4918 | ||||
4919 | class NSConsumedAttr : public InheritableParamAttr { | |||
4920 | public: | |||
4921 | static NSConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4922 | auto *A = new (Ctx) NSConsumedAttr(Loc, Ctx, 0); | |||
4923 | A->setImplicit(true); | |||
4924 | return A; | |||
4925 | } | |||
4926 | ||||
4927 | NSConsumedAttr(SourceRange R, ASTContext &Ctx | |||
4928 | , unsigned SI | |||
4929 | ) | |||
4930 | : InheritableParamAttr(attr::NSConsumed, R, SI, false, false) | |||
4931 | { | |||
4932 | } | |||
4933 | ||||
4934 | NSConsumedAttr *clone(ASTContext &C) const; | |||
4935 | void printPretty(raw_ostream &OS, | |||
4936 | const PrintingPolicy &Policy) const; | |||
4937 | const char *getSpelling() const; | |||
4938 | ||||
4939 | ||||
4940 | static bool classof(const Attr *A) { return A->getKind() == attr::NSConsumed; } | |||
4941 | }; | |||
4942 | ||||
4943 | class NSConsumesSelfAttr : public InheritableAttr { | |||
4944 | public: | |||
4945 | static NSConsumesSelfAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4946 | auto *A = new (Ctx) NSConsumesSelfAttr(Loc, Ctx, 0); | |||
4947 | A->setImplicit(true); | |||
4948 | return A; | |||
4949 | } | |||
4950 | ||||
4951 | NSConsumesSelfAttr(SourceRange R, ASTContext &Ctx | |||
4952 | , unsigned SI | |||
4953 | ) | |||
4954 | : InheritableAttr(attr::NSConsumesSelf, R, SI, false, false) | |||
4955 | { | |||
4956 | } | |||
4957 | ||||
4958 | NSConsumesSelfAttr *clone(ASTContext &C) const; | |||
4959 | void printPretty(raw_ostream &OS, | |||
4960 | const PrintingPolicy &Policy) const; | |||
4961 | const char *getSpelling() const; | |||
4962 | ||||
4963 | ||||
4964 | static bool classof(const Attr *A) { return A->getKind() == attr::NSConsumesSelf; } | |||
4965 | }; | |||
4966 | ||||
4967 | class NSReturnsAutoreleasedAttr : public InheritableAttr { | |||
4968 | public: | |||
4969 | static NSReturnsAutoreleasedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4970 | auto *A = new (Ctx) NSReturnsAutoreleasedAttr(Loc, Ctx, 0); | |||
4971 | A->setImplicit(true); | |||
4972 | return A; | |||
4973 | } | |||
4974 | ||||
4975 | NSReturnsAutoreleasedAttr(SourceRange R, ASTContext &Ctx | |||
4976 | , unsigned SI | |||
4977 | ) | |||
4978 | : InheritableAttr(attr::NSReturnsAutoreleased, R, SI, false, false) | |||
4979 | { | |||
4980 | } | |||
4981 | ||||
4982 | NSReturnsAutoreleasedAttr *clone(ASTContext &C) const; | |||
4983 | void printPretty(raw_ostream &OS, | |||
4984 | const PrintingPolicy &Policy) const; | |||
4985 | const char *getSpelling() const; | |||
4986 | ||||
4987 | ||||
4988 | static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsAutoreleased; } | |||
4989 | }; | |||
4990 | ||||
4991 | class NSReturnsNotRetainedAttr : public InheritableAttr { | |||
4992 | public: | |||
4993 | static NSReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
4994 | auto *A = new (Ctx) NSReturnsNotRetainedAttr(Loc, Ctx, 0); | |||
4995 | A->setImplicit(true); | |||
4996 | return A; | |||
4997 | } | |||
4998 | ||||
4999 | NSReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx | |||
5000 | , unsigned SI | |||
5001 | ) | |||
5002 | : InheritableAttr(attr::NSReturnsNotRetained, R, SI, false, false) | |||
5003 | { | |||
5004 | } | |||
5005 | ||||
5006 | NSReturnsNotRetainedAttr *clone(ASTContext &C) const; | |||
5007 | void printPretty(raw_ostream &OS, | |||
5008 | const PrintingPolicy &Policy) const; | |||
5009 | const char *getSpelling() const; | |||
5010 | ||||
5011 | ||||
5012 | static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsNotRetained; } | |||
5013 | }; | |||
5014 | ||||
5015 | class NSReturnsRetainedAttr : public InheritableAttr { | |||
5016 | public: | |||
5017 | static NSReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5018 | auto *A = new (Ctx) NSReturnsRetainedAttr(Loc, Ctx, 0); | |||
5019 | A->setImplicit(true); | |||
5020 | return A; | |||
5021 | } | |||
5022 | ||||
5023 | NSReturnsRetainedAttr(SourceRange R, ASTContext &Ctx | |||
5024 | , unsigned SI | |||
5025 | ) | |||
5026 | : InheritableAttr(attr::NSReturnsRetained, R, SI, false, false) | |||
5027 | { | |||
5028 | } | |||
5029 | ||||
5030 | NSReturnsRetainedAttr *clone(ASTContext &C) const; | |||
5031 | void printPretty(raw_ostream &OS, | |||
5032 | const PrintingPolicy &Policy) const; | |||
5033 | const char *getSpelling() const; | |||
5034 | ||||
5035 | ||||
5036 | static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsRetained; } | |||
5037 | }; | |||
5038 | ||||
5039 | class NakedAttr : public InheritableAttr { | |||
5040 | public: | |||
5041 | static NakedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5042 | auto *A = new (Ctx) NakedAttr(Loc, Ctx, 0); | |||
5043 | A->setImplicit(true); | |||
5044 | return A; | |||
5045 | } | |||
5046 | ||||
5047 | NakedAttr(SourceRange R, ASTContext &Ctx | |||
5048 | , unsigned SI | |||
5049 | ) | |||
5050 | : InheritableAttr(attr::Naked, R, SI, false, false) | |||
5051 | { | |||
5052 | } | |||
5053 | ||||
5054 | NakedAttr *clone(ASTContext &C) const; | |||
5055 | void printPretty(raw_ostream &OS, | |||
5056 | const PrintingPolicy &Policy) const; | |||
5057 | const char *getSpelling() const; | |||
5058 | ||||
5059 | ||||
5060 | static bool classof(const Attr *A) { return A->getKind() == attr::Naked; } | |||
5061 | }; | |||
5062 | ||||
5063 | class NoAliasAttr : public InheritableAttr { | |||
5064 | public: | |||
5065 | static NoAliasAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5066 | auto *A = new (Ctx) NoAliasAttr(Loc, Ctx, 0); | |||
5067 | A->setImplicit(true); | |||
5068 | return A; | |||
5069 | } | |||
5070 | ||||
5071 | NoAliasAttr(SourceRange R, ASTContext &Ctx | |||
5072 | , unsigned SI | |||
5073 | ) | |||
5074 | : InheritableAttr(attr::NoAlias, R, SI, false, false) | |||
5075 | { | |||
5076 | } | |||
5077 | ||||
5078 | NoAliasAttr *clone(ASTContext &C) const; | |||
5079 | void printPretty(raw_ostream &OS, | |||
5080 | const PrintingPolicy &Policy) const; | |||
5081 | const char *getSpelling() const; | |||
5082 | ||||
5083 | ||||
5084 | static bool classof(const Attr *A) { return A->getKind() == attr::NoAlias; } | |||
5085 | }; | |||
5086 | ||||
5087 | class NoCommonAttr : public InheritableAttr { | |||
5088 | public: | |||
5089 | static NoCommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5090 | auto *A = new (Ctx) NoCommonAttr(Loc, Ctx, 0); | |||
5091 | A->setImplicit(true); | |||
5092 | return A; | |||
5093 | } | |||
5094 | ||||
5095 | NoCommonAttr(SourceRange R, ASTContext &Ctx | |||
5096 | , unsigned SI | |||
5097 | ) | |||
5098 | : InheritableAttr(attr::NoCommon, R, SI, false, false) | |||
5099 | { | |||
5100 | } | |||
5101 | ||||
5102 | NoCommonAttr *clone(ASTContext &C) const; | |||
5103 | void printPretty(raw_ostream &OS, | |||
5104 | const PrintingPolicy &Policy) const; | |||
5105 | const char *getSpelling() const; | |||
5106 | ||||
5107 | ||||
5108 | static bool classof(const Attr *A) { return A->getKind() == attr::NoCommon; } | |||
5109 | }; | |||
5110 | ||||
5111 | class NoDebugAttr : public InheritableAttr { | |||
5112 | public: | |||
5113 | static NoDebugAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5114 | auto *A = new (Ctx) NoDebugAttr(Loc, Ctx, 0); | |||
5115 | A->setImplicit(true); | |||
5116 | return A; | |||
5117 | } | |||
5118 | ||||
5119 | NoDebugAttr(SourceRange R, ASTContext &Ctx | |||
5120 | , unsigned SI | |||
5121 | ) | |||
5122 | : InheritableAttr(attr::NoDebug, R, SI, false, false) | |||
5123 | { | |||
5124 | } | |||
5125 | ||||
5126 | NoDebugAttr *clone(ASTContext &C) const; | |||
5127 | void printPretty(raw_ostream &OS, | |||
5128 | const PrintingPolicy &Policy) const; | |||
5129 | const char *getSpelling() const; | |||
5130 | ||||
5131 | ||||
5132 | static bool classof(const Attr *A) { return A->getKind() == attr::NoDebug; } | |||
5133 | }; | |||
5134 | ||||
5135 | class NoDerefAttr : public TypeAttr { | |||
5136 | public: | |||
5137 | static NoDerefAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5138 | auto *A = new (Ctx) NoDerefAttr(Loc, Ctx, 0); | |||
5139 | A->setImplicit(true); | |||
5140 | return A; | |||
5141 | } | |||
5142 | ||||
5143 | NoDerefAttr(SourceRange R, ASTContext &Ctx | |||
5144 | , unsigned SI | |||
5145 | ) | |||
5146 | : TypeAttr(attr::NoDeref, R, SI, false) | |||
5147 | { | |||
5148 | } | |||
5149 | ||||
5150 | NoDerefAttr *clone(ASTContext &C) const; | |||
5151 | void printPretty(raw_ostream &OS, | |||
5152 | const PrintingPolicy &Policy) const; | |||
5153 | const char *getSpelling() const; | |||
5154 | ||||
5155 | ||||
5156 | static bool classof(const Attr *A) { return A->getKind() == attr::NoDeref; } | |||
5157 | }; | |||
5158 | ||||
5159 | class NoDestroyAttr : public InheritableAttr { | |||
5160 | public: | |||
5161 | static NoDestroyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5162 | auto *A = new (Ctx) NoDestroyAttr(Loc, Ctx, 0); | |||
5163 | A->setImplicit(true); | |||
5164 | return A; | |||
5165 | } | |||
5166 | ||||
5167 | NoDestroyAttr(SourceRange R, ASTContext &Ctx | |||
5168 | , unsigned SI | |||
5169 | ) | |||
5170 | : InheritableAttr(attr::NoDestroy, R, SI, false, false) | |||
5171 | { | |||
5172 | } | |||
5173 | ||||
5174 | NoDestroyAttr *clone(ASTContext &C) const; | |||
5175 | void printPretty(raw_ostream &OS, | |||
5176 | const PrintingPolicy &Policy) const; | |||
5177 | const char *getSpelling() const; | |||
5178 | ||||
5179 | ||||
5180 | static bool classof(const Attr *A) { return A->getKind() == attr::NoDestroy; } | |||
5181 | }; | |||
5182 | ||||
5183 | class NoDuplicateAttr : public InheritableAttr { | |||
5184 | public: | |||
5185 | static NoDuplicateAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5186 | auto *A = new (Ctx) NoDuplicateAttr(Loc, Ctx, 0); | |||
5187 | A->setImplicit(true); | |||
5188 | return A; | |||
5189 | } | |||
5190 | ||||
5191 | NoDuplicateAttr(SourceRange R, ASTContext &Ctx | |||
5192 | , unsigned SI | |||
5193 | ) | |||
5194 | : InheritableAttr(attr::NoDuplicate, R, SI, false, false) | |||
5195 | { | |||
5196 | } | |||
5197 | ||||
5198 | NoDuplicateAttr *clone(ASTContext &C) const; | |||
5199 | void printPretty(raw_ostream &OS, | |||
5200 | const PrintingPolicy &Policy) const; | |||
5201 | const char *getSpelling() const; | |||
5202 | ||||
5203 | ||||
5204 | static bool classof(const Attr *A) { return A->getKind() == attr::NoDuplicate; } | |||
5205 | }; | |||
5206 | ||||
5207 | class NoEscapeAttr : public Attr { | |||
5208 | public: | |||
5209 | static NoEscapeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5210 | auto *A = new (Ctx) NoEscapeAttr(Loc, Ctx, 0); | |||
5211 | A->setImplicit(true); | |||
5212 | return A; | |||
5213 | } | |||
5214 | ||||
5215 | NoEscapeAttr(SourceRange R, ASTContext &Ctx | |||
5216 | , unsigned SI | |||
5217 | ) | |||
5218 | : Attr(attr::NoEscape, R, SI, false) | |||
5219 | { | |||
5220 | } | |||
5221 | ||||
5222 | NoEscapeAttr *clone(ASTContext &C) const; | |||
5223 | void printPretty(raw_ostream &OS, | |||
5224 | const PrintingPolicy &Policy) const; | |||
5225 | const char *getSpelling() const; | |||
5226 | ||||
5227 | ||||
5228 | static bool classof(const Attr *A) { return A->getKind() == attr::NoEscape; } | |||
5229 | }; | |||
5230 | ||||
5231 | class NoInlineAttr : public InheritableAttr { | |||
5232 | public: | |||
5233 | static NoInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5234 | auto *A = new (Ctx) NoInlineAttr(Loc, Ctx, 0); | |||
5235 | A->setImplicit(true); | |||
5236 | return A; | |||
5237 | } | |||
5238 | ||||
5239 | NoInlineAttr(SourceRange R, ASTContext &Ctx | |||
5240 | , unsigned SI | |||
5241 | ) | |||
5242 | : InheritableAttr(attr::NoInline, R, SI, false, false) | |||
5243 | { | |||
5244 | } | |||
5245 | ||||
5246 | NoInlineAttr *clone(ASTContext &C) const; | |||
5247 | void printPretty(raw_ostream &OS, | |||
5248 | const PrintingPolicy &Policy) const; | |||
5249 | const char *getSpelling() const; | |||
5250 | ||||
5251 | ||||
5252 | static bool classof(const Attr *A) { return A->getKind() == attr::NoInline; } | |||
5253 | }; | |||
5254 | ||||
5255 | class NoInstrumentFunctionAttr : public InheritableAttr { | |||
5256 | public: | |||
5257 | static NoInstrumentFunctionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5258 | auto *A = new (Ctx) NoInstrumentFunctionAttr(Loc, Ctx, 0); | |||
5259 | A->setImplicit(true); | |||
5260 | return A; | |||
5261 | } | |||
5262 | ||||
5263 | NoInstrumentFunctionAttr(SourceRange R, ASTContext &Ctx | |||
5264 | , unsigned SI | |||
5265 | ) | |||
5266 | : InheritableAttr(attr::NoInstrumentFunction, R, SI, false, false) | |||
5267 | { | |||
5268 | } | |||
5269 | ||||
5270 | NoInstrumentFunctionAttr *clone(ASTContext &C) const; | |||
5271 | void printPretty(raw_ostream &OS, | |||
5272 | const PrintingPolicy &Policy) const; | |||
5273 | const char *getSpelling() const; | |||
5274 | ||||
5275 | ||||
5276 | static bool classof(const Attr *A) { return A->getKind() == attr::NoInstrumentFunction; } | |||
5277 | }; | |||
5278 | ||||
5279 | class NoMicroMipsAttr : public InheritableAttr { | |||
5280 | public: | |||
5281 | static NoMicroMipsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5282 | auto *A = new (Ctx) NoMicroMipsAttr(Loc, Ctx, 0); | |||
5283 | A->setImplicit(true); | |||
5284 | return A; | |||
5285 | } | |||
5286 | ||||
5287 | NoMicroMipsAttr(SourceRange R, ASTContext &Ctx | |||
5288 | , unsigned SI | |||
5289 | ) | |||
5290 | : InheritableAttr(attr::NoMicroMips, R, SI, false, false) | |||
5291 | { | |||
5292 | } | |||
5293 | ||||
5294 | NoMicroMipsAttr *clone(ASTContext &C) const; | |||
5295 | void printPretty(raw_ostream &OS, | |||
5296 | const PrintingPolicy &Policy) const; | |||
5297 | const char *getSpelling() const; | |||
5298 | ||||
5299 | ||||
5300 | static bool classof(const Attr *A) { return A->getKind() == attr::NoMicroMips; } | |||
5301 | }; | |||
5302 | ||||
5303 | class NoMips16Attr : public InheritableAttr { | |||
5304 | public: | |||
5305 | static NoMips16Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5306 | auto *A = new (Ctx) NoMips16Attr(Loc, Ctx, 0); | |||
5307 | A->setImplicit(true); | |||
5308 | return A; | |||
5309 | } | |||
5310 | ||||
5311 | NoMips16Attr(SourceRange R, ASTContext &Ctx | |||
5312 | , unsigned SI | |||
5313 | ) | |||
5314 | : InheritableAttr(attr::NoMips16, R, SI, false, false) | |||
5315 | { | |||
5316 | } | |||
5317 | ||||
5318 | NoMips16Attr *clone(ASTContext &C) const; | |||
5319 | void printPretty(raw_ostream &OS, | |||
5320 | const PrintingPolicy &Policy) const; | |||
5321 | const char *getSpelling() const; | |||
5322 | ||||
5323 | ||||
5324 | static bool classof(const Attr *A) { return A->getKind() == attr::NoMips16; } | |||
5325 | }; | |||
5326 | ||||
5327 | class NoReturnAttr : public InheritableAttr { | |||
5328 | public: | |||
5329 | static NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5330 | auto *A = new (Ctx) NoReturnAttr(Loc, Ctx, 0); | |||
5331 | A->setImplicit(true); | |||
5332 | return A; | |||
5333 | } | |||
5334 | ||||
5335 | NoReturnAttr(SourceRange R, ASTContext &Ctx | |||
5336 | , unsigned SI | |||
5337 | ) | |||
5338 | : InheritableAttr(attr::NoReturn, R, SI, false, false) | |||
5339 | { | |||
5340 | } | |||
5341 | ||||
5342 | NoReturnAttr *clone(ASTContext &C) const; | |||
5343 | void printPretty(raw_ostream &OS, | |||
5344 | const PrintingPolicy &Policy) const; | |||
5345 | const char *getSpelling() const; | |||
5346 | ||||
5347 | ||||
5348 | static bool classof(const Attr *A) { return A->getKind() == attr::NoReturn; } | |||
5349 | }; | |||
5350 | ||||
5351 | class NoSanitizeAttr : public InheritableAttr { | |||
5352 | unsigned sanitizers_Size; | |||
5353 | StringRef *sanitizers_; | |||
5354 | ||||
5355 | public: | |||
5356 | static NoSanitizeAttr *CreateImplicit(ASTContext &Ctx, StringRef *Sanitizers, unsigned SanitizersSize, SourceRange Loc = SourceRange()) { | |||
5357 | auto *A = new (Ctx) NoSanitizeAttr(Loc, Ctx, Sanitizers, SanitizersSize, 0); | |||
5358 | A->setImplicit(true); | |||
5359 | return A; | |||
5360 | } | |||
5361 | ||||
5362 | NoSanitizeAttr(SourceRange R, ASTContext &Ctx | |||
5363 | , StringRef *Sanitizers, unsigned SanitizersSize | |||
5364 | , unsigned SI | |||
5365 | ) | |||
5366 | : InheritableAttr(attr::NoSanitize, R, SI, false, false) | |||
5367 | , sanitizers_Size(SanitizersSize), sanitizers_(new (Ctx, 16) StringRef[sanitizers_Size]) | |||
5368 | { | |||
5369 | for (size_t I = 0, E = sanitizers_Size; I != E; | |||
5370 | ++I) { | |||
5371 | StringRef Ref = Sanitizers[I]; | |||
5372 | if (!Ref.empty()) { | |||
5373 | char *Mem = new (Ctx, 1) char[Ref.size()]; | |||
5374 | std::memcpy(Mem, Ref.data(), Ref.size()); | |||
5375 | sanitizers_[I] = StringRef(Mem, Ref.size()); | |||
5376 | } | |||
5377 | } | |||
5378 | } | |||
5379 | ||||
5380 | NoSanitizeAttr(SourceRange R, ASTContext &Ctx | |||
5381 | , unsigned SI | |||
5382 | ) | |||
5383 | : InheritableAttr(attr::NoSanitize, R, SI, false, false) | |||
5384 | , sanitizers_Size(0), sanitizers_(nullptr) | |||
5385 | { | |||
5386 | } | |||
5387 | ||||
5388 | NoSanitizeAttr *clone(ASTContext &C) const; | |||
5389 | void printPretty(raw_ostream &OS, | |||
5390 | const PrintingPolicy &Policy) const; | |||
5391 | const char *getSpelling() const; | |||
5392 | typedef StringRef* sanitizers_iterator; | |||
5393 | sanitizers_iterator sanitizers_begin() const { return sanitizers_; } | |||
5394 | sanitizers_iterator sanitizers_end() const { return sanitizers_ + sanitizers_Size; } | |||
5395 | unsigned sanitizers_size() const { return sanitizers_Size; } | |||
5396 | llvm::iterator_range<sanitizers_iterator> sanitizers() const { return llvm::make_range(sanitizers_begin(), sanitizers_end()); } | |||
5397 | ||||
5398 | ||||
5399 | ||||
5400 | SanitizerMask getMask() const { | |||
5401 | SanitizerMask Mask; | |||
5402 | for (auto SanitizerName : sanitizers()) { | |||
5403 | SanitizerMask ParsedMask = | |||
5404 | parseSanitizerValue(SanitizerName, /*AllowGroups=*/true); | |||
5405 | Mask |= expandSanitizerGroups(ParsedMask); | |||
5406 | } | |||
5407 | return Mask; | |||
5408 | } | |||
5409 | ||||
5410 | ||||
5411 | static bool classof(const Attr *A) { return A->getKind() == attr::NoSanitize; } | |||
5412 | }; | |||
5413 | ||||
5414 | class NoSpeculativeLoadHardeningAttr : public InheritableAttr { | |||
5415 | public: | |||
5416 | static NoSpeculativeLoadHardeningAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5417 | auto *A = new (Ctx) NoSpeculativeLoadHardeningAttr(Loc, Ctx, 0); | |||
5418 | A->setImplicit(true); | |||
5419 | return A; | |||
5420 | } | |||
5421 | ||||
5422 | NoSpeculativeLoadHardeningAttr(SourceRange R, ASTContext &Ctx | |||
5423 | , unsigned SI | |||
5424 | ) | |||
5425 | : InheritableAttr(attr::NoSpeculativeLoadHardening, R, SI, false, false) | |||
5426 | { | |||
5427 | } | |||
5428 | ||||
5429 | NoSpeculativeLoadHardeningAttr *clone(ASTContext &C) const; | |||
5430 | void printPretty(raw_ostream &OS, | |||
5431 | const PrintingPolicy &Policy) const; | |||
5432 | const char *getSpelling() const; | |||
5433 | ||||
5434 | ||||
5435 | static bool classof(const Attr *A) { return A->getKind() == attr::NoSpeculativeLoadHardening; } | |||
5436 | }; | |||
5437 | ||||
5438 | class NoSplitStackAttr : public InheritableAttr { | |||
5439 | public: | |||
5440 | static NoSplitStackAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5441 | auto *A = new (Ctx) NoSplitStackAttr(Loc, Ctx, 0); | |||
5442 | A->setImplicit(true); | |||
5443 | return A; | |||
5444 | } | |||
5445 | ||||
5446 | NoSplitStackAttr(SourceRange R, ASTContext &Ctx | |||
5447 | , unsigned SI | |||
5448 | ) | |||
5449 | : InheritableAttr(attr::NoSplitStack, R, SI, false, false) | |||
5450 | { | |||
5451 | } | |||
5452 | ||||
5453 | NoSplitStackAttr *clone(ASTContext &C) const; | |||
5454 | void printPretty(raw_ostream &OS, | |||
5455 | const PrintingPolicy &Policy) const; | |||
5456 | const char *getSpelling() const; | |||
5457 | ||||
5458 | ||||
5459 | static bool classof(const Attr *A) { return A->getKind() == attr::NoSplitStack; } | |||
5460 | }; | |||
5461 | ||||
5462 | class NoStackProtectorAttr : public InheritableAttr { | |||
5463 | public: | |||
5464 | static NoStackProtectorAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5465 | auto *A = new (Ctx) NoStackProtectorAttr(Loc, Ctx, 0); | |||
5466 | A->setImplicit(true); | |||
5467 | return A; | |||
5468 | } | |||
5469 | ||||
5470 | NoStackProtectorAttr(SourceRange R, ASTContext &Ctx | |||
5471 | , unsigned SI | |||
5472 | ) | |||
5473 | : InheritableAttr(attr::NoStackProtector, R, SI, false, false) | |||
5474 | { | |||
5475 | } | |||
5476 | ||||
5477 | NoStackProtectorAttr *clone(ASTContext &C) const; | |||
5478 | void printPretty(raw_ostream &OS, | |||
5479 | const PrintingPolicy &Policy) const; | |||
5480 | const char *getSpelling() const; | |||
5481 | ||||
5482 | ||||
5483 | static bool classof(const Attr *A) { return A->getKind() == attr::NoStackProtector; } | |||
5484 | }; | |||
5485 | ||||
5486 | class NoThreadSafetyAnalysisAttr : public InheritableAttr { | |||
5487 | public: | |||
5488 | static NoThreadSafetyAnalysisAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5489 | auto *A = new (Ctx) NoThreadSafetyAnalysisAttr(Loc, Ctx, 0); | |||
5490 | A->setImplicit(true); | |||
5491 | return A; | |||
5492 | } | |||
5493 | ||||
5494 | NoThreadSafetyAnalysisAttr(SourceRange R, ASTContext &Ctx | |||
5495 | , unsigned SI | |||
5496 | ) | |||
5497 | : InheritableAttr(attr::NoThreadSafetyAnalysis, R, SI, false, false) | |||
5498 | { | |||
5499 | } | |||
5500 | ||||
5501 | NoThreadSafetyAnalysisAttr *clone(ASTContext &C) const; | |||
5502 | void printPretty(raw_ostream &OS, | |||
5503 | const PrintingPolicy &Policy) const; | |||
5504 | const char *getSpelling() const; | |||
5505 | ||||
5506 | ||||
5507 | static bool classof(const Attr *A) { return A->getKind() == attr::NoThreadSafetyAnalysis; } | |||
5508 | }; | |||
5509 | ||||
5510 | class NoThrowAttr : public InheritableAttr { | |||
5511 | public: | |||
5512 | static NoThrowAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5513 | auto *A = new (Ctx) NoThrowAttr(Loc, Ctx, 0); | |||
5514 | A->setImplicit(true); | |||
5515 | return A; | |||
5516 | } | |||
5517 | ||||
5518 | NoThrowAttr(SourceRange R, ASTContext &Ctx | |||
5519 | , unsigned SI | |||
5520 | ) | |||
5521 | : InheritableAttr(attr::NoThrow, R, SI, false, false) | |||
5522 | { | |||
5523 | } | |||
5524 | ||||
5525 | NoThrowAttr *clone(ASTContext &C) const; | |||
5526 | void printPretty(raw_ostream &OS, | |||
5527 | const PrintingPolicy &Policy) const; | |||
5528 | const char *getSpelling() const; | |||
5529 | ||||
5530 | ||||
5531 | static bool classof(const Attr *A) { return A->getKind() == attr::NoThrow; } | |||
5532 | }; | |||
5533 | ||||
5534 | class NonNullAttr : public InheritableParamAttr { | |||
5535 | unsigned args_Size; | |||
5536 | ParamIdx *args_; | |||
5537 | ||||
5538 | public: | |||
5539 | static NonNullAttr *CreateImplicit(ASTContext &Ctx, ParamIdx *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
5540 | auto *A = new (Ctx) NonNullAttr(Loc, Ctx, Args, ArgsSize, 0); | |||
5541 | A->setImplicit(true); | |||
5542 | return A; | |||
5543 | } | |||
5544 | ||||
5545 | NonNullAttr(SourceRange R, ASTContext &Ctx | |||
5546 | , ParamIdx *Args, unsigned ArgsSize | |||
5547 | , unsigned SI | |||
5548 | ) | |||
5549 | : InheritableParamAttr(attr::NonNull, R, SI, false, true) | |||
5550 | , args_Size(ArgsSize), args_(new (Ctx, 16) ParamIdx[args_Size]) | |||
5551 | { | |||
5552 | std::copy(Args, Args + args_Size, args_); | |||
5553 | } | |||
5554 | ||||
5555 | NonNullAttr(SourceRange R, ASTContext &Ctx | |||
5556 | , unsigned SI | |||
5557 | ) | |||
5558 | : InheritableParamAttr(attr::NonNull, R, SI, false, true) | |||
5559 | , args_Size(0), args_(nullptr) | |||
5560 | { | |||
5561 | } | |||
5562 | ||||
5563 | NonNullAttr *clone(ASTContext &C) const; | |||
5564 | void printPretty(raw_ostream &OS, | |||
5565 | const PrintingPolicy &Policy) const; | |||
5566 | const char *getSpelling() const; | |||
5567 | typedef ParamIdx* args_iterator; | |||
5568 | args_iterator args_begin() const { return args_; } | |||
5569 | args_iterator args_end() const { return args_ + args_Size; } | |||
5570 | unsigned args_size() const { return args_Size; } | |||
5571 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
5572 | ||||
5573 | ||||
5574 | ||||
5575 | bool isNonNull(unsigned IdxAST) const { | |||
5576 | if (!args_size()) | |||
5577 | return true; | |||
5578 | return args_end() != std::find_if( | |||
5579 | args_begin(), args_end(), | |||
5580 | [=](const ParamIdx &Idx) { return Idx.getASTIndex() == IdxAST; }); | |||
5581 | } | |||
5582 | ||||
5583 | ||||
5584 | static bool classof(const Attr *A) { return A->getKind() == attr::NonNull; } | |||
5585 | }; | |||
5586 | ||||
5587 | class NotTailCalledAttr : public InheritableAttr { | |||
5588 | public: | |||
5589 | static NotTailCalledAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5590 | auto *A = new (Ctx) NotTailCalledAttr(Loc, Ctx, 0); | |||
5591 | A->setImplicit(true); | |||
5592 | return A; | |||
5593 | } | |||
5594 | ||||
5595 | NotTailCalledAttr(SourceRange R, ASTContext &Ctx | |||
5596 | , unsigned SI | |||
5597 | ) | |||
5598 | : InheritableAttr(attr::NotTailCalled, R, SI, false, false) | |||
5599 | { | |||
5600 | } | |||
5601 | ||||
5602 | NotTailCalledAttr *clone(ASTContext &C) const; | |||
5603 | void printPretty(raw_ostream &OS, | |||
5604 | const PrintingPolicy &Policy) const; | |||
5605 | const char *getSpelling() const; | |||
5606 | ||||
5607 | ||||
5608 | static bool classof(const Attr *A) { return A->getKind() == attr::NotTailCalled; } | |||
5609 | }; | |||
5610 | ||||
5611 | class OMPAllocateDeclAttr : public InheritableAttr { | |||
5612 | public: | |||
5613 | enum AllocatorTypeTy { | |||
5614 | OMPDefaultMemAlloc, | |||
5615 | OMPLargeCapMemAlloc, | |||
5616 | OMPConstMemAlloc, | |||
5617 | OMPHighBWMemAlloc, | |||
5618 | OMPLowLatMemAlloc, | |||
5619 | OMPCGroupMemAlloc, | |||
5620 | OMPPTeamMemAlloc, | |||
5621 | OMPThreadMemAlloc, | |||
5622 | OMPUserDefinedMemAlloc | |||
5623 | }; | |||
5624 | private: | |||
5625 | AllocatorTypeTy allocatorType; | |||
5626 | ||||
5627 | Expr * allocator; | |||
5628 | ||||
5629 | public: | |||
5630 | static OMPAllocateDeclAttr *CreateImplicit(ASTContext &Ctx, AllocatorTypeTy AllocatorType, Expr * Allocator, SourceRange Loc = SourceRange()) { | |||
5631 | auto *A = new (Ctx) OMPAllocateDeclAttr(Loc, Ctx, AllocatorType, Allocator, 0); | |||
5632 | A->setImplicit(true); | |||
5633 | return A; | |||
5634 | } | |||
5635 | ||||
5636 | OMPAllocateDeclAttr(SourceRange R, ASTContext &Ctx | |||
5637 | , AllocatorTypeTy AllocatorType | |||
5638 | , Expr * Allocator | |||
5639 | , unsigned SI | |||
5640 | ) | |||
5641 | : InheritableAttr(attr::OMPAllocateDecl, R, SI, false, false) | |||
5642 | , allocatorType(AllocatorType) | |||
5643 | , allocator(Allocator) | |||
5644 | { | |||
5645 | } | |||
5646 | ||||
5647 | OMPAllocateDeclAttr *clone(ASTContext &C) const; | |||
5648 | void printPretty(raw_ostream &OS, | |||
5649 | const PrintingPolicy &Policy) const; | |||
5650 | const char *getSpelling() const; | |||
5651 | AllocatorTypeTy getAllocatorType() const { | |||
5652 | return allocatorType; | |||
5653 | } | |||
5654 | ||||
5655 | static bool ConvertStrToAllocatorTypeTy(StringRef Val, AllocatorTypeTy &Out) { | |||
5656 | Optional<AllocatorTypeTy> R = llvm::StringSwitch<Optional<AllocatorTypeTy>>(Val) | |||
5657 | .Case("omp_default_mem_alloc", OMPAllocateDeclAttr::OMPDefaultMemAlloc) | |||
5658 | .Case("omp_large_cap_mem_alloc", OMPAllocateDeclAttr::OMPLargeCapMemAlloc) | |||
5659 | .Case("omp_const_mem_alloc", OMPAllocateDeclAttr::OMPConstMemAlloc) | |||
5660 | .Case("omp_high_bw_mem_alloc", OMPAllocateDeclAttr::OMPHighBWMemAlloc) | |||
5661 | .Case("omp_low_lat_mem_alloc", OMPAllocateDeclAttr::OMPLowLatMemAlloc) | |||
5662 | .Case("omp_cgroup_mem_alloc", OMPAllocateDeclAttr::OMPCGroupMemAlloc) | |||
5663 | .Case("omp_pteam_mem_alloc", OMPAllocateDeclAttr::OMPPTeamMemAlloc) | |||
5664 | .Case("omp_thread_mem_alloc", OMPAllocateDeclAttr::OMPThreadMemAlloc) | |||
5665 | .Case("", OMPAllocateDeclAttr::OMPUserDefinedMemAlloc) | |||
5666 | .Default(Optional<AllocatorTypeTy>()); | |||
5667 | if (R) { | |||
5668 | Out = *R; | |||
5669 | return true; | |||
5670 | } | |||
5671 | return false; | |||
5672 | } | |||
5673 | ||||
5674 | static const char *ConvertAllocatorTypeTyToStr(AllocatorTypeTy Val) { | |||
5675 | switch(Val) { | |||
5676 | case OMPAllocateDeclAttr::OMPDefaultMemAlloc: return "omp_default_mem_alloc"; | |||
5677 | case OMPAllocateDeclAttr::OMPLargeCapMemAlloc: return "omp_large_cap_mem_alloc"; | |||
5678 | case OMPAllocateDeclAttr::OMPConstMemAlloc: return "omp_const_mem_alloc"; | |||
5679 | case OMPAllocateDeclAttr::OMPHighBWMemAlloc: return "omp_high_bw_mem_alloc"; | |||
5680 | case OMPAllocateDeclAttr::OMPLowLatMemAlloc: return "omp_low_lat_mem_alloc"; | |||
5681 | case OMPAllocateDeclAttr::OMPCGroupMemAlloc: return "omp_cgroup_mem_alloc"; | |||
5682 | case OMPAllocateDeclAttr::OMPPTeamMemAlloc: return "omp_pteam_mem_alloc"; | |||
5683 | case OMPAllocateDeclAttr::OMPThreadMemAlloc: return "omp_thread_mem_alloc"; | |||
5684 | case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc: return ""; | |||
5685 | } | |||
5686 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 5686); | |||
5687 | } | |||
5688 | Expr * getAllocator() const { | |||
5689 | return allocator; | |||
5690 | } | |||
5691 | ||||
5692 | ||||
5693 | ||||
5694 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPAllocateDecl; } | |||
5695 | }; | |||
5696 | ||||
5697 | class OMPCaptureKindAttr : public Attr { | |||
5698 | unsigned captureKind; | |||
5699 | ||||
5700 | public: | |||
5701 | static OMPCaptureKindAttr *CreateImplicit(ASTContext &Ctx, unsigned CaptureKind, SourceRange Loc = SourceRange()) { | |||
5702 | auto *A = new (Ctx) OMPCaptureKindAttr(Loc, Ctx, CaptureKind, 0); | |||
5703 | A->setImplicit(true); | |||
5704 | return A; | |||
5705 | } | |||
5706 | ||||
5707 | OMPCaptureKindAttr(SourceRange R, ASTContext &Ctx | |||
5708 | , unsigned CaptureKind | |||
5709 | , unsigned SI | |||
5710 | ) | |||
5711 | : Attr(attr::OMPCaptureKind, R, SI, false) | |||
5712 | , captureKind(CaptureKind) | |||
5713 | { | |||
5714 | } | |||
5715 | ||||
5716 | OMPCaptureKindAttr *clone(ASTContext &C) const; | |||
5717 | void printPretty(raw_ostream &OS, | |||
5718 | const PrintingPolicy &Policy) const; | |||
5719 | const char *getSpelling() const; | |||
5720 | unsigned getCaptureKind() const { | |||
5721 | return captureKind; | |||
5722 | } | |||
5723 | ||||
5724 | ||||
5725 | ||||
5726 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPCaptureKind; } | |||
5727 | }; | |||
5728 | ||||
5729 | class OMPCaptureNoInitAttr : public InheritableAttr { | |||
5730 | public: | |||
5731 | static OMPCaptureNoInitAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
5732 | auto *A = new (Ctx) OMPCaptureNoInitAttr(Loc, Ctx, 0); | |||
5733 | A->setImplicit(true); | |||
5734 | return A; | |||
5735 | } | |||
5736 | ||||
5737 | OMPCaptureNoInitAttr(SourceRange R, ASTContext &Ctx | |||
5738 | , unsigned SI | |||
5739 | ) | |||
5740 | : InheritableAttr(attr::OMPCaptureNoInit, R, SI, false, false) | |||
5741 | { | |||
5742 | } | |||
5743 | ||||
5744 | OMPCaptureNoInitAttr *clone(ASTContext &C) const; | |||
5745 | void printPretty(raw_ostream &OS, | |||
5746 | const PrintingPolicy &Policy) const; | |||
5747 | const char *getSpelling() const; | |||
5748 | ||||
5749 | ||||
5750 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPCaptureNoInit; } | |||
5751 | }; | |||
5752 | ||||
5753 | class OMPDeclareSimdDeclAttr : public Attr { | |||
5754 | public: | |||
5755 | enum BranchStateTy { | |||
5756 | BS_Undefined, | |||
5757 | BS_Inbranch, | |||
5758 | BS_Notinbranch | |||
5759 | }; | |||
5760 | private: | |||
5761 | BranchStateTy branchState; | |||
5762 | ||||
5763 | Expr * simdlen; | |||
5764 | ||||
5765 | unsigned uniforms_Size; | |||
5766 | Expr * *uniforms_; | |||
5767 | ||||
5768 | unsigned aligneds_Size; | |||
5769 | Expr * *aligneds_; | |||
5770 | ||||
5771 | unsigned alignments_Size; | |||
5772 | Expr * *alignments_; | |||
5773 | ||||
5774 | unsigned linears_Size; | |||
5775 | Expr * *linears_; | |||
5776 | ||||
5777 | unsigned modifiers_Size; | |||
5778 | unsigned *modifiers_; | |||
5779 | ||||
5780 | unsigned steps_Size; | |||
5781 | Expr * *steps_; | |||
5782 | ||||
5783 | public: | |||
5784 | static OMPDeclareSimdDeclAttr *CreateImplicit(ASTContext &Ctx, BranchStateTy BranchState, Expr * Simdlen, Expr * *Uniforms, unsigned UniformsSize, Expr * *Aligneds, unsigned AlignedsSize, Expr * *Alignments, unsigned AlignmentsSize, Expr * *Linears, unsigned LinearsSize, unsigned *Modifiers, unsigned ModifiersSize, Expr * *Steps, unsigned StepsSize, SourceRange Loc = SourceRange()) { | |||
5785 | auto *A = new (Ctx) OMPDeclareSimdDeclAttr(Loc, Ctx, BranchState, Simdlen, Uniforms, UniformsSize, Aligneds, AlignedsSize, Alignments, AlignmentsSize, Linears, LinearsSize, Modifiers, ModifiersSize, Steps, StepsSize, 0); | |||
5786 | A->setImplicit(true); | |||
5787 | return A; | |||
5788 | } | |||
5789 | ||||
5790 | OMPDeclareSimdDeclAttr(SourceRange R, ASTContext &Ctx | |||
5791 | , BranchStateTy BranchState | |||
5792 | , Expr * Simdlen | |||
5793 | , Expr * *Uniforms, unsigned UniformsSize | |||
5794 | , Expr * *Aligneds, unsigned AlignedsSize | |||
5795 | , Expr * *Alignments, unsigned AlignmentsSize | |||
5796 | , Expr * *Linears, unsigned LinearsSize | |||
5797 | , unsigned *Modifiers, unsigned ModifiersSize | |||
5798 | , Expr * *Steps, unsigned StepsSize | |||
5799 | , unsigned SI | |||
5800 | ) | |||
5801 | : Attr(attr::OMPDeclareSimdDecl, R, SI, false) | |||
5802 | , branchState(BranchState) | |||
5803 | , simdlen(Simdlen) | |||
5804 | , uniforms_Size(UniformsSize), uniforms_(new (Ctx, 16) Expr *[uniforms_Size]) | |||
5805 | , aligneds_Size(AlignedsSize), aligneds_(new (Ctx, 16) Expr *[aligneds_Size]) | |||
5806 | , alignments_Size(AlignmentsSize), alignments_(new (Ctx, 16) Expr *[alignments_Size]) | |||
5807 | , linears_Size(LinearsSize), linears_(new (Ctx, 16) Expr *[linears_Size]) | |||
5808 | , modifiers_Size(ModifiersSize), modifiers_(new (Ctx, 16) unsigned[modifiers_Size]) | |||
5809 | , steps_Size(StepsSize), steps_(new (Ctx, 16) Expr *[steps_Size]) | |||
5810 | { | |||
5811 | std::copy(Uniforms, Uniforms + uniforms_Size, uniforms_); | |||
5812 | std::copy(Aligneds, Aligneds + aligneds_Size, aligneds_); | |||
5813 | std::copy(Alignments, Alignments + alignments_Size, alignments_); | |||
5814 | std::copy(Linears, Linears + linears_Size, linears_); | |||
5815 | std::copy(Modifiers, Modifiers + modifiers_Size, modifiers_); | |||
5816 | std::copy(Steps, Steps + steps_Size, steps_); | |||
5817 | } | |||
5818 | ||||
5819 | OMPDeclareSimdDeclAttr(SourceRange R, ASTContext &Ctx | |||
5820 | , BranchStateTy BranchState | |||
5821 | , Expr * Simdlen | |||
5822 | , unsigned SI | |||
5823 | ) | |||
5824 | : Attr(attr::OMPDeclareSimdDecl, R, SI, false) | |||
5825 | , branchState(BranchState) | |||
5826 | , simdlen(Simdlen) | |||
5827 | , uniforms_Size(0), uniforms_(nullptr) | |||
5828 | , aligneds_Size(0), aligneds_(nullptr) | |||
5829 | , alignments_Size(0), alignments_(nullptr) | |||
5830 | , linears_Size(0), linears_(nullptr) | |||
5831 | , modifiers_Size(0), modifiers_(nullptr) | |||
5832 | , steps_Size(0), steps_(nullptr) | |||
5833 | { | |||
5834 | } | |||
5835 | ||||
5836 | OMPDeclareSimdDeclAttr *clone(ASTContext &C) const; | |||
5837 | void printPretty(raw_ostream &OS, | |||
5838 | const PrintingPolicy &Policy) const; | |||
5839 | const char *getSpelling() const; | |||
5840 | BranchStateTy getBranchState() const { | |||
5841 | return branchState; | |||
5842 | } | |||
5843 | ||||
5844 | static bool ConvertStrToBranchStateTy(StringRef Val, BranchStateTy &Out) { | |||
5845 | Optional<BranchStateTy> R = llvm::StringSwitch<Optional<BranchStateTy>>(Val) | |||
5846 | .Case("", OMPDeclareSimdDeclAttr::BS_Undefined) | |||
5847 | .Case("inbranch", OMPDeclareSimdDeclAttr::BS_Inbranch) | |||
5848 | .Case("notinbranch", OMPDeclareSimdDeclAttr::BS_Notinbranch) | |||
5849 | .Default(Optional<BranchStateTy>()); | |||
5850 | if (R) { | |||
5851 | Out = *R; | |||
5852 | return true; | |||
5853 | } | |||
5854 | return false; | |||
5855 | } | |||
5856 | ||||
5857 | static const char *ConvertBranchStateTyToStr(BranchStateTy Val) { | |||
5858 | switch(Val) { | |||
5859 | case OMPDeclareSimdDeclAttr::BS_Undefined: return ""; | |||
5860 | case OMPDeclareSimdDeclAttr::BS_Inbranch: return "inbranch"; | |||
5861 | case OMPDeclareSimdDeclAttr::BS_Notinbranch: return "notinbranch"; | |||
5862 | } | |||
5863 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 5863); | |||
5864 | } | |||
5865 | Expr * getSimdlen() const { | |||
5866 | return simdlen; | |||
5867 | } | |||
5868 | ||||
5869 | typedef Expr ** uniforms_iterator; | |||
5870 | uniforms_iterator uniforms_begin() const { return uniforms_; } | |||
5871 | uniforms_iterator uniforms_end() const { return uniforms_ + uniforms_Size; } | |||
5872 | unsigned uniforms_size() const { return uniforms_Size; } | |||
5873 | llvm::iterator_range<uniforms_iterator> uniforms() const { return llvm::make_range(uniforms_begin(), uniforms_end()); } | |||
5874 | ||||
5875 | ||||
5876 | typedef Expr ** aligneds_iterator; | |||
5877 | aligneds_iterator aligneds_begin() const { return aligneds_; } | |||
5878 | aligneds_iterator aligneds_end() const { return aligneds_ + aligneds_Size; } | |||
5879 | unsigned aligneds_size() const { return aligneds_Size; } | |||
5880 | llvm::iterator_range<aligneds_iterator> aligneds() const { return llvm::make_range(aligneds_begin(), aligneds_end()); } | |||
5881 | ||||
5882 | ||||
5883 | typedef Expr ** alignments_iterator; | |||
5884 | alignments_iterator alignments_begin() const { return alignments_; } | |||
5885 | alignments_iterator alignments_end() const { return alignments_ + alignments_Size; } | |||
5886 | unsigned alignments_size() const { return alignments_Size; } | |||
5887 | llvm::iterator_range<alignments_iterator> alignments() const { return llvm::make_range(alignments_begin(), alignments_end()); } | |||
5888 | ||||
5889 | ||||
5890 | typedef Expr ** linears_iterator; | |||
5891 | linears_iterator linears_begin() const { return linears_; } | |||
5892 | linears_iterator linears_end() const { return linears_ + linears_Size; } | |||
5893 | unsigned linears_size() const { return linears_Size; } | |||
5894 | llvm::iterator_range<linears_iterator> linears() const { return llvm::make_range(linears_begin(), linears_end()); } | |||
5895 | ||||
5896 | ||||
5897 | typedef unsigned* modifiers_iterator; | |||
5898 | modifiers_iterator modifiers_begin() const { return modifiers_; } | |||
5899 | modifiers_iterator modifiers_end() const { return modifiers_ + modifiers_Size; } | |||
5900 | unsigned modifiers_size() const { return modifiers_Size; } | |||
5901 | llvm::iterator_range<modifiers_iterator> modifiers() const { return llvm::make_range(modifiers_begin(), modifiers_end()); } | |||
5902 | ||||
5903 | ||||
5904 | typedef Expr ** steps_iterator; | |||
5905 | steps_iterator steps_begin() const { return steps_; } | |||
5906 | steps_iterator steps_end() const { return steps_ + steps_Size; } | |||
5907 | unsigned steps_size() const { return steps_Size; } | |||
5908 | llvm::iterator_range<steps_iterator> steps() const { return llvm::make_range(steps_begin(), steps_end()); } | |||
5909 | ||||
5910 | ||||
5911 | ||||
5912 | void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy) | |||
5913 | const { | |||
5914 | if (getBranchState() != BS_Undefined) | |||
5915 | OS << ' ' << ConvertBranchStateTyToStr(getBranchState()); | |||
5916 | if (auto *E = getSimdlen()) { | |||
5917 | OS << " simdlen("; | |||
5918 | E->printPretty(OS, nullptr, Policy); | |||
5919 | OS << ")"; | |||
5920 | } | |||
5921 | if (uniforms_size() > 0) { | |||
5922 | OS << " uniform"; | |||
5923 | StringRef Sep = "("; | |||
5924 | for (auto *E : uniforms()) { | |||
5925 | OS << Sep; | |||
5926 | E->printPretty(OS, nullptr, Policy); | |||
5927 | Sep = ", "; | |||
5928 | } | |||
5929 | OS << ")"; | |||
5930 | } | |||
5931 | alignments_iterator NI = alignments_begin(); | |||
5932 | for (auto *E : aligneds()) { | |||
5933 | OS << " aligned("; | |||
5934 | E->printPretty(OS, nullptr, Policy); | |||
5935 | if (*NI) { | |||
5936 | OS << ": "; | |||
5937 | (*NI)->printPretty(OS, nullptr, Policy); | |||
5938 | } | |||
5939 | OS << ")"; | |||
5940 | ++NI; | |||
5941 | } | |||
5942 | steps_iterator I = steps_begin(); | |||
5943 | modifiers_iterator MI = modifiers_begin(); | |||
5944 | for (auto *E : linears()) { | |||
5945 | OS << " linear("; | |||
5946 | if (*MI != OMPC_LINEAR_unknown) | |||
5947 | OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "("; | |||
5948 | E->printPretty(OS, nullptr, Policy); | |||
5949 | if (*MI != OMPC_LINEAR_unknown) | |||
5950 | OS << ")"; | |||
5951 | if (*I) { | |||
5952 | OS << ": "; | |||
5953 | (*I)->printPretty(OS, nullptr, Policy); | |||
5954 | } | |||
5955 | OS << ")"; | |||
5956 | ++I; | |||
5957 | ++MI; | |||
5958 | } | |||
5959 | } | |||
5960 | ||||
5961 | ||||
5962 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPDeclareSimdDecl; } | |||
5963 | }; | |||
5964 | ||||
5965 | class OMPDeclareTargetDeclAttr : public InheritableAttr { | |||
5966 | public: | |||
5967 | enum MapTypeTy { | |||
5968 | MT_To, | |||
5969 | MT_Link | |||
5970 | }; | |||
5971 | private: | |||
5972 | MapTypeTy mapType; | |||
5973 | ||||
5974 | public: | |||
5975 | static OMPDeclareTargetDeclAttr *CreateImplicit(ASTContext &Ctx, MapTypeTy MapType, SourceRange Loc = SourceRange()) { | |||
5976 | auto *A = new (Ctx) OMPDeclareTargetDeclAttr(Loc, Ctx, MapType, 0); | |||
5977 | A->setImplicit(true); | |||
5978 | return A; | |||
5979 | } | |||
5980 | ||||
5981 | OMPDeclareTargetDeclAttr(SourceRange R, ASTContext &Ctx | |||
5982 | , MapTypeTy MapType | |||
5983 | , unsigned SI | |||
5984 | ) | |||
5985 | : InheritableAttr(attr::OMPDeclareTargetDecl, R, SI, false, false) | |||
5986 | , mapType(MapType) | |||
5987 | { | |||
5988 | } | |||
5989 | ||||
5990 | OMPDeclareTargetDeclAttr *clone(ASTContext &C) const; | |||
5991 | void printPretty(raw_ostream &OS, | |||
5992 | const PrintingPolicy &Policy) const; | |||
5993 | const char *getSpelling() const; | |||
5994 | MapTypeTy getMapType() const { | |||
5995 | return mapType; | |||
5996 | } | |||
5997 | ||||
5998 | static bool ConvertStrToMapTypeTy(StringRef Val, MapTypeTy &Out) { | |||
5999 | Optional<MapTypeTy> R = llvm::StringSwitch<Optional<MapTypeTy>>(Val) | |||
6000 | .Case("to", OMPDeclareTargetDeclAttr::MT_To) | |||
6001 | .Case("link", OMPDeclareTargetDeclAttr::MT_Link) | |||
6002 | .Default(Optional<MapTypeTy>()); | |||
6003 | if (R) { | |||
6004 | Out = *R; | |||
6005 | return true; | |||
6006 | } | |||
6007 | return false; | |||
6008 | } | |||
6009 | ||||
6010 | static const char *ConvertMapTypeTyToStr(MapTypeTy Val) { | |||
6011 | switch(Val) { | |||
6012 | case OMPDeclareTargetDeclAttr::MT_To: return "to"; | |||
6013 | case OMPDeclareTargetDeclAttr::MT_Link: return "link"; | |||
6014 | } | |||
6015 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 6015); | |||
6016 | } | |||
6017 | ||||
6018 | void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const { | |||
6019 | // Use fake syntax because it is for testing and debugging purpose only. | |||
6020 | if (getMapType() != MT_To) | |||
6021 | OS << ' ' << ConvertMapTypeTyToStr(getMapType()); | |||
6022 | } | |||
6023 | static llvm::Optional<MapTypeTy> | |||
6024 | isDeclareTargetDeclaration(const ValueDecl *VD) { | |||
6025 | if (!VD->hasAttrs()) | |||
6026 | return llvm::None; | |||
6027 | if (const auto *Attr = VD->getAttr<OMPDeclareTargetDeclAttr>()) | |||
6028 | return Attr->getMapType(); | |||
6029 | ||||
6030 | return llvm::None; | |||
6031 | } | |||
6032 | ||||
6033 | ||||
6034 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPDeclareTargetDecl; } | |||
6035 | }; | |||
6036 | ||||
6037 | class OMPReferencedVarAttr : public Attr { | |||
6038 | Expr * ref; | |||
6039 | ||||
6040 | public: | |||
6041 | static OMPReferencedVarAttr *CreateImplicit(ASTContext &Ctx, Expr * Ref, SourceRange Loc = SourceRange()) { | |||
6042 | auto *A = new (Ctx) OMPReferencedVarAttr(Loc, Ctx, Ref, 0); | |||
6043 | A->setImplicit(true); | |||
6044 | return A; | |||
6045 | } | |||
6046 | ||||
6047 | OMPReferencedVarAttr(SourceRange R, ASTContext &Ctx | |||
6048 | , Expr * Ref | |||
6049 | , unsigned SI | |||
6050 | ) | |||
6051 | : Attr(attr::OMPReferencedVar, R, SI, false) | |||
6052 | , ref(Ref) | |||
6053 | { | |||
6054 | } | |||
6055 | ||||
6056 | OMPReferencedVarAttr *clone(ASTContext &C) const; | |||
6057 | void printPretty(raw_ostream &OS, | |||
6058 | const PrintingPolicy &Policy) const; | |||
6059 | const char *getSpelling() const; | |||
6060 | Expr * getRef() const { | |||
6061 | return ref; | |||
6062 | } | |||
6063 | ||||
6064 | ||||
6065 | ||||
6066 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPReferencedVar; } | |||
6067 | }; | |||
6068 | ||||
6069 | class OMPThreadPrivateDeclAttr : public InheritableAttr { | |||
6070 | public: | |||
6071 | static OMPThreadPrivateDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6072 | auto *A = new (Ctx) OMPThreadPrivateDeclAttr(Loc, Ctx, 0); | |||
6073 | A->setImplicit(true); | |||
6074 | return A; | |||
6075 | } | |||
6076 | ||||
6077 | OMPThreadPrivateDeclAttr(SourceRange R, ASTContext &Ctx | |||
6078 | , unsigned SI | |||
6079 | ) | |||
6080 | : InheritableAttr(attr::OMPThreadPrivateDecl, R, SI, false, false) | |||
6081 | { | |||
6082 | } | |||
6083 | ||||
6084 | OMPThreadPrivateDeclAttr *clone(ASTContext &C) const; | |||
6085 | void printPretty(raw_ostream &OS, | |||
6086 | const PrintingPolicy &Policy) const; | |||
6087 | const char *getSpelling() const; | |||
6088 | ||||
6089 | ||||
6090 | static bool classof(const Attr *A) { return A->getKind() == attr::OMPThreadPrivateDecl; } | |||
6091 | }; | |||
6092 | ||||
6093 | class OSConsumedAttr : public InheritableParamAttr { | |||
6094 | public: | |||
6095 | static OSConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6096 | auto *A = new (Ctx) OSConsumedAttr(Loc, Ctx, 0); | |||
6097 | A->setImplicit(true); | |||
6098 | return A; | |||
6099 | } | |||
6100 | ||||
6101 | OSConsumedAttr(SourceRange R, ASTContext &Ctx | |||
6102 | , unsigned SI | |||
6103 | ) | |||
6104 | : InheritableParamAttr(attr::OSConsumed, R, SI, false, false) | |||
6105 | { | |||
6106 | } | |||
6107 | ||||
6108 | OSConsumedAttr *clone(ASTContext &C) const; | |||
6109 | void printPretty(raw_ostream &OS, | |||
6110 | const PrintingPolicy &Policy) const; | |||
6111 | const char *getSpelling() const; | |||
6112 | ||||
6113 | ||||
6114 | static bool classof(const Attr *A) { return A->getKind() == attr::OSConsumed; } | |||
6115 | }; | |||
6116 | ||||
6117 | class OSConsumesThisAttr : public InheritableAttr { | |||
6118 | public: | |||
6119 | static OSConsumesThisAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6120 | auto *A = new (Ctx) OSConsumesThisAttr(Loc, Ctx, 0); | |||
6121 | A->setImplicit(true); | |||
6122 | return A; | |||
6123 | } | |||
6124 | ||||
6125 | OSConsumesThisAttr(SourceRange R, ASTContext &Ctx | |||
6126 | , unsigned SI | |||
6127 | ) | |||
6128 | : InheritableAttr(attr::OSConsumesThis, R, SI, false, false) | |||
6129 | { | |||
6130 | } | |||
6131 | ||||
6132 | OSConsumesThisAttr *clone(ASTContext &C) const; | |||
6133 | void printPretty(raw_ostream &OS, | |||
6134 | const PrintingPolicy &Policy) const; | |||
6135 | const char *getSpelling() const; | |||
6136 | ||||
6137 | ||||
6138 | static bool classof(const Attr *A) { return A->getKind() == attr::OSConsumesThis; } | |||
6139 | }; | |||
6140 | ||||
6141 | class OSReturnsNotRetainedAttr : public InheritableAttr { | |||
6142 | public: | |||
6143 | static OSReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6144 | auto *A = new (Ctx) OSReturnsNotRetainedAttr(Loc, Ctx, 0); | |||
6145 | A->setImplicit(true); | |||
6146 | return A; | |||
6147 | } | |||
6148 | ||||
6149 | OSReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx | |||
6150 | , unsigned SI | |||
6151 | ) | |||
6152 | : InheritableAttr(attr::OSReturnsNotRetained, R, SI, false, false) | |||
6153 | { | |||
6154 | } | |||
6155 | ||||
6156 | OSReturnsNotRetainedAttr *clone(ASTContext &C) const; | |||
6157 | void printPretty(raw_ostream &OS, | |||
6158 | const PrintingPolicy &Policy) const; | |||
6159 | const char *getSpelling() const; | |||
6160 | ||||
6161 | ||||
6162 | static bool classof(const Attr *A) { return A->getKind() == attr::OSReturnsNotRetained; } | |||
6163 | }; | |||
6164 | ||||
6165 | class OSReturnsRetainedAttr : public InheritableAttr { | |||
6166 | public: | |||
6167 | static OSReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6168 | auto *A = new (Ctx) OSReturnsRetainedAttr(Loc, Ctx, 0); | |||
6169 | A->setImplicit(true); | |||
6170 | return A; | |||
6171 | } | |||
6172 | ||||
6173 | OSReturnsRetainedAttr(SourceRange R, ASTContext &Ctx | |||
6174 | , unsigned SI | |||
6175 | ) | |||
6176 | : InheritableAttr(attr::OSReturnsRetained, R, SI, false, false) | |||
6177 | { | |||
6178 | } | |||
6179 | ||||
6180 | OSReturnsRetainedAttr *clone(ASTContext &C) const; | |||
6181 | void printPretty(raw_ostream &OS, | |||
6182 | const PrintingPolicy &Policy) const; | |||
6183 | const char *getSpelling() const; | |||
6184 | ||||
6185 | ||||
6186 | static bool classof(const Attr *A) { return A->getKind() == attr::OSReturnsRetained; } | |||
6187 | }; | |||
6188 | ||||
6189 | class OSReturnsRetainedOnNonZeroAttr : public InheritableAttr { | |||
6190 | public: | |||
6191 | static OSReturnsRetainedOnNonZeroAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6192 | auto *A = new (Ctx) OSReturnsRetainedOnNonZeroAttr(Loc, Ctx, 0); | |||
6193 | A->setImplicit(true); | |||
6194 | return A; | |||
6195 | } | |||
6196 | ||||
6197 | OSReturnsRetainedOnNonZeroAttr(SourceRange R, ASTContext &Ctx | |||
6198 | , unsigned SI | |||
6199 | ) | |||
6200 | : InheritableAttr(attr::OSReturnsRetainedOnNonZero, R, SI, false, false) | |||
6201 | { | |||
6202 | } | |||
6203 | ||||
6204 | OSReturnsRetainedOnNonZeroAttr *clone(ASTContext &C) const; | |||
6205 | void printPretty(raw_ostream &OS, | |||
6206 | const PrintingPolicy &Policy) const; | |||
6207 | const char *getSpelling() const; | |||
6208 | ||||
6209 | ||||
6210 | static bool classof(const Attr *A) { return A->getKind() == attr::OSReturnsRetainedOnNonZero; } | |||
6211 | }; | |||
6212 | ||||
6213 | class OSReturnsRetainedOnZeroAttr : public InheritableAttr { | |||
6214 | public: | |||
6215 | static OSReturnsRetainedOnZeroAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6216 | auto *A = new (Ctx) OSReturnsRetainedOnZeroAttr(Loc, Ctx, 0); | |||
6217 | A->setImplicit(true); | |||
6218 | return A; | |||
6219 | } | |||
6220 | ||||
6221 | OSReturnsRetainedOnZeroAttr(SourceRange R, ASTContext &Ctx | |||
6222 | , unsigned SI | |||
6223 | ) | |||
6224 | : InheritableAttr(attr::OSReturnsRetainedOnZero, R, SI, false, false) | |||
6225 | { | |||
6226 | } | |||
6227 | ||||
6228 | OSReturnsRetainedOnZeroAttr *clone(ASTContext &C) const; | |||
6229 | void printPretty(raw_ostream &OS, | |||
6230 | const PrintingPolicy &Policy) const; | |||
6231 | const char *getSpelling() const; | |||
6232 | ||||
6233 | ||||
6234 | static bool classof(const Attr *A) { return A->getKind() == attr::OSReturnsRetainedOnZero; } | |||
6235 | }; | |||
6236 | ||||
6237 | class ObjCBoxableAttr : public Attr { | |||
6238 | public: | |||
6239 | static ObjCBoxableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6240 | auto *A = new (Ctx) ObjCBoxableAttr(Loc, Ctx, 0); | |||
6241 | A->setImplicit(true); | |||
6242 | return A; | |||
6243 | } | |||
6244 | ||||
6245 | ObjCBoxableAttr(SourceRange R, ASTContext &Ctx | |||
6246 | , unsigned SI | |||
6247 | ) | |||
6248 | : Attr(attr::ObjCBoxable, R, SI, false) | |||
6249 | { | |||
6250 | } | |||
6251 | ||||
6252 | ObjCBoxableAttr *clone(ASTContext &C) const; | |||
6253 | void printPretty(raw_ostream &OS, | |||
6254 | const PrintingPolicy &Policy) const; | |||
6255 | const char *getSpelling() const; | |||
6256 | ||||
6257 | ||||
6258 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBoxable; } | |||
6259 | }; | |||
6260 | ||||
6261 | class ObjCBridgeAttr : public InheritableAttr { | |||
6262 | IdentifierInfo * bridgedType; | |||
6263 | ||||
6264 | public: | |||
6265 | static ObjCBridgeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * BridgedType, SourceRange Loc = SourceRange()) { | |||
6266 | auto *A = new (Ctx) ObjCBridgeAttr(Loc, Ctx, BridgedType, 0); | |||
6267 | A->setImplicit(true); | |||
6268 | return A; | |||
6269 | } | |||
6270 | ||||
6271 | ObjCBridgeAttr(SourceRange R, ASTContext &Ctx | |||
6272 | , IdentifierInfo * BridgedType | |||
6273 | , unsigned SI | |||
6274 | ) | |||
6275 | : InheritableAttr(attr::ObjCBridge, R, SI, false, false) | |||
6276 | , bridgedType(BridgedType) | |||
6277 | { | |||
6278 | } | |||
6279 | ||||
6280 | ObjCBridgeAttr *clone(ASTContext &C) const; | |||
6281 | void printPretty(raw_ostream &OS, | |||
6282 | const PrintingPolicy &Policy) const; | |||
6283 | const char *getSpelling() const; | |||
6284 | IdentifierInfo * getBridgedType() const { | |||
6285 | return bridgedType; | |||
6286 | } | |||
6287 | ||||
6288 | ||||
6289 | ||||
6290 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridge; } | |||
6291 | }; | |||
6292 | ||||
6293 | class ObjCBridgeMutableAttr : public InheritableAttr { | |||
6294 | IdentifierInfo * bridgedType; | |||
6295 | ||||
6296 | public: | |||
6297 | static ObjCBridgeMutableAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * BridgedType, SourceRange Loc = SourceRange()) { | |||
6298 | auto *A = new (Ctx) ObjCBridgeMutableAttr(Loc, Ctx, BridgedType, 0); | |||
6299 | A->setImplicit(true); | |||
6300 | return A; | |||
6301 | } | |||
6302 | ||||
6303 | ObjCBridgeMutableAttr(SourceRange R, ASTContext &Ctx | |||
6304 | , IdentifierInfo * BridgedType | |||
6305 | , unsigned SI | |||
6306 | ) | |||
6307 | : InheritableAttr(attr::ObjCBridgeMutable, R, SI, false, false) | |||
6308 | , bridgedType(BridgedType) | |||
6309 | { | |||
6310 | } | |||
6311 | ||||
6312 | ObjCBridgeMutableAttr *clone(ASTContext &C) const; | |||
6313 | void printPretty(raw_ostream &OS, | |||
6314 | const PrintingPolicy &Policy) const; | |||
6315 | const char *getSpelling() const; | |||
6316 | IdentifierInfo * getBridgedType() const { | |||
6317 | return bridgedType; | |||
6318 | } | |||
6319 | ||||
6320 | ||||
6321 | ||||
6322 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridgeMutable; } | |||
6323 | }; | |||
6324 | ||||
6325 | class ObjCBridgeRelatedAttr : public InheritableAttr { | |||
6326 | IdentifierInfo * relatedClass; | |||
6327 | ||||
6328 | IdentifierInfo * classMethod; | |||
6329 | ||||
6330 | IdentifierInfo * instanceMethod; | |||
6331 | ||||
6332 | public: | |||
6333 | static ObjCBridgeRelatedAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * RelatedClass, IdentifierInfo * ClassMethod, IdentifierInfo * InstanceMethod, SourceRange Loc = SourceRange()) { | |||
6334 | auto *A = new (Ctx) ObjCBridgeRelatedAttr(Loc, Ctx, RelatedClass, ClassMethod, InstanceMethod, 0); | |||
6335 | A->setImplicit(true); | |||
6336 | return A; | |||
6337 | } | |||
6338 | ||||
6339 | ObjCBridgeRelatedAttr(SourceRange R, ASTContext &Ctx | |||
6340 | , IdentifierInfo * RelatedClass | |||
6341 | , IdentifierInfo * ClassMethod | |||
6342 | , IdentifierInfo * InstanceMethod | |||
6343 | , unsigned SI | |||
6344 | ) | |||
6345 | : InheritableAttr(attr::ObjCBridgeRelated, R, SI, false, false) | |||
6346 | , relatedClass(RelatedClass) | |||
6347 | , classMethod(ClassMethod) | |||
6348 | , instanceMethod(InstanceMethod) | |||
6349 | { | |||
6350 | } | |||
6351 | ||||
6352 | ObjCBridgeRelatedAttr *clone(ASTContext &C) const; | |||
6353 | void printPretty(raw_ostream &OS, | |||
6354 | const PrintingPolicy &Policy) const; | |||
6355 | const char *getSpelling() const; | |||
6356 | IdentifierInfo * getRelatedClass() const { | |||
6357 | return relatedClass; | |||
6358 | } | |||
6359 | ||||
6360 | IdentifierInfo * getClassMethod() const { | |||
6361 | return classMethod; | |||
6362 | } | |||
6363 | ||||
6364 | IdentifierInfo * getInstanceMethod() const { | |||
6365 | return instanceMethod; | |||
6366 | } | |||
6367 | ||||
6368 | ||||
6369 | ||||
6370 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridgeRelated; } | |||
6371 | }; | |||
6372 | ||||
6373 | class ObjCClassStubAttr : public Attr { | |||
6374 | public: | |||
6375 | static ObjCClassStubAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6376 | auto *A = new (Ctx) ObjCClassStubAttr(Loc, Ctx, 0); | |||
6377 | A->setImplicit(true); | |||
6378 | return A; | |||
6379 | } | |||
6380 | ||||
6381 | ObjCClassStubAttr(SourceRange R, ASTContext &Ctx | |||
6382 | , unsigned SI | |||
6383 | ) | |||
6384 | : Attr(attr::ObjCClassStub, R, SI, false) | |||
6385 | { | |||
6386 | } | |||
6387 | ||||
6388 | ObjCClassStubAttr *clone(ASTContext &C) const; | |||
6389 | void printPretty(raw_ostream &OS, | |||
6390 | const PrintingPolicy &Policy) const; | |||
6391 | const char *getSpelling() const; | |||
6392 | ||||
6393 | ||||
6394 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCClassStub; } | |||
6395 | }; | |||
6396 | ||||
6397 | class ObjCDesignatedInitializerAttr : public Attr { | |||
6398 | public: | |||
6399 | static ObjCDesignatedInitializerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6400 | auto *A = new (Ctx) ObjCDesignatedInitializerAttr(Loc, Ctx, 0); | |||
6401 | A->setImplicit(true); | |||
6402 | return A; | |||
6403 | } | |||
6404 | ||||
6405 | ObjCDesignatedInitializerAttr(SourceRange R, ASTContext &Ctx | |||
6406 | , unsigned SI | |||
6407 | ) | |||
6408 | : Attr(attr::ObjCDesignatedInitializer, R, SI, false) | |||
6409 | { | |||
6410 | } | |||
6411 | ||||
6412 | ObjCDesignatedInitializerAttr *clone(ASTContext &C) const; | |||
6413 | void printPretty(raw_ostream &OS, | |||
6414 | const PrintingPolicy &Policy) const; | |||
6415 | const char *getSpelling() const; | |||
6416 | ||||
6417 | ||||
6418 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCDesignatedInitializer; } | |||
6419 | }; | |||
6420 | ||||
6421 | class ObjCExceptionAttr : public InheritableAttr { | |||
6422 | public: | |||
6423 | static ObjCExceptionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6424 | auto *A = new (Ctx) ObjCExceptionAttr(Loc, Ctx, 0); | |||
6425 | A->setImplicit(true); | |||
6426 | return A; | |||
6427 | } | |||
6428 | ||||
6429 | ObjCExceptionAttr(SourceRange R, ASTContext &Ctx | |||
6430 | , unsigned SI | |||
6431 | ) | |||
6432 | : InheritableAttr(attr::ObjCException, R, SI, false, false) | |||
6433 | { | |||
6434 | } | |||
6435 | ||||
6436 | ObjCExceptionAttr *clone(ASTContext &C) const; | |||
6437 | void printPretty(raw_ostream &OS, | |||
6438 | const PrintingPolicy &Policy) const; | |||
6439 | const char *getSpelling() const; | |||
6440 | ||||
6441 | ||||
6442 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCException; } | |||
6443 | }; | |||
6444 | ||||
6445 | class ObjCExplicitProtocolImplAttr : public InheritableAttr { | |||
6446 | public: | |||
6447 | static ObjCExplicitProtocolImplAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6448 | auto *A = new (Ctx) ObjCExplicitProtocolImplAttr(Loc, Ctx, 0); | |||
6449 | A->setImplicit(true); | |||
6450 | return A; | |||
6451 | } | |||
6452 | ||||
6453 | ObjCExplicitProtocolImplAttr(SourceRange R, ASTContext &Ctx | |||
6454 | , unsigned SI | |||
6455 | ) | |||
6456 | : InheritableAttr(attr::ObjCExplicitProtocolImpl, R, SI, false, false) | |||
6457 | { | |||
6458 | } | |||
6459 | ||||
6460 | ObjCExplicitProtocolImplAttr *clone(ASTContext &C) const; | |||
6461 | void printPretty(raw_ostream &OS, | |||
6462 | const PrintingPolicy &Policy) const; | |||
6463 | const char *getSpelling() const; | |||
6464 | ||||
6465 | ||||
6466 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCExplicitProtocolImpl; } | |||
6467 | }; | |||
6468 | ||||
6469 | class ObjCExternallyRetainedAttr : public InheritableAttr { | |||
6470 | public: | |||
6471 | static ObjCExternallyRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6472 | auto *A = new (Ctx) ObjCExternallyRetainedAttr(Loc, Ctx, 0); | |||
6473 | A->setImplicit(true); | |||
6474 | return A; | |||
6475 | } | |||
6476 | ||||
6477 | ObjCExternallyRetainedAttr(SourceRange R, ASTContext &Ctx | |||
6478 | , unsigned SI | |||
6479 | ) | |||
6480 | : InheritableAttr(attr::ObjCExternallyRetained, R, SI, false, false) | |||
6481 | { | |||
6482 | } | |||
6483 | ||||
6484 | ObjCExternallyRetainedAttr *clone(ASTContext &C) const; | |||
6485 | void printPretty(raw_ostream &OS, | |||
6486 | const PrintingPolicy &Policy) const; | |||
6487 | const char *getSpelling() const; | |||
6488 | ||||
6489 | ||||
6490 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCExternallyRetained; } | |||
6491 | }; | |||
6492 | ||||
6493 | class ObjCGCAttr : public TypeAttr { | |||
6494 | IdentifierInfo * kind; | |||
6495 | ||||
6496 | public: | |||
6497 | static ObjCGCAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Kind, SourceRange Loc = SourceRange()) { | |||
6498 | auto *A = new (Ctx) ObjCGCAttr(Loc, Ctx, Kind, 0); | |||
6499 | A->setImplicit(true); | |||
6500 | return A; | |||
6501 | } | |||
6502 | ||||
6503 | ObjCGCAttr(SourceRange R, ASTContext &Ctx | |||
6504 | , IdentifierInfo * Kind | |||
6505 | , unsigned SI | |||
6506 | ) | |||
6507 | : TypeAttr(attr::ObjCGC, R, SI, false) | |||
6508 | , kind(Kind) | |||
6509 | { | |||
6510 | } | |||
6511 | ||||
6512 | ObjCGCAttr *clone(ASTContext &C) const; | |||
6513 | void printPretty(raw_ostream &OS, | |||
6514 | const PrintingPolicy &Policy) const; | |||
6515 | const char *getSpelling() const; | |||
6516 | IdentifierInfo * getKind() const { | |||
6517 | return kind; | |||
6518 | } | |||
6519 | ||||
6520 | ||||
6521 | ||||
6522 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCGC; } | |||
6523 | }; | |||
6524 | ||||
6525 | class ObjCIndependentClassAttr : public InheritableAttr { | |||
6526 | public: | |||
6527 | static ObjCIndependentClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6528 | auto *A = new (Ctx) ObjCIndependentClassAttr(Loc, Ctx, 0); | |||
6529 | A->setImplicit(true); | |||
6530 | return A; | |||
6531 | } | |||
6532 | ||||
6533 | ObjCIndependentClassAttr(SourceRange R, ASTContext &Ctx | |||
6534 | , unsigned SI | |||
6535 | ) | |||
6536 | : InheritableAttr(attr::ObjCIndependentClass, R, SI, false, false) | |||
6537 | { | |||
6538 | } | |||
6539 | ||||
6540 | ObjCIndependentClassAttr *clone(ASTContext &C) const; | |||
6541 | void printPretty(raw_ostream &OS, | |||
6542 | const PrintingPolicy &Policy) const; | |||
6543 | const char *getSpelling() const; | |||
6544 | ||||
6545 | ||||
6546 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCIndependentClass; } | |||
6547 | }; | |||
6548 | ||||
6549 | class ObjCInertUnsafeUnretainedAttr : public TypeAttr { | |||
6550 | public: | |||
6551 | static ObjCInertUnsafeUnretainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6552 | auto *A = new (Ctx) ObjCInertUnsafeUnretainedAttr(Loc, Ctx, 0); | |||
6553 | A->setImplicit(true); | |||
6554 | return A; | |||
6555 | } | |||
6556 | ||||
6557 | ObjCInertUnsafeUnretainedAttr(SourceRange R, ASTContext &Ctx | |||
6558 | , unsigned SI | |||
6559 | ) | |||
6560 | : TypeAttr(attr::ObjCInertUnsafeUnretained, R, SI, false) | |||
6561 | { | |||
6562 | } | |||
6563 | ||||
6564 | ObjCInertUnsafeUnretainedAttr *clone(ASTContext &C) const; | |||
6565 | void printPretty(raw_ostream &OS, | |||
6566 | const PrintingPolicy &Policy) const; | |||
6567 | const char *getSpelling() const; | |||
6568 | ||||
6569 | ||||
6570 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCInertUnsafeUnretained; } | |||
6571 | }; | |||
6572 | ||||
6573 | class ObjCKindOfAttr : public TypeAttr { | |||
6574 | public: | |||
6575 | static ObjCKindOfAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6576 | auto *A = new (Ctx) ObjCKindOfAttr(Loc, Ctx, 0); | |||
6577 | A->setImplicit(true); | |||
6578 | return A; | |||
6579 | } | |||
6580 | ||||
6581 | ObjCKindOfAttr(SourceRange R, ASTContext &Ctx | |||
6582 | , unsigned SI | |||
6583 | ) | |||
6584 | : TypeAttr(attr::ObjCKindOf, R, SI, false) | |||
6585 | { | |||
6586 | } | |||
6587 | ||||
6588 | ObjCKindOfAttr *clone(ASTContext &C) const; | |||
6589 | void printPretty(raw_ostream &OS, | |||
6590 | const PrintingPolicy &Policy) const; | |||
6591 | const char *getSpelling() const; | |||
6592 | ||||
6593 | ||||
6594 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCKindOf; } | |||
6595 | }; | |||
6596 | ||||
6597 | class ObjCMethodFamilyAttr : public InheritableAttr { | |||
6598 | public: | |||
6599 | enum FamilyKind { | |||
6600 | OMF_None, | |||
6601 | OMF_alloc, | |||
6602 | OMF_copy, | |||
6603 | OMF_init, | |||
6604 | OMF_mutableCopy, | |||
6605 | OMF_new | |||
6606 | }; | |||
6607 | private: | |||
6608 | FamilyKind family; | |||
6609 | ||||
6610 | public: | |||
6611 | static ObjCMethodFamilyAttr *CreateImplicit(ASTContext &Ctx, FamilyKind Family, SourceRange Loc = SourceRange()) { | |||
6612 | auto *A = new (Ctx) ObjCMethodFamilyAttr(Loc, Ctx, Family, 0); | |||
6613 | A->setImplicit(true); | |||
6614 | return A; | |||
6615 | } | |||
6616 | ||||
6617 | ObjCMethodFamilyAttr(SourceRange R, ASTContext &Ctx | |||
6618 | , FamilyKind Family | |||
6619 | , unsigned SI | |||
6620 | ) | |||
6621 | : InheritableAttr(attr::ObjCMethodFamily, R, SI, false, false) | |||
6622 | , family(Family) | |||
6623 | { | |||
6624 | } | |||
6625 | ||||
6626 | ObjCMethodFamilyAttr *clone(ASTContext &C) const; | |||
6627 | void printPretty(raw_ostream &OS, | |||
6628 | const PrintingPolicy &Policy) const; | |||
6629 | const char *getSpelling() const; | |||
6630 | FamilyKind getFamily() const { | |||
6631 | return family; | |||
6632 | } | |||
6633 | ||||
6634 | static bool ConvertStrToFamilyKind(StringRef Val, FamilyKind &Out) { | |||
6635 | Optional<FamilyKind> R = llvm::StringSwitch<Optional<FamilyKind>>(Val) | |||
6636 | .Case("none", ObjCMethodFamilyAttr::OMF_None) | |||
6637 | .Case("alloc", ObjCMethodFamilyAttr::OMF_alloc) | |||
6638 | .Case("copy", ObjCMethodFamilyAttr::OMF_copy) | |||
6639 | .Case("init", ObjCMethodFamilyAttr::OMF_init) | |||
6640 | .Case("mutableCopy", ObjCMethodFamilyAttr::OMF_mutableCopy) | |||
6641 | .Case("new", ObjCMethodFamilyAttr::OMF_new) | |||
6642 | .Default(Optional<FamilyKind>()); | |||
6643 | if (R) { | |||
6644 | Out = *R; | |||
6645 | return true; | |||
6646 | } | |||
6647 | return false; | |||
6648 | } | |||
6649 | ||||
6650 | static const char *ConvertFamilyKindToStr(FamilyKind Val) { | |||
6651 | switch(Val) { | |||
6652 | case ObjCMethodFamilyAttr::OMF_None: return "none"; | |||
6653 | case ObjCMethodFamilyAttr::OMF_alloc: return "alloc"; | |||
6654 | case ObjCMethodFamilyAttr::OMF_copy: return "copy"; | |||
6655 | case ObjCMethodFamilyAttr::OMF_init: return "init"; | |||
6656 | case ObjCMethodFamilyAttr::OMF_mutableCopy: return "mutableCopy"; | |||
6657 | case ObjCMethodFamilyAttr::OMF_new: return "new"; | |||
6658 | } | |||
6659 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 6659); | |||
6660 | } | |||
6661 | ||||
6662 | ||||
6663 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCMethodFamily; } | |||
6664 | }; | |||
6665 | ||||
6666 | class ObjCNSObjectAttr : public InheritableAttr { | |||
6667 | public: | |||
6668 | static ObjCNSObjectAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6669 | auto *A = new (Ctx) ObjCNSObjectAttr(Loc, Ctx, 0); | |||
6670 | A->setImplicit(true); | |||
6671 | return A; | |||
6672 | } | |||
6673 | ||||
6674 | ObjCNSObjectAttr(SourceRange R, ASTContext &Ctx | |||
6675 | , unsigned SI | |||
6676 | ) | |||
6677 | : InheritableAttr(attr::ObjCNSObject, R, SI, false, false) | |||
6678 | { | |||
6679 | } | |||
6680 | ||||
6681 | ObjCNSObjectAttr *clone(ASTContext &C) const; | |||
6682 | void printPretty(raw_ostream &OS, | |||
6683 | const PrintingPolicy &Policy) const; | |||
6684 | const char *getSpelling() const; | |||
6685 | ||||
6686 | ||||
6687 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCNSObject; } | |||
6688 | }; | |||
6689 | ||||
6690 | class ObjCNonLazyClassAttr : public Attr { | |||
6691 | public: | |||
6692 | static ObjCNonLazyClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6693 | auto *A = new (Ctx) ObjCNonLazyClassAttr(Loc, Ctx, 0); | |||
6694 | A->setImplicit(true); | |||
6695 | return A; | |||
6696 | } | |||
6697 | ||||
6698 | ObjCNonLazyClassAttr(SourceRange R, ASTContext &Ctx | |||
6699 | , unsigned SI | |||
6700 | ) | |||
6701 | : Attr(attr::ObjCNonLazyClass, R, SI, false) | |||
6702 | { | |||
6703 | } | |||
6704 | ||||
6705 | ObjCNonLazyClassAttr *clone(ASTContext &C) const; | |||
6706 | void printPretty(raw_ostream &OS, | |||
6707 | const PrintingPolicy &Policy) const; | |||
6708 | const char *getSpelling() const; | |||
6709 | ||||
6710 | ||||
6711 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCNonLazyClass; } | |||
6712 | }; | |||
6713 | ||||
6714 | class ObjCOwnershipAttr : public InheritableAttr { | |||
6715 | IdentifierInfo * kind; | |||
6716 | ||||
6717 | public: | |||
6718 | static ObjCOwnershipAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Kind, SourceRange Loc = SourceRange()) { | |||
6719 | auto *A = new (Ctx) ObjCOwnershipAttr(Loc, Ctx, Kind, 0); | |||
6720 | A->setImplicit(true); | |||
6721 | return A; | |||
6722 | } | |||
6723 | ||||
6724 | ObjCOwnershipAttr(SourceRange R, ASTContext &Ctx | |||
6725 | , IdentifierInfo * Kind | |||
6726 | , unsigned SI | |||
6727 | ) | |||
6728 | : InheritableAttr(attr::ObjCOwnership, R, SI, false, false) | |||
6729 | , kind(Kind) | |||
6730 | { | |||
6731 | } | |||
6732 | ||||
6733 | ObjCOwnershipAttr *clone(ASTContext &C) const; | |||
6734 | void printPretty(raw_ostream &OS, | |||
6735 | const PrintingPolicy &Policy) const; | |||
6736 | const char *getSpelling() const; | |||
6737 | IdentifierInfo * getKind() const { | |||
6738 | return kind; | |||
6739 | } | |||
6740 | ||||
6741 | ||||
6742 | ||||
6743 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCOwnership; } | |||
6744 | }; | |||
6745 | ||||
6746 | class ObjCPreciseLifetimeAttr : public InheritableAttr { | |||
6747 | public: | |||
6748 | static ObjCPreciseLifetimeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6749 | auto *A = new (Ctx) ObjCPreciseLifetimeAttr(Loc, Ctx, 0); | |||
6750 | A->setImplicit(true); | |||
6751 | return A; | |||
6752 | } | |||
6753 | ||||
6754 | ObjCPreciseLifetimeAttr(SourceRange R, ASTContext &Ctx | |||
6755 | , unsigned SI | |||
6756 | ) | |||
6757 | : InheritableAttr(attr::ObjCPreciseLifetime, R, SI, false, false) | |||
6758 | { | |||
6759 | } | |||
6760 | ||||
6761 | ObjCPreciseLifetimeAttr *clone(ASTContext &C) const; | |||
6762 | void printPretty(raw_ostream &OS, | |||
6763 | const PrintingPolicy &Policy) const; | |||
6764 | const char *getSpelling() const; | |||
6765 | ||||
6766 | ||||
6767 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCPreciseLifetime; } | |||
6768 | }; | |||
6769 | ||||
6770 | class ObjCRequiresPropertyDefsAttr : public InheritableAttr { | |||
6771 | public: | |||
6772 | static ObjCRequiresPropertyDefsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6773 | auto *A = new (Ctx) ObjCRequiresPropertyDefsAttr(Loc, Ctx, 0); | |||
6774 | A->setImplicit(true); | |||
6775 | return A; | |||
6776 | } | |||
6777 | ||||
6778 | ObjCRequiresPropertyDefsAttr(SourceRange R, ASTContext &Ctx | |||
6779 | , unsigned SI | |||
6780 | ) | |||
6781 | : InheritableAttr(attr::ObjCRequiresPropertyDefs, R, SI, false, false) | |||
6782 | { | |||
6783 | } | |||
6784 | ||||
6785 | ObjCRequiresPropertyDefsAttr *clone(ASTContext &C) const; | |||
6786 | void printPretty(raw_ostream &OS, | |||
6787 | const PrintingPolicy &Policy) const; | |||
6788 | const char *getSpelling() const; | |||
6789 | ||||
6790 | ||||
6791 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRequiresPropertyDefs; } | |||
6792 | }; | |||
6793 | ||||
6794 | class ObjCRequiresSuperAttr : public InheritableAttr { | |||
6795 | public: | |||
6796 | static ObjCRequiresSuperAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6797 | auto *A = new (Ctx) ObjCRequiresSuperAttr(Loc, Ctx, 0); | |||
6798 | A->setImplicit(true); | |||
6799 | return A; | |||
6800 | } | |||
6801 | ||||
6802 | ObjCRequiresSuperAttr(SourceRange R, ASTContext &Ctx | |||
6803 | , unsigned SI | |||
6804 | ) | |||
6805 | : InheritableAttr(attr::ObjCRequiresSuper, R, SI, false, false) | |||
6806 | { | |||
6807 | } | |||
6808 | ||||
6809 | ObjCRequiresSuperAttr *clone(ASTContext &C) const; | |||
6810 | void printPretty(raw_ostream &OS, | |||
6811 | const PrintingPolicy &Policy) const; | |||
6812 | const char *getSpelling() const; | |||
6813 | ||||
6814 | ||||
6815 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRequiresSuper; } | |||
6816 | }; | |||
6817 | ||||
6818 | class ObjCReturnsInnerPointerAttr : public InheritableAttr { | |||
6819 | public: | |||
6820 | static ObjCReturnsInnerPointerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6821 | auto *A = new (Ctx) ObjCReturnsInnerPointerAttr(Loc, Ctx, 0); | |||
6822 | A->setImplicit(true); | |||
6823 | return A; | |||
6824 | } | |||
6825 | ||||
6826 | ObjCReturnsInnerPointerAttr(SourceRange R, ASTContext &Ctx | |||
6827 | , unsigned SI | |||
6828 | ) | |||
6829 | : InheritableAttr(attr::ObjCReturnsInnerPointer, R, SI, false, false) | |||
6830 | { | |||
6831 | } | |||
6832 | ||||
6833 | ObjCReturnsInnerPointerAttr *clone(ASTContext &C) const; | |||
6834 | void printPretty(raw_ostream &OS, | |||
6835 | const PrintingPolicy &Policy) const; | |||
6836 | const char *getSpelling() const; | |||
6837 | ||||
6838 | ||||
6839 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCReturnsInnerPointer; } | |||
6840 | }; | |||
6841 | ||||
6842 | class ObjCRootClassAttr : public InheritableAttr { | |||
6843 | public: | |||
6844 | static ObjCRootClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6845 | auto *A = new (Ctx) ObjCRootClassAttr(Loc, Ctx, 0); | |||
6846 | A->setImplicit(true); | |||
6847 | return A; | |||
6848 | } | |||
6849 | ||||
6850 | ObjCRootClassAttr(SourceRange R, ASTContext &Ctx | |||
6851 | , unsigned SI | |||
6852 | ) | |||
6853 | : InheritableAttr(attr::ObjCRootClass, R, SI, false, false) | |||
6854 | { | |||
6855 | } | |||
6856 | ||||
6857 | ObjCRootClassAttr *clone(ASTContext &C) const; | |||
6858 | void printPretty(raw_ostream &OS, | |||
6859 | const PrintingPolicy &Policy) const; | |||
6860 | const char *getSpelling() const; | |||
6861 | ||||
6862 | ||||
6863 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRootClass; } | |||
6864 | }; | |||
6865 | ||||
6866 | class ObjCRuntimeNameAttr : public Attr { | |||
6867 | unsigned metadataNameLength; | |||
6868 | char *metadataName; | |||
6869 | ||||
6870 | public: | |||
6871 | static ObjCRuntimeNameAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef MetadataName, SourceRange Loc = SourceRange()) { | |||
6872 | auto *A = new (Ctx) ObjCRuntimeNameAttr(Loc, Ctx, MetadataName, 0); | |||
6873 | A->setImplicit(true); | |||
6874 | return A; | |||
6875 | } | |||
6876 | ||||
6877 | ObjCRuntimeNameAttr(SourceRange R, ASTContext &Ctx | |||
6878 | , llvm::StringRef MetadataName | |||
6879 | , unsigned SI | |||
6880 | ) | |||
6881 | : Attr(attr::ObjCRuntimeName, R, SI, false) | |||
6882 | , metadataNameLength(MetadataName.size()),metadataName(new (Ctx, 1) char[metadataNameLength]) | |||
6883 | { | |||
6884 | if (!MetadataName.empty()) | |||
6885 | std::memcpy(metadataName, MetadataName.data(), metadataNameLength); | |||
6886 | } | |||
6887 | ||||
6888 | ObjCRuntimeNameAttr *clone(ASTContext &C) const; | |||
6889 | void printPretty(raw_ostream &OS, | |||
6890 | const PrintingPolicy &Policy) const; | |||
6891 | const char *getSpelling() const; | |||
6892 | llvm::StringRef getMetadataName() const { | |||
6893 | return llvm::StringRef(metadataName, metadataNameLength); | |||
6894 | } | |||
6895 | unsigned getMetadataNameLength() const { | |||
6896 | return metadataNameLength; | |||
6897 | } | |||
6898 | void setMetadataName(ASTContext &C, llvm::StringRef S) { | |||
6899 | metadataNameLength = S.size(); | |||
6900 | this->metadataName = new (C, 1) char [metadataNameLength]; | |||
6901 | if (!S.empty()) | |||
6902 | std::memcpy(this->metadataName, S.data(), metadataNameLength); | |||
6903 | } | |||
6904 | ||||
6905 | ||||
6906 | ||||
6907 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRuntimeName; } | |||
6908 | }; | |||
6909 | ||||
6910 | class ObjCRuntimeVisibleAttr : public Attr { | |||
6911 | public: | |||
6912 | static ObjCRuntimeVisibleAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6913 | auto *A = new (Ctx) ObjCRuntimeVisibleAttr(Loc, Ctx, 0); | |||
6914 | A->setImplicit(true); | |||
6915 | return A; | |||
6916 | } | |||
6917 | ||||
6918 | ObjCRuntimeVisibleAttr(SourceRange R, ASTContext &Ctx | |||
6919 | , unsigned SI | |||
6920 | ) | |||
6921 | : Attr(attr::ObjCRuntimeVisible, R, SI, false) | |||
6922 | { | |||
6923 | } | |||
6924 | ||||
6925 | ObjCRuntimeVisibleAttr *clone(ASTContext &C) const; | |||
6926 | void printPretty(raw_ostream &OS, | |||
6927 | const PrintingPolicy &Policy) const; | |||
6928 | const char *getSpelling() const; | |||
6929 | ||||
6930 | ||||
6931 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRuntimeVisible; } | |||
6932 | }; | |||
6933 | ||||
6934 | class ObjCSubclassingRestrictedAttr : public InheritableAttr { | |||
6935 | public: | |||
6936 | static ObjCSubclassingRestrictedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
6937 | auto *A = new (Ctx) ObjCSubclassingRestrictedAttr(Loc, Ctx, 0); | |||
6938 | A->setImplicit(true); | |||
6939 | return A; | |||
6940 | } | |||
6941 | ||||
6942 | ObjCSubclassingRestrictedAttr(SourceRange R, ASTContext &Ctx | |||
6943 | , unsigned SI | |||
6944 | ) | |||
6945 | : InheritableAttr(attr::ObjCSubclassingRestricted, R, SI, false, false) | |||
6946 | { | |||
6947 | } | |||
6948 | ||||
6949 | ObjCSubclassingRestrictedAttr *clone(ASTContext &C) const; | |||
6950 | void printPretty(raw_ostream &OS, | |||
6951 | const PrintingPolicy &Policy) const; | |||
6952 | const char *getSpelling() const; | |||
6953 | ||||
6954 | ||||
6955 | static bool classof(const Attr *A) { return A->getKind() == attr::ObjCSubclassingRestricted; } | |||
6956 | }; | |||
6957 | ||||
6958 | class OpenCLAccessAttr : public Attr { | |||
6959 | public: | |||
6960 | enum Spelling { | |||
6961 | Keyword_read_only = 0, | |||
6962 | Keyword_write_only = 2, | |||
6963 | Keyword_read_write = 4 | |||
6964 | }; | |||
6965 | ||||
6966 | static OpenCLAccessAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
6967 | auto *A = new (Ctx) OpenCLAccessAttr(Loc, Ctx, S); | |||
6968 | A->setImplicit(true); | |||
6969 | return A; | |||
6970 | } | |||
6971 | ||||
6972 | OpenCLAccessAttr(SourceRange R, ASTContext &Ctx | |||
6973 | , unsigned SI | |||
6974 | ) | |||
6975 | : Attr(attr::OpenCLAccess, R, SI, false) | |||
6976 | { | |||
6977 | } | |||
6978 | ||||
6979 | OpenCLAccessAttr *clone(ASTContext &C) const; | |||
6980 | void printPretty(raw_ostream &OS, | |||
6981 | const PrintingPolicy &Policy) const; | |||
6982 | const char *getSpelling() const; | |||
6983 | Spelling getSemanticSpelling() const { | |||
6984 | switch (SpellingListIndex) { | |||
6985 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 6985); | |||
6986 | case 0: return Keyword_read_only; | |||
6987 | case 1: return Keyword_read_only; | |||
6988 | case 2: return Keyword_write_only; | |||
6989 | case 3: return Keyword_write_only; | |||
6990 | case 4: return Keyword_read_write; | |||
6991 | case 5: return Keyword_read_write; | |||
6992 | } | |||
6993 | } | |||
6994 | bool isReadOnly() const { return SpellingListIndex == 0 || | |||
6995 | SpellingListIndex == 1; } | |||
6996 | bool isReadWrite() const { return SpellingListIndex == 4 || | |||
6997 | SpellingListIndex == 5; } | |||
6998 | bool isWriteOnly() const { return SpellingListIndex == 2 || | |||
6999 | SpellingListIndex == 3; } | |||
7000 | ||||
7001 | ||||
7002 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLAccess; } | |||
7003 | }; | |||
7004 | ||||
7005 | class OpenCLConstantAddressSpaceAttr : public TypeAttr { | |||
7006 | public: | |||
7007 | static OpenCLConstantAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7008 | auto *A = new (Ctx) OpenCLConstantAddressSpaceAttr(Loc, Ctx, 0); | |||
7009 | A->setImplicit(true); | |||
7010 | return A; | |||
7011 | } | |||
7012 | ||||
7013 | OpenCLConstantAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7014 | , unsigned SI | |||
7015 | ) | |||
7016 | : TypeAttr(attr::OpenCLConstantAddressSpace, R, SI, false) | |||
7017 | { | |||
7018 | } | |||
7019 | ||||
7020 | OpenCLConstantAddressSpaceAttr *clone(ASTContext &C) const; | |||
7021 | void printPretty(raw_ostream &OS, | |||
7022 | const PrintingPolicy &Policy) const; | |||
7023 | const char *getSpelling() const; | |||
7024 | ||||
7025 | ||||
7026 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLConstantAddressSpace; } | |||
7027 | }; | |||
7028 | ||||
7029 | class OpenCLGenericAddressSpaceAttr : public TypeAttr { | |||
7030 | public: | |||
7031 | static OpenCLGenericAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7032 | auto *A = new (Ctx) OpenCLGenericAddressSpaceAttr(Loc, Ctx, 0); | |||
7033 | A->setImplicit(true); | |||
7034 | return A; | |||
7035 | } | |||
7036 | ||||
7037 | OpenCLGenericAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7038 | , unsigned SI | |||
7039 | ) | |||
7040 | : TypeAttr(attr::OpenCLGenericAddressSpace, R, SI, false) | |||
7041 | { | |||
7042 | } | |||
7043 | ||||
7044 | OpenCLGenericAddressSpaceAttr *clone(ASTContext &C) const; | |||
7045 | void printPretty(raw_ostream &OS, | |||
7046 | const PrintingPolicy &Policy) const; | |||
7047 | const char *getSpelling() const; | |||
7048 | ||||
7049 | ||||
7050 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLGenericAddressSpace; } | |||
7051 | }; | |||
7052 | ||||
7053 | class OpenCLGlobalAddressSpaceAttr : public TypeAttr { | |||
7054 | public: | |||
7055 | static OpenCLGlobalAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7056 | auto *A = new (Ctx) OpenCLGlobalAddressSpaceAttr(Loc, Ctx, 0); | |||
7057 | A->setImplicit(true); | |||
7058 | return A; | |||
7059 | } | |||
7060 | ||||
7061 | OpenCLGlobalAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7062 | , unsigned SI | |||
7063 | ) | |||
7064 | : TypeAttr(attr::OpenCLGlobalAddressSpace, R, SI, false) | |||
7065 | { | |||
7066 | } | |||
7067 | ||||
7068 | OpenCLGlobalAddressSpaceAttr *clone(ASTContext &C) const; | |||
7069 | void printPretty(raw_ostream &OS, | |||
7070 | const PrintingPolicy &Policy) const; | |||
7071 | const char *getSpelling() const; | |||
7072 | ||||
7073 | ||||
7074 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLGlobalAddressSpace; } | |||
7075 | }; | |||
7076 | ||||
7077 | class OpenCLIntelReqdSubGroupSizeAttr : public InheritableAttr { | |||
7078 | unsigned subGroupSize; | |||
7079 | ||||
7080 | public: | |||
7081 | static OpenCLIntelReqdSubGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned SubGroupSize, SourceRange Loc = SourceRange()) { | |||
7082 | auto *A = new (Ctx) OpenCLIntelReqdSubGroupSizeAttr(Loc, Ctx, SubGroupSize, 0); | |||
7083 | A->setImplicit(true); | |||
7084 | return A; | |||
7085 | } | |||
7086 | ||||
7087 | OpenCLIntelReqdSubGroupSizeAttr(SourceRange R, ASTContext &Ctx | |||
7088 | , unsigned SubGroupSize | |||
7089 | , unsigned SI | |||
7090 | ) | |||
7091 | : InheritableAttr(attr::OpenCLIntelReqdSubGroupSize, R, SI, false, false) | |||
7092 | , subGroupSize(SubGroupSize) | |||
7093 | { | |||
7094 | } | |||
7095 | ||||
7096 | OpenCLIntelReqdSubGroupSizeAttr *clone(ASTContext &C) const; | |||
7097 | void printPretty(raw_ostream &OS, | |||
7098 | const PrintingPolicy &Policy) const; | |||
7099 | const char *getSpelling() const; | |||
7100 | unsigned getSubGroupSize() const { | |||
7101 | return subGroupSize; | |||
7102 | } | |||
7103 | ||||
7104 | ||||
7105 | ||||
7106 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLIntelReqdSubGroupSize; } | |||
7107 | }; | |||
7108 | ||||
7109 | class OpenCLKernelAttr : public InheritableAttr { | |||
7110 | public: | |||
7111 | static OpenCLKernelAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7112 | auto *A = new (Ctx) OpenCLKernelAttr(Loc, Ctx, 0); | |||
7113 | A->setImplicit(true); | |||
7114 | return A; | |||
7115 | } | |||
7116 | ||||
7117 | OpenCLKernelAttr(SourceRange R, ASTContext &Ctx | |||
7118 | , unsigned SI | |||
7119 | ) | |||
7120 | : InheritableAttr(attr::OpenCLKernel, R, SI, false, false) | |||
7121 | { | |||
7122 | } | |||
7123 | ||||
7124 | OpenCLKernelAttr *clone(ASTContext &C) const; | |||
7125 | void printPretty(raw_ostream &OS, | |||
7126 | const PrintingPolicy &Policy) const; | |||
7127 | const char *getSpelling() const; | |||
7128 | ||||
7129 | ||||
7130 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLKernel; } | |||
7131 | }; | |||
7132 | ||||
7133 | class OpenCLLocalAddressSpaceAttr : public TypeAttr { | |||
7134 | public: | |||
7135 | static OpenCLLocalAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7136 | auto *A = new (Ctx) OpenCLLocalAddressSpaceAttr(Loc, Ctx, 0); | |||
7137 | A->setImplicit(true); | |||
7138 | return A; | |||
7139 | } | |||
7140 | ||||
7141 | OpenCLLocalAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7142 | , unsigned SI | |||
7143 | ) | |||
7144 | : TypeAttr(attr::OpenCLLocalAddressSpace, R, SI, false) | |||
7145 | { | |||
7146 | } | |||
7147 | ||||
7148 | OpenCLLocalAddressSpaceAttr *clone(ASTContext &C) const; | |||
7149 | void printPretty(raw_ostream &OS, | |||
7150 | const PrintingPolicy &Policy) const; | |||
7151 | const char *getSpelling() const; | |||
7152 | ||||
7153 | ||||
7154 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLLocalAddressSpace; } | |||
7155 | }; | |||
7156 | ||||
7157 | class OpenCLPrivateAddressSpaceAttr : public TypeAttr { | |||
7158 | public: | |||
7159 | static OpenCLPrivateAddressSpaceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7160 | auto *A = new (Ctx) OpenCLPrivateAddressSpaceAttr(Loc, Ctx, 0); | |||
7161 | A->setImplicit(true); | |||
7162 | return A; | |||
7163 | } | |||
7164 | ||||
7165 | OpenCLPrivateAddressSpaceAttr(SourceRange R, ASTContext &Ctx | |||
7166 | , unsigned SI | |||
7167 | ) | |||
7168 | : TypeAttr(attr::OpenCLPrivateAddressSpace, R, SI, false) | |||
7169 | { | |||
7170 | } | |||
7171 | ||||
7172 | OpenCLPrivateAddressSpaceAttr *clone(ASTContext &C) const; | |||
7173 | void printPretty(raw_ostream &OS, | |||
7174 | const PrintingPolicy &Policy) const; | |||
7175 | const char *getSpelling() const; | |||
7176 | ||||
7177 | ||||
7178 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLPrivateAddressSpace; } | |||
7179 | }; | |||
7180 | ||||
7181 | class OpenCLUnrollHintAttr : public InheritableAttr { | |||
7182 | unsigned unrollHint; | |||
7183 | ||||
7184 | public: | |||
7185 | static OpenCLUnrollHintAttr *CreateImplicit(ASTContext &Ctx, unsigned UnrollHint, SourceRange Loc = SourceRange()) { | |||
7186 | auto *A = new (Ctx) OpenCLUnrollHintAttr(Loc, Ctx, UnrollHint, 0); | |||
7187 | A->setImplicit(true); | |||
7188 | return A; | |||
7189 | } | |||
7190 | ||||
7191 | OpenCLUnrollHintAttr(SourceRange R, ASTContext &Ctx | |||
7192 | , unsigned UnrollHint | |||
7193 | , unsigned SI | |||
7194 | ) | |||
7195 | : InheritableAttr(attr::OpenCLUnrollHint, R, SI, false, false) | |||
7196 | , unrollHint(UnrollHint) | |||
7197 | { | |||
7198 | } | |||
7199 | ||||
7200 | OpenCLUnrollHintAttr *clone(ASTContext &C) const; | |||
7201 | void printPretty(raw_ostream &OS, | |||
7202 | const PrintingPolicy &Policy) const; | |||
7203 | const char *getSpelling() const; | |||
7204 | unsigned getUnrollHint() const { | |||
7205 | return unrollHint; | |||
7206 | } | |||
7207 | ||||
7208 | ||||
7209 | ||||
7210 | static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLUnrollHint; } | |||
7211 | }; | |||
7212 | ||||
7213 | class OptimizeNoneAttr : public InheritableAttr { | |||
7214 | public: | |||
7215 | static OptimizeNoneAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7216 | auto *A = new (Ctx) OptimizeNoneAttr(Loc, Ctx, 0); | |||
7217 | A->setImplicit(true); | |||
7218 | return A; | |||
7219 | } | |||
7220 | ||||
7221 | OptimizeNoneAttr(SourceRange R, ASTContext &Ctx | |||
7222 | , unsigned SI | |||
7223 | ) | |||
7224 | : InheritableAttr(attr::OptimizeNone, R, SI, false, false) | |||
7225 | { | |||
7226 | } | |||
7227 | ||||
7228 | OptimizeNoneAttr *clone(ASTContext &C) const; | |||
7229 | void printPretty(raw_ostream &OS, | |||
7230 | const PrintingPolicy &Policy) const; | |||
7231 | const char *getSpelling() const; | |||
7232 | ||||
7233 | ||||
7234 | static bool classof(const Attr *A) { return A->getKind() == attr::OptimizeNone; } | |||
7235 | }; | |||
7236 | ||||
7237 | class OverloadableAttr : public Attr { | |||
7238 | public: | |||
7239 | static OverloadableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7240 | auto *A = new (Ctx) OverloadableAttr(Loc, Ctx, 0); | |||
7241 | A->setImplicit(true); | |||
7242 | return A; | |||
7243 | } | |||
7244 | ||||
7245 | OverloadableAttr(SourceRange R, ASTContext &Ctx | |||
7246 | , unsigned SI | |||
7247 | ) | |||
7248 | : Attr(attr::Overloadable, R, SI, false) | |||
7249 | { | |||
7250 | } | |||
7251 | ||||
7252 | OverloadableAttr *clone(ASTContext &C) const; | |||
7253 | void printPretty(raw_ostream &OS, | |||
7254 | const PrintingPolicy &Policy) const; | |||
7255 | const char *getSpelling() const; | |||
7256 | ||||
7257 | ||||
7258 | static bool classof(const Attr *A) { return A->getKind() == attr::Overloadable; } | |||
7259 | }; | |||
7260 | ||||
7261 | class OverrideAttr : public InheritableAttr { | |||
7262 | public: | |||
7263 | static OverrideAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7264 | auto *A = new (Ctx) OverrideAttr(Loc, Ctx, 0); | |||
7265 | A->setImplicit(true); | |||
7266 | return A; | |||
7267 | } | |||
7268 | ||||
7269 | OverrideAttr(SourceRange R, ASTContext &Ctx | |||
7270 | , unsigned SI | |||
7271 | ) | |||
7272 | : InheritableAttr(attr::Override, R, SI, false, false) | |||
7273 | { | |||
7274 | } | |||
7275 | ||||
7276 | OverrideAttr *clone(ASTContext &C) const; | |||
7277 | void printPretty(raw_ostream &OS, | |||
7278 | const PrintingPolicy &Policy) const; | |||
7279 | const char *getSpelling() const; | |||
7280 | ||||
7281 | ||||
7282 | static bool classof(const Attr *A) { return A->getKind() == attr::Override; } | |||
7283 | }; | |||
7284 | ||||
7285 | class OwnershipAttr : public InheritableAttr { | |||
7286 | IdentifierInfo * module; | |||
7287 | ||||
7288 | unsigned args_Size; | |||
7289 | ParamIdx *args_; | |||
7290 | ||||
7291 | public: | |||
7292 | enum Spelling { | |||
7293 | GNU_ownership_holds = 0, | |||
7294 | CXX11_clang_ownership_holds = 1, | |||
7295 | C2x_clang_ownership_holds = 2, | |||
7296 | GNU_ownership_returns = 3, | |||
7297 | CXX11_clang_ownership_returns = 4, | |||
7298 | C2x_clang_ownership_returns = 5, | |||
7299 | GNU_ownership_takes = 6, | |||
7300 | CXX11_clang_ownership_takes = 7, | |||
7301 | C2x_clang_ownership_takes = 8 | |||
7302 | }; | |||
7303 | ||||
7304 | static OwnershipAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * Module, ParamIdx *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
7305 | auto *A = new (Ctx) OwnershipAttr(Loc, Ctx, Module, Args, ArgsSize, S); | |||
7306 | A->setImplicit(true); | |||
7307 | return A; | |||
7308 | } | |||
7309 | ||||
7310 | OwnershipAttr(SourceRange R, ASTContext &Ctx | |||
7311 | , IdentifierInfo * Module | |||
7312 | , ParamIdx *Args, unsigned ArgsSize | |||
7313 | , unsigned SI | |||
7314 | ) | |||
7315 | : InheritableAttr(attr::Ownership, R, SI, false, false) | |||
7316 | , module(Module) | |||
7317 | , args_Size(ArgsSize), args_(new (Ctx, 16) ParamIdx[args_Size]) | |||
7318 | { | |||
7319 | std::copy(Args, Args + args_Size, args_); | |||
7320 | } | |||
7321 | ||||
7322 | OwnershipAttr(SourceRange R, ASTContext &Ctx | |||
7323 | , IdentifierInfo * Module | |||
7324 | , unsigned SI | |||
7325 | ) | |||
7326 | : InheritableAttr(attr::Ownership, R, SI, false, false) | |||
7327 | , module(Module) | |||
7328 | , args_Size(0), args_(nullptr) | |||
7329 | { | |||
7330 | } | |||
7331 | ||||
7332 | OwnershipAttr *clone(ASTContext &C) const; | |||
7333 | void printPretty(raw_ostream &OS, | |||
7334 | const PrintingPolicy &Policy) const; | |||
7335 | const char *getSpelling() const; | |||
7336 | Spelling getSemanticSpelling() const { | |||
7337 | switch (SpellingListIndex) { | |||
7338 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 7338); | |||
7339 | case 0: return GNU_ownership_holds; | |||
7340 | case 1: return CXX11_clang_ownership_holds; | |||
7341 | case 2: return C2x_clang_ownership_holds; | |||
7342 | case 3: return GNU_ownership_returns; | |||
7343 | case 4: return CXX11_clang_ownership_returns; | |||
7344 | case 5: return C2x_clang_ownership_returns; | |||
7345 | case 6: return GNU_ownership_takes; | |||
7346 | case 7: return CXX11_clang_ownership_takes; | |||
7347 | case 8: return C2x_clang_ownership_takes; | |||
7348 | } | |||
7349 | } | |||
7350 | bool isHolds() const { return SpellingListIndex == 0 || | |||
7351 | SpellingListIndex == 1 || | |||
7352 | SpellingListIndex == 2; } | |||
7353 | bool isReturns() const { return SpellingListIndex == 3 || | |||
7354 | SpellingListIndex == 4 || | |||
7355 | SpellingListIndex == 5; } | |||
7356 | bool isTakes() const { return SpellingListIndex == 6 || | |||
7357 | SpellingListIndex == 7 || | |||
7358 | SpellingListIndex == 8; } | |||
7359 | IdentifierInfo * getModule() const { | |||
7360 | return module; | |||
7361 | } | |||
7362 | ||||
7363 | typedef ParamIdx* args_iterator; | |||
7364 | args_iterator args_begin() const { return args_; } | |||
7365 | args_iterator args_end() const { return args_ + args_Size; } | |||
7366 | unsigned args_size() const { return args_Size; } | |||
7367 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
7368 | ||||
7369 | ||||
7370 | ||||
7371 | enum OwnershipKind { Holds, Returns, Takes }; | |||
7372 | OwnershipKind getOwnKind() const { | |||
7373 | return isHolds() ? Holds : | |||
7374 | isTakes() ? Takes : | |||
7375 | Returns; | |||
7376 | } | |||
7377 | ||||
7378 | ||||
7379 | static bool classof(const Attr *A) { return A->getKind() == attr::Ownership; } | |||
7380 | }; | |||
7381 | ||||
7382 | class PackedAttr : public InheritableAttr { | |||
7383 | public: | |||
7384 | static PackedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7385 | auto *A = new (Ctx) PackedAttr(Loc, Ctx, 0); | |||
7386 | A->setImplicit(true); | |||
7387 | return A; | |||
7388 | } | |||
7389 | ||||
7390 | PackedAttr(SourceRange R, ASTContext &Ctx | |||
7391 | , unsigned SI | |||
7392 | ) | |||
7393 | : InheritableAttr(attr::Packed, R, SI, false, false) | |||
7394 | { | |||
7395 | } | |||
7396 | ||||
7397 | PackedAttr *clone(ASTContext &C) const; | |||
7398 | void printPretty(raw_ostream &OS, | |||
7399 | const PrintingPolicy &Policy) const; | |||
7400 | const char *getSpelling() const; | |||
7401 | ||||
7402 | ||||
7403 | static bool classof(const Attr *A) { return A->getKind() == attr::Packed; } | |||
7404 | }; | |||
7405 | ||||
7406 | class ParamTypestateAttr : public InheritableAttr { | |||
7407 | public: | |||
7408 | enum ConsumedState { | |||
7409 | Unknown, | |||
7410 | Consumed, | |||
7411 | Unconsumed | |||
7412 | }; | |||
7413 | private: | |||
7414 | ConsumedState paramState; | |||
7415 | ||||
7416 | public: | |||
7417 | static ParamTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState ParamState, SourceRange Loc = SourceRange()) { | |||
7418 | auto *A = new (Ctx) ParamTypestateAttr(Loc, Ctx, ParamState, 0); | |||
7419 | A->setImplicit(true); | |||
7420 | return A; | |||
7421 | } | |||
7422 | ||||
7423 | ParamTypestateAttr(SourceRange R, ASTContext &Ctx | |||
7424 | , ConsumedState ParamState | |||
7425 | , unsigned SI | |||
7426 | ) | |||
7427 | : InheritableAttr(attr::ParamTypestate, R, SI, false, false) | |||
7428 | , paramState(ParamState) | |||
7429 | { | |||
7430 | } | |||
7431 | ||||
7432 | ParamTypestateAttr *clone(ASTContext &C) const; | |||
7433 | void printPretty(raw_ostream &OS, | |||
7434 | const PrintingPolicy &Policy) const; | |||
7435 | const char *getSpelling() const; | |||
7436 | ConsumedState getParamState() const { | |||
7437 | return paramState; | |||
7438 | } | |||
7439 | ||||
7440 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
7441 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
7442 | .Case("unknown", ParamTypestateAttr::Unknown) | |||
7443 | .Case("consumed", ParamTypestateAttr::Consumed) | |||
7444 | .Case("unconsumed", ParamTypestateAttr::Unconsumed) | |||
7445 | .Default(Optional<ConsumedState>()); | |||
7446 | if (R) { | |||
7447 | Out = *R; | |||
7448 | return true; | |||
7449 | } | |||
7450 | return false; | |||
7451 | } | |||
7452 | ||||
7453 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
7454 | switch(Val) { | |||
7455 | case ParamTypestateAttr::Unknown: return "unknown"; | |||
7456 | case ParamTypestateAttr::Consumed: return "consumed"; | |||
7457 | case ParamTypestateAttr::Unconsumed: return "unconsumed"; | |||
7458 | } | |||
7459 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 7459); | |||
7460 | } | |||
7461 | ||||
7462 | ||||
7463 | static bool classof(const Attr *A) { return A->getKind() == attr::ParamTypestate; } | |||
7464 | }; | |||
7465 | ||||
7466 | class PascalAttr : public InheritableAttr { | |||
7467 | public: | |||
7468 | static PascalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7469 | auto *A = new (Ctx) PascalAttr(Loc, Ctx, 0); | |||
7470 | A->setImplicit(true); | |||
7471 | return A; | |||
7472 | } | |||
7473 | ||||
7474 | PascalAttr(SourceRange R, ASTContext &Ctx | |||
7475 | , unsigned SI | |||
7476 | ) | |||
7477 | : InheritableAttr(attr::Pascal, R, SI, false, false) | |||
7478 | { | |||
7479 | } | |||
7480 | ||||
7481 | PascalAttr *clone(ASTContext &C) const; | |||
7482 | void printPretty(raw_ostream &OS, | |||
7483 | const PrintingPolicy &Policy) const; | |||
7484 | const char *getSpelling() const; | |||
7485 | ||||
7486 | ||||
7487 | static bool classof(const Attr *A) { return A->getKind() == attr::Pascal; } | |||
7488 | }; | |||
7489 | ||||
7490 | class PassObjectSizeAttr : public InheritableParamAttr { | |||
7491 | int type; | |||
7492 | ||||
7493 | public: | |||
7494 | enum Spelling { | |||
7495 | GNU_pass_object_size = 0, | |||
7496 | CXX11_clang_pass_object_size = 1, | |||
7497 | C2x_clang_pass_object_size = 2, | |||
7498 | GNU_pass_dynamic_object_size = 3, | |||
7499 | CXX11_clang_pass_dynamic_object_size = 4, | |||
7500 | C2x_clang_pass_dynamic_object_size = 5 | |||
7501 | }; | |||
7502 | ||||
7503 | static PassObjectSizeAttr *CreateImplicit(ASTContext &Ctx, Spelling S, int Type, SourceRange Loc = SourceRange()) { | |||
7504 | auto *A = new (Ctx) PassObjectSizeAttr(Loc, Ctx, Type, S); | |||
7505 | A->setImplicit(true); | |||
7506 | return A; | |||
7507 | } | |||
7508 | ||||
7509 | PassObjectSizeAttr(SourceRange R, ASTContext &Ctx | |||
7510 | , int Type | |||
7511 | , unsigned SI | |||
7512 | ) | |||
7513 | : InheritableParamAttr(attr::PassObjectSize, R, SI, false, false) | |||
7514 | , type(Type) | |||
7515 | { | |||
7516 | } | |||
7517 | ||||
7518 | PassObjectSizeAttr *clone(ASTContext &C) const; | |||
7519 | void printPretty(raw_ostream &OS, | |||
7520 | const PrintingPolicy &Policy) const; | |||
7521 | const char *getSpelling() const; | |||
7522 | Spelling getSemanticSpelling() const { | |||
7523 | switch (SpellingListIndex) { | |||
7524 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 7524); | |||
7525 | case 0: return GNU_pass_object_size; | |||
7526 | case 1: return CXX11_clang_pass_object_size; | |||
7527 | case 2: return C2x_clang_pass_object_size; | |||
7528 | case 3: return GNU_pass_dynamic_object_size; | |||
7529 | case 4: return CXX11_clang_pass_dynamic_object_size; | |||
7530 | case 5: return C2x_clang_pass_dynamic_object_size; | |||
7531 | } | |||
7532 | } | |||
7533 | bool isDynamic() const { return SpellingListIndex == 3 || | |||
7534 | SpellingListIndex == 4 || | |||
7535 | SpellingListIndex == 5; } | |||
7536 | int getType() const { | |||
7537 | return type; | |||
7538 | } | |||
7539 | ||||
7540 | ||||
7541 | ||||
7542 | static bool classof(const Attr *A) { return A->getKind() == attr::PassObjectSize; } | |||
7543 | }; | |||
7544 | ||||
7545 | class PcsAttr : public InheritableAttr { | |||
7546 | public: | |||
7547 | enum PCSType { | |||
7548 | AAPCS, | |||
7549 | AAPCS_VFP | |||
7550 | }; | |||
7551 | private: | |||
7552 | PCSType pCS; | |||
7553 | ||||
7554 | public: | |||
7555 | static PcsAttr *CreateImplicit(ASTContext &Ctx, PCSType PCS, SourceRange Loc = SourceRange()) { | |||
7556 | auto *A = new (Ctx) PcsAttr(Loc, Ctx, PCS, 0); | |||
7557 | A->setImplicit(true); | |||
7558 | return A; | |||
7559 | } | |||
7560 | ||||
7561 | PcsAttr(SourceRange R, ASTContext &Ctx | |||
7562 | , PCSType PCS | |||
7563 | , unsigned SI | |||
7564 | ) | |||
7565 | : InheritableAttr(attr::Pcs, R, SI, false, false) | |||
7566 | , pCS(PCS) | |||
7567 | { | |||
7568 | } | |||
7569 | ||||
7570 | PcsAttr *clone(ASTContext &C) const; | |||
7571 | void printPretty(raw_ostream &OS, | |||
7572 | const PrintingPolicy &Policy) const; | |||
7573 | const char *getSpelling() const; | |||
7574 | PCSType getPCS() const { | |||
7575 | return pCS; | |||
7576 | } | |||
7577 | ||||
7578 | static bool ConvertStrToPCSType(StringRef Val, PCSType &Out) { | |||
7579 | Optional<PCSType> R = llvm::StringSwitch<Optional<PCSType>>(Val) | |||
7580 | .Case("aapcs", PcsAttr::AAPCS) | |||
7581 | .Case("aapcs-vfp", PcsAttr::AAPCS_VFP) | |||
7582 | .Default(Optional<PCSType>()); | |||
7583 | if (R) { | |||
7584 | Out = *R; | |||
7585 | return true; | |||
7586 | } | |||
7587 | return false; | |||
7588 | } | |||
7589 | ||||
7590 | static const char *ConvertPCSTypeToStr(PCSType Val) { | |||
7591 | switch(Val) { | |||
7592 | case PcsAttr::AAPCS: return "aapcs"; | |||
7593 | case PcsAttr::AAPCS_VFP: return "aapcs-vfp"; | |||
7594 | } | |||
7595 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 7595); | |||
7596 | } | |||
7597 | ||||
7598 | ||||
7599 | static bool classof(const Attr *A) { return A->getKind() == attr::Pcs; } | |||
7600 | }; | |||
7601 | ||||
7602 | class PragmaClangBSSSectionAttr : public InheritableAttr { | |||
7603 | unsigned nameLength; | |||
7604 | char *name; | |||
7605 | ||||
7606 | public: | |||
7607 | static PragmaClangBSSSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
7608 | auto *A = new (Ctx) PragmaClangBSSSectionAttr(Loc, Ctx, Name, 0); | |||
7609 | A->setImplicit(true); | |||
7610 | return A; | |||
7611 | } | |||
7612 | ||||
7613 | PragmaClangBSSSectionAttr(SourceRange R, ASTContext &Ctx | |||
7614 | , llvm::StringRef Name | |||
7615 | , unsigned SI | |||
7616 | ) | |||
7617 | : InheritableAttr(attr::PragmaClangBSSSection, R, SI, false, false) | |||
7618 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
7619 | { | |||
7620 | if (!Name.empty()) | |||
7621 | std::memcpy(name, Name.data(), nameLength); | |||
7622 | } | |||
7623 | ||||
7624 | PragmaClangBSSSectionAttr *clone(ASTContext &C) const; | |||
7625 | void printPretty(raw_ostream &OS, | |||
7626 | const PrintingPolicy &Policy) const; | |||
7627 | const char *getSpelling() const; | |||
7628 | llvm::StringRef getName() const { | |||
7629 | return llvm::StringRef(name, nameLength); | |||
7630 | } | |||
7631 | unsigned getNameLength() const { | |||
7632 | return nameLength; | |||
7633 | } | |||
7634 | void setName(ASTContext &C, llvm::StringRef S) { | |||
7635 | nameLength = S.size(); | |||
7636 | this->name = new (C, 1) char [nameLength]; | |||
7637 | if (!S.empty()) | |||
7638 | std::memcpy(this->name, S.data(), nameLength); | |||
7639 | } | |||
7640 | ||||
7641 | ||||
7642 | ||||
7643 | static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangBSSSection; } | |||
7644 | }; | |||
7645 | ||||
7646 | class PragmaClangDataSectionAttr : public InheritableAttr { | |||
7647 | unsigned nameLength; | |||
7648 | char *name; | |||
7649 | ||||
7650 | public: | |||
7651 | static PragmaClangDataSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
7652 | auto *A = new (Ctx) PragmaClangDataSectionAttr(Loc, Ctx, Name, 0); | |||
7653 | A->setImplicit(true); | |||
7654 | return A; | |||
7655 | } | |||
7656 | ||||
7657 | PragmaClangDataSectionAttr(SourceRange R, ASTContext &Ctx | |||
7658 | , llvm::StringRef Name | |||
7659 | , unsigned SI | |||
7660 | ) | |||
7661 | : InheritableAttr(attr::PragmaClangDataSection, R, SI, false, false) | |||
7662 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
7663 | { | |||
7664 | if (!Name.empty()) | |||
7665 | std::memcpy(name, Name.data(), nameLength); | |||
7666 | } | |||
7667 | ||||
7668 | PragmaClangDataSectionAttr *clone(ASTContext &C) const; | |||
7669 | void printPretty(raw_ostream &OS, | |||
7670 | const PrintingPolicy &Policy) const; | |||
7671 | const char *getSpelling() const; | |||
7672 | llvm::StringRef getName() const { | |||
7673 | return llvm::StringRef(name, nameLength); | |||
7674 | } | |||
7675 | unsigned getNameLength() const { | |||
7676 | return nameLength; | |||
7677 | } | |||
7678 | void setName(ASTContext &C, llvm::StringRef S) { | |||
7679 | nameLength = S.size(); | |||
7680 | this->name = new (C, 1) char [nameLength]; | |||
7681 | if (!S.empty()) | |||
7682 | std::memcpy(this->name, S.data(), nameLength); | |||
7683 | } | |||
7684 | ||||
7685 | ||||
7686 | ||||
7687 | static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangDataSection; } | |||
7688 | }; | |||
7689 | ||||
7690 | class PragmaClangRodataSectionAttr : public InheritableAttr { | |||
7691 | unsigned nameLength; | |||
7692 | char *name; | |||
7693 | ||||
7694 | public: | |||
7695 | static PragmaClangRodataSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
7696 | auto *A = new (Ctx) PragmaClangRodataSectionAttr(Loc, Ctx, Name, 0); | |||
7697 | A->setImplicit(true); | |||
7698 | return A; | |||
7699 | } | |||
7700 | ||||
7701 | PragmaClangRodataSectionAttr(SourceRange R, ASTContext &Ctx | |||
7702 | , llvm::StringRef Name | |||
7703 | , unsigned SI | |||
7704 | ) | |||
7705 | : InheritableAttr(attr::PragmaClangRodataSection, R, SI, false, false) | |||
7706 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
7707 | { | |||
7708 | if (!Name.empty()) | |||
7709 | std::memcpy(name, Name.data(), nameLength); | |||
7710 | } | |||
7711 | ||||
7712 | PragmaClangRodataSectionAttr *clone(ASTContext &C) const; | |||
7713 | void printPretty(raw_ostream &OS, | |||
7714 | const PrintingPolicy &Policy) const; | |||
7715 | const char *getSpelling() const; | |||
7716 | llvm::StringRef getName() const { | |||
7717 | return llvm::StringRef(name, nameLength); | |||
7718 | } | |||
7719 | unsigned getNameLength() const { | |||
7720 | return nameLength; | |||
7721 | } | |||
7722 | void setName(ASTContext &C, llvm::StringRef S) { | |||
7723 | nameLength = S.size(); | |||
7724 | this->name = new (C, 1) char [nameLength]; | |||
7725 | if (!S.empty()) | |||
7726 | std::memcpy(this->name, S.data(), nameLength); | |||
7727 | } | |||
7728 | ||||
7729 | ||||
7730 | ||||
7731 | static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangRodataSection; } | |||
7732 | }; | |||
7733 | ||||
7734 | class PragmaClangTextSectionAttr : public InheritableAttr { | |||
7735 | unsigned nameLength; | |||
7736 | char *name; | |||
7737 | ||||
7738 | public: | |||
7739 | static PragmaClangTextSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
7740 | auto *A = new (Ctx) PragmaClangTextSectionAttr(Loc, Ctx, Name, 0); | |||
7741 | A->setImplicit(true); | |||
7742 | return A; | |||
7743 | } | |||
7744 | ||||
7745 | PragmaClangTextSectionAttr(SourceRange R, ASTContext &Ctx | |||
7746 | , llvm::StringRef Name | |||
7747 | , unsigned SI | |||
7748 | ) | |||
7749 | : InheritableAttr(attr::PragmaClangTextSection, R, SI, false, false) | |||
7750 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
7751 | { | |||
7752 | if (!Name.empty()) | |||
7753 | std::memcpy(name, Name.data(), nameLength); | |||
7754 | } | |||
7755 | ||||
7756 | PragmaClangTextSectionAttr *clone(ASTContext &C) const; | |||
7757 | void printPretty(raw_ostream &OS, | |||
7758 | const PrintingPolicy &Policy) const; | |||
7759 | const char *getSpelling() const; | |||
7760 | llvm::StringRef getName() const { | |||
7761 | return llvm::StringRef(name, nameLength); | |||
7762 | } | |||
7763 | unsigned getNameLength() const { | |||
7764 | return nameLength; | |||
7765 | } | |||
7766 | void setName(ASTContext &C, llvm::StringRef S) { | |||
7767 | nameLength = S.size(); | |||
7768 | this->name = new (C, 1) char [nameLength]; | |||
7769 | if (!S.empty()) | |||
7770 | std::memcpy(this->name, S.data(), nameLength); | |||
7771 | } | |||
7772 | ||||
7773 | ||||
7774 | ||||
7775 | static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangTextSection; } | |||
7776 | }; | |||
7777 | ||||
7778 | class PreserveAllAttr : public InheritableAttr { | |||
7779 | public: | |||
7780 | static PreserveAllAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7781 | auto *A = new (Ctx) PreserveAllAttr(Loc, Ctx, 0); | |||
7782 | A->setImplicit(true); | |||
7783 | return A; | |||
7784 | } | |||
7785 | ||||
7786 | PreserveAllAttr(SourceRange R, ASTContext &Ctx | |||
7787 | , unsigned SI | |||
7788 | ) | |||
7789 | : InheritableAttr(attr::PreserveAll, R, SI, false, false) | |||
7790 | { | |||
7791 | } | |||
7792 | ||||
7793 | PreserveAllAttr *clone(ASTContext &C) const; | |||
7794 | void printPretty(raw_ostream &OS, | |||
7795 | const PrintingPolicy &Policy) const; | |||
7796 | const char *getSpelling() const; | |||
7797 | ||||
7798 | ||||
7799 | static bool classof(const Attr *A) { return A->getKind() == attr::PreserveAll; } | |||
7800 | }; | |||
7801 | ||||
7802 | class PreserveMostAttr : public InheritableAttr { | |||
7803 | public: | |||
7804 | static PreserveMostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7805 | auto *A = new (Ctx) PreserveMostAttr(Loc, Ctx, 0); | |||
7806 | A->setImplicit(true); | |||
7807 | return A; | |||
7808 | } | |||
7809 | ||||
7810 | PreserveMostAttr(SourceRange R, ASTContext &Ctx | |||
7811 | , unsigned SI | |||
7812 | ) | |||
7813 | : InheritableAttr(attr::PreserveMost, R, SI, false, false) | |||
7814 | { | |||
7815 | } | |||
7816 | ||||
7817 | PreserveMostAttr *clone(ASTContext &C) const; | |||
7818 | void printPretty(raw_ostream &OS, | |||
7819 | const PrintingPolicy &Policy) const; | |||
7820 | const char *getSpelling() const; | |||
7821 | ||||
7822 | ||||
7823 | static bool classof(const Attr *A) { return A->getKind() == attr::PreserveMost; } | |||
7824 | }; | |||
7825 | ||||
7826 | class PtGuardedByAttr : public InheritableAttr { | |||
7827 | Expr * arg; | |||
7828 | ||||
7829 | public: | |||
7830 | static PtGuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) { | |||
7831 | auto *A = new (Ctx) PtGuardedByAttr(Loc, Ctx, Arg, 0); | |||
7832 | A->setImplicit(true); | |||
7833 | return A; | |||
7834 | } | |||
7835 | ||||
7836 | PtGuardedByAttr(SourceRange R, ASTContext &Ctx | |||
7837 | , Expr * Arg | |||
7838 | , unsigned SI | |||
7839 | ) | |||
7840 | : InheritableAttr(attr::PtGuardedBy, R, SI, true, true) | |||
7841 | , arg(Arg) | |||
7842 | { | |||
7843 | } | |||
7844 | ||||
7845 | PtGuardedByAttr *clone(ASTContext &C) const; | |||
7846 | void printPretty(raw_ostream &OS, | |||
7847 | const PrintingPolicy &Policy) const; | |||
7848 | const char *getSpelling() const; | |||
7849 | Expr * getArg() const { | |||
7850 | return arg; | |||
7851 | } | |||
7852 | ||||
7853 | ||||
7854 | ||||
7855 | static bool classof(const Attr *A) { return A->getKind() == attr::PtGuardedBy; } | |||
7856 | }; | |||
7857 | ||||
7858 | class PtGuardedVarAttr : public InheritableAttr { | |||
7859 | public: | |||
7860 | static PtGuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7861 | auto *A = new (Ctx) PtGuardedVarAttr(Loc, Ctx, 0); | |||
7862 | A->setImplicit(true); | |||
7863 | return A; | |||
7864 | } | |||
7865 | ||||
7866 | PtGuardedVarAttr(SourceRange R, ASTContext &Ctx | |||
7867 | , unsigned SI | |||
7868 | ) | |||
7869 | : InheritableAttr(attr::PtGuardedVar, R, SI, false, false) | |||
7870 | { | |||
7871 | } | |||
7872 | ||||
7873 | PtGuardedVarAttr *clone(ASTContext &C) const; | |||
7874 | void printPretty(raw_ostream &OS, | |||
7875 | const PrintingPolicy &Policy) const; | |||
7876 | const char *getSpelling() const; | |||
7877 | ||||
7878 | ||||
7879 | static bool classof(const Attr *A) { return A->getKind() == attr::PtGuardedVar; } | |||
7880 | }; | |||
7881 | ||||
7882 | class Ptr32Attr : public TypeAttr { | |||
7883 | public: | |||
7884 | static Ptr32Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7885 | auto *A = new (Ctx) Ptr32Attr(Loc, Ctx, 0); | |||
7886 | A->setImplicit(true); | |||
7887 | return A; | |||
7888 | } | |||
7889 | ||||
7890 | Ptr32Attr(SourceRange R, ASTContext &Ctx | |||
7891 | , unsigned SI | |||
7892 | ) | |||
7893 | : TypeAttr(attr::Ptr32, R, SI, false) | |||
7894 | { | |||
7895 | } | |||
7896 | ||||
7897 | Ptr32Attr *clone(ASTContext &C) const; | |||
7898 | void printPretty(raw_ostream &OS, | |||
7899 | const PrintingPolicy &Policy) const; | |||
7900 | const char *getSpelling() const; | |||
7901 | ||||
7902 | ||||
7903 | static bool classof(const Attr *A) { return A->getKind() == attr::Ptr32; } | |||
7904 | }; | |||
7905 | ||||
7906 | class Ptr64Attr : public TypeAttr { | |||
7907 | public: | |||
7908 | static Ptr64Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7909 | auto *A = new (Ctx) Ptr64Attr(Loc, Ctx, 0); | |||
7910 | A->setImplicit(true); | |||
7911 | return A; | |||
7912 | } | |||
7913 | ||||
7914 | Ptr64Attr(SourceRange R, ASTContext &Ctx | |||
7915 | , unsigned SI | |||
7916 | ) | |||
7917 | : TypeAttr(attr::Ptr64, R, SI, false) | |||
7918 | { | |||
7919 | } | |||
7920 | ||||
7921 | Ptr64Attr *clone(ASTContext &C) const; | |||
7922 | void printPretty(raw_ostream &OS, | |||
7923 | const PrintingPolicy &Policy) const; | |||
7924 | const char *getSpelling() const; | |||
7925 | ||||
7926 | ||||
7927 | static bool classof(const Attr *A) { return A->getKind() == attr::Ptr64; } | |||
7928 | }; | |||
7929 | ||||
7930 | class PureAttr : public InheritableAttr { | |||
7931 | public: | |||
7932 | static PureAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
7933 | auto *A = new (Ctx) PureAttr(Loc, Ctx, 0); | |||
7934 | A->setImplicit(true); | |||
7935 | return A; | |||
7936 | } | |||
7937 | ||||
7938 | PureAttr(SourceRange R, ASTContext &Ctx | |||
7939 | , unsigned SI | |||
7940 | ) | |||
7941 | : InheritableAttr(attr::Pure, R, SI, false, false) | |||
7942 | { | |||
7943 | } | |||
7944 | ||||
7945 | PureAttr *clone(ASTContext &C) const; | |||
7946 | void printPretty(raw_ostream &OS, | |||
7947 | const PrintingPolicy &Policy) const; | |||
7948 | const char *getSpelling() const; | |||
7949 | ||||
7950 | ||||
7951 | static bool classof(const Attr *A) { return A->getKind() == attr::Pure; } | |||
7952 | }; | |||
7953 | ||||
7954 | class RISCVInterruptAttr : public InheritableAttr { | |||
7955 | public: | |||
7956 | enum InterruptType { | |||
7957 | user, | |||
7958 | supervisor, | |||
7959 | machine | |||
7960 | }; | |||
7961 | private: | |||
7962 | InterruptType interrupt; | |||
7963 | ||||
7964 | public: | |||
7965 | static RISCVInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) { | |||
7966 | auto *A = new (Ctx) RISCVInterruptAttr(Loc, Ctx, Interrupt, 0); | |||
7967 | A->setImplicit(true); | |||
7968 | return A; | |||
7969 | } | |||
7970 | ||||
7971 | RISCVInterruptAttr(SourceRange R, ASTContext &Ctx | |||
7972 | , InterruptType Interrupt | |||
7973 | , unsigned SI | |||
7974 | ) | |||
7975 | : InheritableAttr(attr::RISCVInterrupt, R, SI, false, false) | |||
7976 | , interrupt(Interrupt) | |||
7977 | { | |||
7978 | } | |||
7979 | ||||
7980 | RISCVInterruptAttr(SourceRange R, ASTContext &Ctx | |||
7981 | , unsigned SI | |||
7982 | ) | |||
7983 | : InheritableAttr(attr::RISCVInterrupt, R, SI, false, false) | |||
7984 | , interrupt(InterruptType(0)) | |||
7985 | { | |||
7986 | } | |||
7987 | ||||
7988 | RISCVInterruptAttr *clone(ASTContext &C) const; | |||
7989 | void printPretty(raw_ostream &OS, | |||
7990 | const PrintingPolicy &Policy) const; | |||
7991 | const char *getSpelling() const; | |||
7992 | InterruptType getInterrupt() const { | |||
7993 | return interrupt; | |||
7994 | } | |||
7995 | ||||
7996 | static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) { | |||
7997 | Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val) | |||
7998 | .Case("user", RISCVInterruptAttr::user) | |||
7999 | .Case("supervisor", RISCVInterruptAttr::supervisor) | |||
8000 | .Case("machine", RISCVInterruptAttr::machine) | |||
8001 | .Default(Optional<InterruptType>()); | |||
8002 | if (R) { | |||
8003 | Out = *R; | |||
8004 | return true; | |||
8005 | } | |||
8006 | return false; | |||
8007 | } | |||
8008 | ||||
8009 | static const char *ConvertInterruptTypeToStr(InterruptType Val) { | |||
8010 | switch(Val) { | |||
8011 | case RISCVInterruptAttr::user: return "user"; | |||
8012 | case RISCVInterruptAttr::supervisor: return "supervisor"; | |||
8013 | case RISCVInterruptAttr::machine: return "machine"; | |||
8014 | } | |||
8015 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8015); | |||
8016 | } | |||
8017 | ||||
8018 | ||||
8019 | static bool classof(const Attr *A) { return A->getKind() == attr::RISCVInterrupt; } | |||
8020 | }; | |||
8021 | ||||
8022 | class RegCallAttr : public InheritableAttr { | |||
8023 | public: | |||
8024 | static RegCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8025 | auto *A = new (Ctx) RegCallAttr(Loc, Ctx, 0); | |||
8026 | A->setImplicit(true); | |||
8027 | return A; | |||
8028 | } | |||
8029 | ||||
8030 | RegCallAttr(SourceRange R, ASTContext &Ctx | |||
8031 | , unsigned SI | |||
8032 | ) | |||
8033 | : InheritableAttr(attr::RegCall, R, SI, false, false) | |||
8034 | { | |||
8035 | } | |||
8036 | ||||
8037 | RegCallAttr *clone(ASTContext &C) const; | |||
8038 | void printPretty(raw_ostream &OS, | |||
8039 | const PrintingPolicy &Policy) const; | |||
8040 | const char *getSpelling() const; | |||
8041 | ||||
8042 | ||||
8043 | static bool classof(const Attr *A) { return A->getKind() == attr::RegCall; } | |||
8044 | }; | |||
8045 | ||||
8046 | class ReinitializesAttr : public InheritableAttr { | |||
8047 | public: | |||
8048 | static ReinitializesAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8049 | auto *A = new (Ctx) ReinitializesAttr(Loc, Ctx, 0); | |||
8050 | A->setImplicit(true); | |||
8051 | return A; | |||
8052 | } | |||
8053 | ||||
8054 | ReinitializesAttr(SourceRange R, ASTContext &Ctx | |||
8055 | , unsigned SI | |||
8056 | ) | |||
8057 | : InheritableAttr(attr::Reinitializes, R, SI, false, false) | |||
8058 | { | |||
8059 | } | |||
8060 | ||||
8061 | ReinitializesAttr *clone(ASTContext &C) const; | |||
8062 | void printPretty(raw_ostream &OS, | |||
8063 | const PrintingPolicy &Policy) const; | |||
8064 | const char *getSpelling() const; | |||
8065 | ||||
8066 | ||||
8067 | static bool classof(const Attr *A) { return A->getKind() == attr::Reinitializes; } | |||
8068 | }; | |||
8069 | ||||
8070 | class ReleaseCapabilityAttr : public InheritableAttr { | |||
8071 | unsigned args_Size; | |||
8072 | Expr * *args_; | |||
8073 | ||||
8074 | public: | |||
8075 | enum Spelling { | |||
8076 | GNU_release_capability = 0, | |||
8077 | CXX11_clang_release_capability = 1, | |||
8078 | GNU_release_shared_capability = 2, | |||
8079 | CXX11_clang_release_shared_capability = 3, | |||
8080 | GNU_release_generic_capability = 4, | |||
8081 | CXX11_clang_release_generic_capability = 5, | |||
8082 | GNU_unlock_function = 6, | |||
8083 | CXX11_clang_unlock_function = 7 | |||
8084 | }; | |||
8085 | ||||
8086 | static ReleaseCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
8087 | auto *A = new (Ctx) ReleaseCapabilityAttr(Loc, Ctx, Args, ArgsSize, S); | |||
8088 | A->setImplicit(true); | |||
8089 | return A; | |||
8090 | } | |||
8091 | ||||
8092 | ReleaseCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
8093 | , Expr * *Args, unsigned ArgsSize | |||
8094 | , unsigned SI | |||
8095 | ) | |||
8096 | : InheritableAttr(attr::ReleaseCapability, R, SI, true, true) | |||
8097 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
8098 | { | |||
8099 | std::copy(Args, Args + args_Size, args_); | |||
8100 | } | |||
8101 | ||||
8102 | ReleaseCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
8103 | , unsigned SI | |||
8104 | ) | |||
8105 | : InheritableAttr(attr::ReleaseCapability, R, SI, true, true) | |||
8106 | , args_Size(0), args_(nullptr) | |||
8107 | { | |||
8108 | } | |||
8109 | ||||
8110 | ReleaseCapabilityAttr *clone(ASTContext &C) const; | |||
8111 | void printPretty(raw_ostream &OS, | |||
8112 | const PrintingPolicy &Policy) const; | |||
8113 | const char *getSpelling() const; | |||
8114 | Spelling getSemanticSpelling() const { | |||
8115 | switch (SpellingListIndex) { | |||
8116 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8116); | |||
8117 | case 0: return GNU_release_capability; | |||
8118 | case 1: return CXX11_clang_release_capability; | |||
8119 | case 2: return GNU_release_shared_capability; | |||
8120 | case 3: return CXX11_clang_release_shared_capability; | |||
8121 | case 4: return GNU_release_generic_capability; | |||
8122 | case 5: return CXX11_clang_release_generic_capability; | |||
8123 | case 6: return GNU_unlock_function; | |||
8124 | case 7: return CXX11_clang_unlock_function; | |||
8125 | } | |||
8126 | } | |||
8127 | bool isShared() const { return SpellingListIndex == 2 || | |||
8128 | SpellingListIndex == 3; } | |||
8129 | bool isGeneric() const { return SpellingListIndex == 4 || | |||
8130 | SpellingListIndex == 5 || | |||
8131 | SpellingListIndex == 6 || | |||
8132 | SpellingListIndex == 7; } | |||
8133 | typedef Expr ** args_iterator; | |||
8134 | args_iterator args_begin() const { return args_; } | |||
8135 | args_iterator args_end() const { return args_ + args_Size; } | |||
8136 | unsigned args_size() const { return args_Size; } | |||
8137 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
8138 | ||||
8139 | ||||
8140 | ||||
8141 | ||||
8142 | static bool classof(const Attr *A) { return A->getKind() == attr::ReleaseCapability; } | |||
8143 | }; | |||
8144 | ||||
8145 | class RenderScriptKernelAttr : public Attr { | |||
8146 | public: | |||
8147 | static RenderScriptKernelAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8148 | auto *A = new (Ctx) RenderScriptKernelAttr(Loc, Ctx, 0); | |||
8149 | A->setImplicit(true); | |||
8150 | return A; | |||
8151 | } | |||
8152 | ||||
8153 | RenderScriptKernelAttr(SourceRange R, ASTContext &Ctx | |||
8154 | , unsigned SI | |||
8155 | ) | |||
8156 | : Attr(attr::RenderScriptKernel, R, SI, false) | |||
8157 | { | |||
8158 | } | |||
8159 | ||||
8160 | RenderScriptKernelAttr *clone(ASTContext &C) const; | |||
8161 | void printPretty(raw_ostream &OS, | |||
8162 | const PrintingPolicy &Policy) const; | |||
8163 | const char *getSpelling() const; | |||
8164 | ||||
8165 | ||||
8166 | static bool classof(const Attr *A) { return A->getKind() == attr::RenderScriptKernel; } | |||
8167 | }; | |||
8168 | ||||
8169 | class ReqdWorkGroupSizeAttr : public InheritableAttr { | |||
8170 | unsigned xDim; | |||
8171 | ||||
8172 | unsigned yDim; | |||
8173 | ||||
8174 | unsigned zDim; | |||
8175 | ||||
8176 | public: | |||
8177 | static ReqdWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned XDim, unsigned YDim, unsigned ZDim, SourceRange Loc = SourceRange()) { | |||
8178 | auto *A = new (Ctx) ReqdWorkGroupSizeAttr(Loc, Ctx, XDim, YDim, ZDim, 0); | |||
8179 | A->setImplicit(true); | |||
8180 | return A; | |||
8181 | } | |||
8182 | ||||
8183 | ReqdWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx | |||
8184 | , unsigned XDim | |||
8185 | , unsigned YDim | |||
8186 | , unsigned ZDim | |||
8187 | , unsigned SI | |||
8188 | ) | |||
8189 | : InheritableAttr(attr::ReqdWorkGroupSize, R, SI, false, false) | |||
8190 | , xDim(XDim) | |||
8191 | , yDim(YDim) | |||
8192 | , zDim(ZDim) | |||
8193 | { | |||
8194 | } | |||
8195 | ||||
8196 | ReqdWorkGroupSizeAttr *clone(ASTContext &C) const; | |||
8197 | void printPretty(raw_ostream &OS, | |||
8198 | const PrintingPolicy &Policy) const; | |||
8199 | const char *getSpelling() const; | |||
8200 | unsigned getXDim() const { | |||
8201 | return xDim; | |||
8202 | } | |||
8203 | ||||
8204 | unsigned getYDim() const { | |||
8205 | return yDim; | |||
8206 | } | |||
8207 | ||||
8208 | unsigned getZDim() const { | |||
8209 | return zDim; | |||
8210 | } | |||
8211 | ||||
8212 | ||||
8213 | ||||
8214 | static bool classof(const Attr *A) { return A->getKind() == attr::ReqdWorkGroupSize; } | |||
8215 | }; | |||
8216 | ||||
8217 | class RequireConstantInitAttr : public InheritableAttr { | |||
8218 | public: | |||
8219 | static RequireConstantInitAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8220 | auto *A = new (Ctx) RequireConstantInitAttr(Loc, Ctx, 0); | |||
8221 | A->setImplicit(true); | |||
8222 | return A; | |||
8223 | } | |||
8224 | ||||
8225 | RequireConstantInitAttr(SourceRange R, ASTContext &Ctx | |||
8226 | , unsigned SI | |||
8227 | ) | |||
8228 | : InheritableAttr(attr::RequireConstantInit, R, SI, false, false) | |||
8229 | { | |||
8230 | } | |||
8231 | ||||
8232 | RequireConstantInitAttr *clone(ASTContext &C) const; | |||
8233 | void printPretty(raw_ostream &OS, | |||
8234 | const PrintingPolicy &Policy) const; | |||
8235 | const char *getSpelling() const; | |||
8236 | ||||
8237 | ||||
8238 | static bool classof(const Attr *A) { return A->getKind() == attr::RequireConstantInit; } | |||
8239 | }; | |||
8240 | ||||
8241 | class RequiresCapabilityAttr : public InheritableAttr { | |||
8242 | unsigned args_Size; | |||
8243 | Expr * *args_; | |||
8244 | ||||
8245 | public: | |||
8246 | enum Spelling { | |||
8247 | GNU_requires_capability = 0, | |||
8248 | CXX11_clang_requires_capability = 1, | |||
8249 | GNU_exclusive_locks_required = 2, | |||
8250 | CXX11_clang_exclusive_locks_required = 3, | |||
8251 | GNU_requires_shared_capability = 4, | |||
8252 | CXX11_clang_requires_shared_capability = 5, | |||
8253 | GNU_shared_locks_required = 6, | |||
8254 | CXX11_clang_shared_locks_required = 7 | |||
8255 | }; | |||
8256 | ||||
8257 | static RequiresCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
8258 | auto *A = new (Ctx) RequiresCapabilityAttr(Loc, Ctx, Args, ArgsSize, S); | |||
8259 | A->setImplicit(true); | |||
8260 | return A; | |||
8261 | } | |||
8262 | ||||
8263 | RequiresCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
8264 | , Expr * *Args, unsigned ArgsSize | |||
8265 | , unsigned SI | |||
8266 | ) | |||
8267 | : InheritableAttr(attr::RequiresCapability, R, SI, true, true) | |||
8268 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
8269 | { | |||
8270 | std::copy(Args, Args + args_Size, args_); | |||
8271 | } | |||
8272 | ||||
8273 | RequiresCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
8274 | , unsigned SI | |||
8275 | ) | |||
8276 | : InheritableAttr(attr::RequiresCapability, R, SI, true, true) | |||
8277 | , args_Size(0), args_(nullptr) | |||
8278 | { | |||
8279 | } | |||
8280 | ||||
8281 | RequiresCapabilityAttr *clone(ASTContext &C) const; | |||
8282 | void printPretty(raw_ostream &OS, | |||
8283 | const PrintingPolicy &Policy) const; | |||
8284 | const char *getSpelling() const; | |||
8285 | Spelling getSemanticSpelling() const { | |||
8286 | switch (SpellingListIndex) { | |||
8287 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8287); | |||
8288 | case 0: return GNU_requires_capability; | |||
8289 | case 1: return CXX11_clang_requires_capability; | |||
8290 | case 2: return GNU_exclusive_locks_required; | |||
8291 | case 3: return CXX11_clang_exclusive_locks_required; | |||
8292 | case 4: return GNU_requires_shared_capability; | |||
8293 | case 5: return CXX11_clang_requires_shared_capability; | |||
8294 | case 6: return GNU_shared_locks_required; | |||
8295 | case 7: return CXX11_clang_shared_locks_required; | |||
8296 | } | |||
8297 | } | |||
8298 | bool isShared() const { return SpellingListIndex == 4 || | |||
8299 | SpellingListIndex == 5 || | |||
8300 | SpellingListIndex == 6 || | |||
8301 | SpellingListIndex == 7; } | |||
8302 | typedef Expr ** args_iterator; | |||
8303 | args_iterator args_begin() const { return args_; } | |||
8304 | args_iterator args_end() const { return args_ + args_Size; } | |||
8305 | unsigned args_size() const { return args_Size; } | |||
8306 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
8307 | ||||
8308 | ||||
8309 | ||||
8310 | ||||
8311 | static bool classof(const Attr *A) { return A->getKind() == attr::RequiresCapability; } | |||
8312 | }; | |||
8313 | ||||
8314 | class RestrictAttr : public InheritableAttr { | |||
8315 | public: | |||
8316 | enum Spelling { | |||
8317 | Declspec_restrict = 0, | |||
8318 | GNU_malloc = 1, | |||
8319 | CXX11_gnu_malloc = 2 | |||
8320 | }; | |||
8321 | ||||
8322 | static RestrictAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
8323 | auto *A = new (Ctx) RestrictAttr(Loc, Ctx, S); | |||
8324 | A->setImplicit(true); | |||
8325 | return A; | |||
8326 | } | |||
8327 | ||||
8328 | RestrictAttr(SourceRange R, ASTContext &Ctx | |||
8329 | , unsigned SI | |||
8330 | ) | |||
8331 | : InheritableAttr(attr::Restrict, R, SI, false, false) | |||
8332 | { | |||
8333 | } | |||
8334 | ||||
8335 | RestrictAttr *clone(ASTContext &C) const; | |||
8336 | void printPretty(raw_ostream &OS, | |||
8337 | const PrintingPolicy &Policy) const; | |||
8338 | const char *getSpelling() const; | |||
8339 | Spelling getSemanticSpelling() const { | |||
8340 | switch (SpellingListIndex) { | |||
8341 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8341); | |||
8342 | case 0: return Declspec_restrict; | |||
8343 | case 1: return GNU_malloc; | |||
8344 | case 2: return CXX11_gnu_malloc; | |||
8345 | } | |||
8346 | } | |||
8347 | ||||
8348 | ||||
8349 | static bool classof(const Attr *A) { return A->getKind() == attr::Restrict; } | |||
8350 | }; | |||
8351 | ||||
8352 | class ReturnTypestateAttr : public InheritableAttr { | |||
8353 | public: | |||
8354 | enum ConsumedState { | |||
8355 | Unknown, | |||
8356 | Consumed, | |||
8357 | Unconsumed | |||
8358 | }; | |||
8359 | private: | |||
8360 | ConsumedState state; | |||
8361 | ||||
8362 | public: | |||
8363 | static ReturnTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState State, SourceRange Loc = SourceRange()) { | |||
8364 | auto *A = new (Ctx) ReturnTypestateAttr(Loc, Ctx, State, 0); | |||
8365 | A->setImplicit(true); | |||
8366 | return A; | |||
8367 | } | |||
8368 | ||||
8369 | ReturnTypestateAttr(SourceRange R, ASTContext &Ctx | |||
8370 | , ConsumedState State | |||
8371 | , unsigned SI | |||
8372 | ) | |||
8373 | : InheritableAttr(attr::ReturnTypestate, R, SI, false, false) | |||
8374 | , state(State) | |||
8375 | { | |||
8376 | } | |||
8377 | ||||
8378 | ReturnTypestateAttr *clone(ASTContext &C) const; | |||
8379 | void printPretty(raw_ostream &OS, | |||
8380 | const PrintingPolicy &Policy) const; | |||
8381 | const char *getSpelling() const; | |||
8382 | ConsumedState getState() const { | |||
8383 | return state; | |||
8384 | } | |||
8385 | ||||
8386 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
8387 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
8388 | .Case("unknown", ReturnTypestateAttr::Unknown) | |||
8389 | .Case("consumed", ReturnTypestateAttr::Consumed) | |||
8390 | .Case("unconsumed", ReturnTypestateAttr::Unconsumed) | |||
8391 | .Default(Optional<ConsumedState>()); | |||
8392 | if (R) { | |||
8393 | Out = *R; | |||
8394 | return true; | |||
8395 | } | |||
8396 | return false; | |||
8397 | } | |||
8398 | ||||
8399 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
8400 | switch(Val) { | |||
8401 | case ReturnTypestateAttr::Unknown: return "unknown"; | |||
8402 | case ReturnTypestateAttr::Consumed: return "consumed"; | |||
8403 | case ReturnTypestateAttr::Unconsumed: return "unconsumed"; | |||
8404 | } | |||
8405 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8405); | |||
8406 | } | |||
8407 | ||||
8408 | ||||
8409 | static bool classof(const Attr *A) { return A->getKind() == attr::ReturnTypestate; } | |||
8410 | }; | |||
8411 | ||||
8412 | class ReturnsNonNullAttr : public InheritableAttr { | |||
8413 | public: | |||
8414 | static ReturnsNonNullAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8415 | auto *A = new (Ctx) ReturnsNonNullAttr(Loc, Ctx, 0); | |||
8416 | A->setImplicit(true); | |||
8417 | return A; | |||
8418 | } | |||
8419 | ||||
8420 | ReturnsNonNullAttr(SourceRange R, ASTContext &Ctx | |||
8421 | , unsigned SI | |||
8422 | ) | |||
8423 | : InheritableAttr(attr::ReturnsNonNull, R, SI, false, false) | |||
8424 | { | |||
8425 | } | |||
8426 | ||||
8427 | ReturnsNonNullAttr *clone(ASTContext &C) const; | |||
8428 | void printPretty(raw_ostream &OS, | |||
8429 | const PrintingPolicy &Policy) const; | |||
8430 | const char *getSpelling() const; | |||
8431 | ||||
8432 | ||||
8433 | static bool classof(const Attr *A) { return A->getKind() == attr::ReturnsNonNull; } | |||
8434 | }; | |||
8435 | ||||
8436 | class ReturnsTwiceAttr : public InheritableAttr { | |||
8437 | public: | |||
8438 | static ReturnsTwiceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8439 | auto *A = new (Ctx) ReturnsTwiceAttr(Loc, Ctx, 0); | |||
8440 | A->setImplicit(true); | |||
8441 | return A; | |||
8442 | } | |||
8443 | ||||
8444 | ReturnsTwiceAttr(SourceRange R, ASTContext &Ctx | |||
8445 | , unsigned SI | |||
8446 | ) | |||
8447 | : InheritableAttr(attr::ReturnsTwice, R, SI, false, false) | |||
8448 | { | |||
8449 | } | |||
8450 | ||||
8451 | ReturnsTwiceAttr *clone(ASTContext &C) const; | |||
8452 | void printPretty(raw_ostream &OS, | |||
8453 | const PrintingPolicy &Policy) const; | |||
8454 | const char *getSpelling() const; | |||
8455 | ||||
8456 | ||||
8457 | static bool classof(const Attr *A) { return A->getKind() == attr::ReturnsTwice; } | |||
8458 | }; | |||
8459 | ||||
8460 | class SPtrAttr : public TypeAttr { | |||
8461 | public: | |||
8462 | static SPtrAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8463 | auto *A = new (Ctx) SPtrAttr(Loc, Ctx, 0); | |||
8464 | A->setImplicit(true); | |||
8465 | return A; | |||
8466 | } | |||
8467 | ||||
8468 | SPtrAttr(SourceRange R, ASTContext &Ctx | |||
8469 | , unsigned SI | |||
8470 | ) | |||
8471 | : TypeAttr(attr::SPtr, R, SI, false) | |||
8472 | { | |||
8473 | } | |||
8474 | ||||
8475 | SPtrAttr *clone(ASTContext &C) const; | |||
8476 | void printPretty(raw_ostream &OS, | |||
8477 | const PrintingPolicy &Policy) const; | |||
8478 | const char *getSpelling() const; | |||
8479 | ||||
8480 | ||||
8481 | static bool classof(const Attr *A) { return A->getKind() == attr::SPtr; } | |||
8482 | }; | |||
8483 | ||||
8484 | class ScopedLockableAttr : public InheritableAttr { | |||
8485 | public: | |||
8486 | static ScopedLockableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8487 | auto *A = new (Ctx) ScopedLockableAttr(Loc, Ctx, 0); | |||
8488 | A->setImplicit(true); | |||
8489 | return A; | |||
8490 | } | |||
8491 | ||||
8492 | ScopedLockableAttr(SourceRange R, ASTContext &Ctx | |||
8493 | , unsigned SI | |||
8494 | ) | |||
8495 | : InheritableAttr(attr::ScopedLockable, R, SI, false, false) | |||
8496 | { | |||
8497 | } | |||
8498 | ||||
8499 | ScopedLockableAttr *clone(ASTContext &C) const; | |||
8500 | void printPretty(raw_ostream &OS, | |||
8501 | const PrintingPolicy &Policy) const; | |||
8502 | const char *getSpelling() const; | |||
8503 | ||||
8504 | ||||
8505 | static bool classof(const Attr *A) { return A->getKind() == attr::ScopedLockable; } | |||
8506 | }; | |||
8507 | ||||
8508 | class SectionAttr : public InheritableAttr { | |||
8509 | unsigned nameLength; | |||
8510 | char *name; | |||
8511 | ||||
8512 | public: | |||
8513 | enum Spelling { | |||
8514 | GNU_section = 0, | |||
8515 | CXX11_gnu_section = 1, | |||
8516 | Declspec_allocate = 2 | |||
8517 | }; | |||
8518 | ||||
8519 | static SectionAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) { | |||
8520 | auto *A = new (Ctx) SectionAttr(Loc, Ctx, Name, S); | |||
8521 | A->setImplicit(true); | |||
8522 | return A; | |||
8523 | } | |||
8524 | ||||
8525 | SectionAttr(SourceRange R, ASTContext &Ctx | |||
8526 | , llvm::StringRef Name | |||
8527 | , unsigned SI | |||
8528 | ) | |||
8529 | : InheritableAttr(attr::Section, R, SI, false, false) | |||
8530 | , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength]) | |||
8531 | { | |||
8532 | if (!Name.empty()) | |||
8533 | std::memcpy(name, Name.data(), nameLength); | |||
8534 | } | |||
8535 | ||||
8536 | SectionAttr *clone(ASTContext &C) const; | |||
8537 | void printPretty(raw_ostream &OS, | |||
8538 | const PrintingPolicy &Policy) const; | |||
8539 | const char *getSpelling() const; | |||
8540 | Spelling getSemanticSpelling() const { | |||
8541 | switch (SpellingListIndex) { | |||
8542 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8542); | |||
8543 | case 0: return GNU_section; | |||
8544 | case 1: return CXX11_gnu_section; | |||
8545 | case 2: return Declspec_allocate; | |||
8546 | } | |||
8547 | } | |||
8548 | llvm::StringRef getName() const { | |||
8549 | return llvm::StringRef(name, nameLength); | |||
8550 | } | |||
8551 | unsigned getNameLength() const { | |||
8552 | return nameLength; | |||
8553 | } | |||
8554 | void setName(ASTContext &C, llvm::StringRef S) { | |||
8555 | nameLength = S.size(); | |||
8556 | this->name = new (C, 1) char [nameLength]; | |||
8557 | if (!S.empty()) | |||
8558 | std::memcpy(this->name, S.data(), nameLength); | |||
8559 | } | |||
8560 | ||||
8561 | ||||
8562 | ||||
8563 | static bool classof(const Attr *A) { return A->getKind() == attr::Section; } | |||
8564 | }; | |||
8565 | ||||
8566 | class SelectAnyAttr : public InheritableAttr { | |||
8567 | public: | |||
8568 | static SelectAnyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8569 | auto *A = new (Ctx) SelectAnyAttr(Loc, Ctx, 0); | |||
8570 | A->setImplicit(true); | |||
8571 | return A; | |||
8572 | } | |||
8573 | ||||
8574 | SelectAnyAttr(SourceRange R, ASTContext &Ctx | |||
8575 | , unsigned SI | |||
8576 | ) | |||
8577 | : InheritableAttr(attr::SelectAny, R, SI, false, false) | |||
8578 | { | |||
8579 | } | |||
8580 | ||||
8581 | SelectAnyAttr *clone(ASTContext &C) const; | |||
8582 | void printPretty(raw_ostream &OS, | |||
8583 | const PrintingPolicy &Policy) const; | |||
8584 | const char *getSpelling() const; | |||
8585 | ||||
8586 | ||||
8587 | static bool classof(const Attr *A) { return A->getKind() == attr::SelectAny; } | |||
8588 | }; | |||
8589 | ||||
8590 | class SentinelAttr : public InheritableAttr { | |||
8591 | int sentinel; | |||
8592 | ||||
8593 | int nullPos; | |||
8594 | ||||
8595 | public: | |||
8596 | static SentinelAttr *CreateImplicit(ASTContext &Ctx, int Sentinel, int NullPos, SourceRange Loc = SourceRange()) { | |||
8597 | auto *A = new (Ctx) SentinelAttr(Loc, Ctx, Sentinel, NullPos, 0); | |||
8598 | A->setImplicit(true); | |||
8599 | return A; | |||
8600 | } | |||
8601 | ||||
8602 | SentinelAttr(SourceRange R, ASTContext &Ctx | |||
8603 | , int Sentinel | |||
8604 | , int NullPos | |||
8605 | , unsigned SI | |||
8606 | ) | |||
8607 | : InheritableAttr(attr::Sentinel, R, SI, false, false) | |||
8608 | , sentinel(Sentinel) | |||
8609 | , nullPos(NullPos) | |||
8610 | { | |||
8611 | } | |||
8612 | ||||
8613 | SentinelAttr(SourceRange R, ASTContext &Ctx | |||
8614 | , unsigned SI | |||
8615 | ) | |||
8616 | : InheritableAttr(attr::Sentinel, R, SI, false, false) | |||
8617 | , sentinel() | |||
8618 | , nullPos() | |||
8619 | { | |||
8620 | } | |||
8621 | ||||
8622 | SentinelAttr *clone(ASTContext &C) const; | |||
8623 | void printPretty(raw_ostream &OS, | |||
8624 | const PrintingPolicy &Policy) const; | |||
8625 | const char *getSpelling() const; | |||
8626 | int getSentinel() const { | |||
8627 | return sentinel; | |||
8628 | } | |||
8629 | ||||
8630 | static const int DefaultSentinel = 0; | |||
8631 | ||||
8632 | int getNullPos() const { | |||
8633 | return nullPos; | |||
8634 | } | |||
8635 | ||||
8636 | static const int DefaultNullPos = 0; | |||
8637 | ||||
8638 | ||||
8639 | ||||
8640 | static bool classof(const Attr *A) { return A->getKind() == attr::Sentinel; } | |||
8641 | }; | |||
8642 | ||||
8643 | class SetTypestateAttr : public InheritableAttr { | |||
8644 | public: | |||
8645 | enum ConsumedState { | |||
8646 | Unknown, | |||
8647 | Consumed, | |||
8648 | Unconsumed | |||
8649 | }; | |||
8650 | private: | |||
8651 | ConsumedState newState; | |||
8652 | ||||
8653 | public: | |||
8654 | static SetTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState NewState, SourceRange Loc = SourceRange()) { | |||
8655 | auto *A = new (Ctx) SetTypestateAttr(Loc, Ctx, NewState, 0); | |||
8656 | A->setImplicit(true); | |||
8657 | return A; | |||
8658 | } | |||
8659 | ||||
8660 | SetTypestateAttr(SourceRange R, ASTContext &Ctx | |||
8661 | , ConsumedState NewState | |||
8662 | , unsigned SI | |||
8663 | ) | |||
8664 | : InheritableAttr(attr::SetTypestate, R, SI, false, false) | |||
8665 | , newState(NewState) | |||
8666 | { | |||
8667 | } | |||
8668 | ||||
8669 | SetTypestateAttr *clone(ASTContext &C) const; | |||
8670 | void printPretty(raw_ostream &OS, | |||
8671 | const PrintingPolicy &Policy) const; | |||
8672 | const char *getSpelling() const; | |||
8673 | ConsumedState getNewState() const { | |||
8674 | return newState; | |||
8675 | } | |||
8676 | ||||
8677 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
8678 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
8679 | .Case("unknown", SetTypestateAttr::Unknown) | |||
8680 | .Case("consumed", SetTypestateAttr::Consumed) | |||
8681 | .Case("unconsumed", SetTypestateAttr::Unconsumed) | |||
8682 | .Default(Optional<ConsumedState>()); | |||
8683 | if (R) { | |||
8684 | Out = *R; | |||
8685 | return true; | |||
8686 | } | |||
8687 | return false; | |||
8688 | } | |||
8689 | ||||
8690 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
8691 | switch(Val) { | |||
8692 | case SetTypestateAttr::Unknown: return "unknown"; | |||
8693 | case SetTypestateAttr::Consumed: return "consumed"; | |||
8694 | case SetTypestateAttr::Unconsumed: return "unconsumed"; | |||
8695 | } | |||
8696 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 8696); | |||
8697 | } | |||
8698 | ||||
8699 | ||||
8700 | static bool classof(const Attr *A) { return A->getKind() == attr::SetTypestate; } | |||
8701 | }; | |||
8702 | ||||
8703 | class SharedTrylockFunctionAttr : public InheritableAttr { | |||
8704 | Expr * successValue; | |||
8705 | ||||
8706 | unsigned args_Size; | |||
8707 | Expr * *args_; | |||
8708 | ||||
8709 | public: | |||
8710 | static SharedTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
8711 | auto *A = new (Ctx) SharedTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0); | |||
8712 | A->setImplicit(true); | |||
8713 | return A; | |||
8714 | } | |||
8715 | ||||
8716 | SharedTrylockFunctionAttr(SourceRange R, ASTContext &Ctx | |||
8717 | , Expr * SuccessValue | |||
8718 | , Expr * *Args, unsigned ArgsSize | |||
8719 | , unsigned SI | |||
8720 | ) | |||
8721 | : InheritableAttr(attr::SharedTrylockFunction, R, SI, true, true) | |||
8722 | , successValue(SuccessValue) | |||
8723 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
8724 | { | |||
8725 | std::copy(Args, Args + args_Size, args_); | |||
8726 | } | |||
8727 | ||||
8728 | SharedTrylockFunctionAttr(SourceRange R, ASTContext &Ctx | |||
8729 | , Expr * SuccessValue | |||
8730 | , unsigned SI | |||
8731 | ) | |||
8732 | : InheritableAttr(attr::SharedTrylockFunction, R, SI, true, true) | |||
8733 | , successValue(SuccessValue) | |||
8734 | , args_Size(0), args_(nullptr) | |||
8735 | { | |||
8736 | } | |||
8737 | ||||
8738 | SharedTrylockFunctionAttr *clone(ASTContext &C) const; | |||
8739 | void printPretty(raw_ostream &OS, | |||
8740 | const PrintingPolicy &Policy) const; | |||
8741 | const char *getSpelling() const; | |||
8742 | Expr * getSuccessValue() const { | |||
8743 | return successValue; | |||
8744 | } | |||
8745 | ||||
8746 | typedef Expr ** args_iterator; | |||
8747 | args_iterator args_begin() const { return args_; } | |||
8748 | args_iterator args_end() const { return args_ + args_Size; } | |||
8749 | unsigned args_size() const { return args_Size; } | |||
8750 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
8751 | ||||
8752 | ||||
8753 | ||||
8754 | ||||
8755 | static bool classof(const Attr *A) { return A->getKind() == attr::SharedTrylockFunction; } | |||
8756 | }; | |||
8757 | ||||
8758 | class SpeculativeLoadHardeningAttr : public InheritableAttr { | |||
8759 | public: | |||
8760 | static SpeculativeLoadHardeningAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8761 | auto *A = new (Ctx) SpeculativeLoadHardeningAttr(Loc, Ctx, 0); | |||
8762 | A->setImplicit(true); | |||
8763 | return A; | |||
8764 | } | |||
8765 | ||||
8766 | SpeculativeLoadHardeningAttr(SourceRange R, ASTContext &Ctx | |||
8767 | , unsigned SI | |||
8768 | ) | |||
8769 | : InheritableAttr(attr::SpeculativeLoadHardening, R, SI, false, false) | |||
8770 | { | |||
8771 | } | |||
8772 | ||||
8773 | SpeculativeLoadHardeningAttr *clone(ASTContext &C) const; | |||
8774 | void printPretty(raw_ostream &OS, | |||
8775 | const PrintingPolicy &Policy) const; | |||
8776 | const char *getSpelling() const; | |||
8777 | ||||
8778 | ||||
8779 | static bool classof(const Attr *A) { return A->getKind() == attr::SpeculativeLoadHardening; } | |||
8780 | }; | |||
8781 | ||||
8782 | class StdCallAttr : public InheritableAttr { | |||
8783 | public: | |||
8784 | static StdCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8785 | auto *A = new (Ctx) StdCallAttr(Loc, Ctx, 0); | |||
8786 | A->setImplicit(true); | |||
8787 | return A; | |||
8788 | } | |||
8789 | ||||
8790 | StdCallAttr(SourceRange R, ASTContext &Ctx | |||
8791 | , unsigned SI | |||
8792 | ) | |||
8793 | : InheritableAttr(attr::StdCall, R, SI, false, false) | |||
8794 | { | |||
8795 | } | |||
8796 | ||||
8797 | StdCallAttr *clone(ASTContext &C) const; | |||
8798 | void printPretty(raw_ostream &OS, | |||
8799 | const PrintingPolicy &Policy) const; | |||
8800 | const char *getSpelling() const; | |||
8801 | ||||
8802 | ||||
8803 | static bool classof(const Attr *A) { return A->getKind() == attr::StdCall; } | |||
8804 | }; | |||
8805 | ||||
8806 | class SuppressAttr : public StmtAttr { | |||
8807 | unsigned diagnosticIdentifiers_Size; | |||
8808 | StringRef *diagnosticIdentifiers_; | |||
8809 | ||||
8810 | public: | |||
8811 | static SuppressAttr *CreateImplicit(ASTContext &Ctx, StringRef *DiagnosticIdentifiers, unsigned DiagnosticIdentifiersSize, SourceRange Loc = SourceRange()) { | |||
8812 | auto *A = new (Ctx) SuppressAttr(Loc, Ctx, DiagnosticIdentifiers, DiagnosticIdentifiersSize, 0); | |||
8813 | A->setImplicit(true); | |||
8814 | return A; | |||
8815 | } | |||
8816 | ||||
8817 | SuppressAttr(SourceRange R, ASTContext &Ctx | |||
8818 | , StringRef *DiagnosticIdentifiers, unsigned DiagnosticIdentifiersSize | |||
8819 | , unsigned SI | |||
8820 | ) | |||
8821 | : StmtAttr(attr::Suppress, R, SI, false) | |||
8822 | , diagnosticIdentifiers_Size(DiagnosticIdentifiersSize), diagnosticIdentifiers_(new (Ctx, 16) StringRef[diagnosticIdentifiers_Size]) | |||
8823 | { | |||
8824 | for (size_t I = 0, E = diagnosticIdentifiers_Size; I != E; | |||
8825 | ++I) { | |||
8826 | StringRef Ref = DiagnosticIdentifiers[I]; | |||
8827 | if (!Ref.empty()) { | |||
8828 | char *Mem = new (Ctx, 1) char[Ref.size()]; | |||
8829 | std::memcpy(Mem, Ref.data(), Ref.size()); | |||
8830 | diagnosticIdentifiers_[I] = StringRef(Mem, Ref.size()); | |||
8831 | } | |||
8832 | } | |||
8833 | } | |||
8834 | ||||
8835 | SuppressAttr(SourceRange R, ASTContext &Ctx | |||
8836 | , unsigned SI | |||
8837 | ) | |||
8838 | : StmtAttr(attr::Suppress, R, SI, false) | |||
8839 | , diagnosticIdentifiers_Size(0), diagnosticIdentifiers_(nullptr) | |||
8840 | { | |||
8841 | } | |||
8842 | ||||
8843 | SuppressAttr *clone(ASTContext &C) const; | |||
8844 | void printPretty(raw_ostream &OS, | |||
8845 | const PrintingPolicy &Policy) const; | |||
8846 | const char *getSpelling() const; | |||
8847 | typedef StringRef* diagnosticIdentifiers_iterator; | |||
8848 | diagnosticIdentifiers_iterator diagnosticIdentifiers_begin() const { return diagnosticIdentifiers_; } | |||
8849 | diagnosticIdentifiers_iterator diagnosticIdentifiers_end() const { return diagnosticIdentifiers_ + diagnosticIdentifiers_Size; } | |||
8850 | unsigned diagnosticIdentifiers_size() const { return diagnosticIdentifiers_Size; } | |||
8851 | llvm::iterator_range<diagnosticIdentifiers_iterator> diagnosticIdentifiers() const { return llvm::make_range(diagnosticIdentifiers_begin(), diagnosticIdentifiers_end()); } | |||
8852 | ||||
8853 | ||||
8854 | ||||
8855 | ||||
8856 | static bool classof(const Attr *A) { return A->getKind() == attr::Suppress; } | |||
8857 | }; | |||
8858 | ||||
8859 | class SwiftCallAttr : public InheritableAttr { | |||
8860 | public: | |||
8861 | static SwiftCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8862 | auto *A = new (Ctx) SwiftCallAttr(Loc, Ctx, 0); | |||
8863 | A->setImplicit(true); | |||
8864 | return A; | |||
8865 | } | |||
8866 | ||||
8867 | SwiftCallAttr(SourceRange R, ASTContext &Ctx | |||
8868 | , unsigned SI | |||
8869 | ) | |||
8870 | : InheritableAttr(attr::SwiftCall, R, SI, false, false) | |||
8871 | { | |||
8872 | } | |||
8873 | ||||
8874 | SwiftCallAttr *clone(ASTContext &C) const; | |||
8875 | void printPretty(raw_ostream &OS, | |||
8876 | const PrintingPolicy &Policy) const; | |||
8877 | const char *getSpelling() const; | |||
8878 | ||||
8879 | ||||
8880 | static bool classof(const Attr *A) { return A->getKind() == attr::SwiftCall; } | |||
8881 | }; | |||
8882 | ||||
8883 | class SwiftContextAttr : public ParameterABIAttr { | |||
8884 | public: | |||
8885 | static SwiftContextAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8886 | auto *A = new (Ctx) SwiftContextAttr(Loc, Ctx, 0); | |||
8887 | A->setImplicit(true); | |||
8888 | return A; | |||
8889 | } | |||
8890 | ||||
8891 | SwiftContextAttr(SourceRange R, ASTContext &Ctx | |||
8892 | , unsigned SI | |||
8893 | ) | |||
8894 | : ParameterABIAttr(attr::SwiftContext, R, SI, false, false) | |||
8895 | { | |||
8896 | } | |||
8897 | ||||
8898 | SwiftContextAttr *clone(ASTContext &C) const; | |||
8899 | void printPretty(raw_ostream &OS, | |||
8900 | const PrintingPolicy &Policy) const; | |||
8901 | const char *getSpelling() const; | |||
8902 | ||||
8903 | ||||
8904 | static bool classof(const Attr *A) { return A->getKind() == attr::SwiftContext; } | |||
8905 | }; | |||
8906 | ||||
8907 | class SwiftErrorResultAttr : public ParameterABIAttr { | |||
8908 | public: | |||
8909 | static SwiftErrorResultAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8910 | auto *A = new (Ctx) SwiftErrorResultAttr(Loc, Ctx, 0); | |||
8911 | A->setImplicit(true); | |||
8912 | return A; | |||
8913 | } | |||
8914 | ||||
8915 | SwiftErrorResultAttr(SourceRange R, ASTContext &Ctx | |||
8916 | , unsigned SI | |||
8917 | ) | |||
8918 | : ParameterABIAttr(attr::SwiftErrorResult, R, SI, false, false) | |||
8919 | { | |||
8920 | } | |||
8921 | ||||
8922 | SwiftErrorResultAttr *clone(ASTContext &C) const; | |||
8923 | void printPretty(raw_ostream &OS, | |||
8924 | const PrintingPolicy &Policy) const; | |||
8925 | const char *getSpelling() const; | |||
8926 | ||||
8927 | ||||
8928 | static bool classof(const Attr *A) { return A->getKind() == attr::SwiftErrorResult; } | |||
8929 | }; | |||
8930 | ||||
8931 | class SwiftIndirectResultAttr : public ParameterABIAttr { | |||
8932 | public: | |||
8933 | static SwiftIndirectResultAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8934 | auto *A = new (Ctx) SwiftIndirectResultAttr(Loc, Ctx, 0); | |||
8935 | A->setImplicit(true); | |||
8936 | return A; | |||
8937 | } | |||
8938 | ||||
8939 | SwiftIndirectResultAttr(SourceRange R, ASTContext &Ctx | |||
8940 | , unsigned SI | |||
8941 | ) | |||
8942 | : ParameterABIAttr(attr::SwiftIndirectResult, R, SI, false, false) | |||
8943 | { | |||
8944 | } | |||
8945 | ||||
8946 | SwiftIndirectResultAttr *clone(ASTContext &C) const; | |||
8947 | void printPretty(raw_ostream &OS, | |||
8948 | const PrintingPolicy &Policy) const; | |||
8949 | const char *getSpelling() const; | |||
8950 | ||||
8951 | ||||
8952 | static bool classof(const Attr *A) { return A->getKind() == attr::SwiftIndirectResult; } | |||
8953 | }; | |||
8954 | ||||
8955 | class SysVABIAttr : public InheritableAttr { | |||
8956 | public: | |||
8957 | static SysVABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
8958 | auto *A = new (Ctx) SysVABIAttr(Loc, Ctx, 0); | |||
8959 | A->setImplicit(true); | |||
8960 | return A; | |||
8961 | } | |||
8962 | ||||
8963 | SysVABIAttr(SourceRange R, ASTContext &Ctx | |||
8964 | , unsigned SI | |||
8965 | ) | |||
8966 | : InheritableAttr(attr::SysVABI, R, SI, false, false) | |||
8967 | { | |||
8968 | } | |||
8969 | ||||
8970 | SysVABIAttr *clone(ASTContext &C) const; | |||
8971 | void printPretty(raw_ostream &OS, | |||
8972 | const PrintingPolicy &Policy) const; | |||
8973 | const char *getSpelling() const; | |||
8974 | ||||
8975 | ||||
8976 | static bool classof(const Attr *A) { return A->getKind() == attr::SysVABI; } | |||
8977 | }; | |||
8978 | ||||
8979 | class TLSModelAttr : public InheritableAttr { | |||
8980 | unsigned modelLength; | |||
8981 | char *model; | |||
8982 | ||||
8983 | public: | |||
8984 | static TLSModelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Model, SourceRange Loc = SourceRange()) { | |||
8985 | auto *A = new (Ctx) TLSModelAttr(Loc, Ctx, Model, 0); | |||
8986 | A->setImplicit(true); | |||
8987 | return A; | |||
8988 | } | |||
8989 | ||||
8990 | TLSModelAttr(SourceRange R, ASTContext &Ctx | |||
8991 | , llvm::StringRef Model | |||
8992 | , unsigned SI | |||
8993 | ) | |||
8994 | : InheritableAttr(attr::TLSModel, R, SI, false, false) | |||
8995 | , modelLength(Model.size()),model(new (Ctx, 1) char[modelLength]) | |||
8996 | { | |||
8997 | if (!Model.empty()) | |||
8998 | std::memcpy(model, Model.data(), modelLength); | |||
8999 | } | |||
9000 | ||||
9001 | TLSModelAttr *clone(ASTContext &C) const; | |||
9002 | void printPretty(raw_ostream &OS, | |||
9003 | const PrintingPolicy &Policy) const; | |||
9004 | const char *getSpelling() const; | |||
9005 | llvm::StringRef getModel() const { | |||
9006 | return llvm::StringRef(model, modelLength); | |||
9007 | } | |||
9008 | unsigned getModelLength() const { | |||
9009 | return modelLength; | |||
9010 | } | |||
9011 | void setModel(ASTContext &C, llvm::StringRef S) { | |||
9012 | modelLength = S.size(); | |||
9013 | this->model = new (C, 1) char [modelLength]; | |||
9014 | if (!S.empty()) | |||
9015 | std::memcpy(this->model, S.data(), modelLength); | |||
9016 | } | |||
9017 | ||||
9018 | ||||
9019 | ||||
9020 | static bool classof(const Attr *A) { return A->getKind() == attr::TLSModel; } | |||
9021 | }; | |||
9022 | ||||
9023 | class TargetAttr : public InheritableAttr { | |||
9024 | unsigned featuresStrLength; | |||
9025 | char *featuresStr; | |||
9026 | ||||
9027 | public: | |||
9028 | static TargetAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef FeaturesStr, SourceRange Loc = SourceRange()) { | |||
9029 | auto *A = new (Ctx) TargetAttr(Loc, Ctx, FeaturesStr, 0); | |||
9030 | A->setImplicit(true); | |||
9031 | return A; | |||
9032 | } | |||
9033 | ||||
9034 | TargetAttr(SourceRange R, ASTContext &Ctx | |||
9035 | , llvm::StringRef FeaturesStr | |||
9036 | , unsigned SI | |||
9037 | ) | |||
9038 | : InheritableAttr(attr::Target, R, SI, false, false) | |||
9039 | , featuresStrLength(FeaturesStr.size()),featuresStr(new (Ctx, 1) char[featuresStrLength]) | |||
9040 | { | |||
9041 | if (!FeaturesStr.empty()) | |||
9042 | std::memcpy(featuresStr, FeaturesStr.data(), featuresStrLength); | |||
9043 | } | |||
9044 | ||||
9045 | TargetAttr *clone(ASTContext &C) const; | |||
9046 | void printPretty(raw_ostream &OS, | |||
9047 | const PrintingPolicy &Policy) const; | |||
9048 | const char *getSpelling() const; | |||
9049 | llvm::StringRef getFeaturesStr() const { | |||
9050 | return llvm::StringRef(featuresStr, featuresStrLength); | |||
9051 | } | |||
9052 | unsigned getFeaturesStrLength() const { | |||
9053 | return featuresStrLength; | |||
9054 | } | |||
9055 | void setFeaturesStr(ASTContext &C, llvm::StringRef S) { | |||
9056 | featuresStrLength = S.size(); | |||
9057 | this->featuresStr = new (C, 1) char [featuresStrLength]; | |||
9058 | if (!S.empty()) | |||
9059 | std::memcpy(this->featuresStr, S.data(), featuresStrLength); | |||
9060 | } | |||
9061 | ||||
9062 | ||||
9063 | struct ParsedTargetAttr { | |||
9064 | std::vector<std::string> Features; | |||
9065 | StringRef Architecture; | |||
9066 | bool DuplicateArchitecture = false; | |||
9067 | bool operator ==(const ParsedTargetAttr &Other) const { | |||
9068 | return DuplicateArchitecture == Other.DuplicateArchitecture && | |||
9069 | Architecture == Other.Architecture && Features == Other.Features; | |||
9070 | } | |||
9071 | }; | |||
9072 | ParsedTargetAttr parse() const { | |||
9073 | return parse(getFeaturesStr()); | |||
9074 | } | |||
9075 | ||||
9076 | StringRef getArchitecture() const { | |||
9077 | StringRef Features = getFeaturesStr(); | |||
9078 | if (Features == "default") return {}; | |||
9079 | ||||
9080 | SmallVector<StringRef, 1> AttrFeatures; | |||
9081 | Features.split(AttrFeatures, ","); | |||
9082 | ||||
9083 | for (auto &Feature : AttrFeatures) { | |||
9084 | Feature = Feature.trim(); | |||
9085 | if (Feature.startswith("arch=")) | |||
9086 | return Feature.drop_front(sizeof("arch=") - 1); | |||
9087 | } | |||
9088 | return ""; | |||
9089 | } | |||
9090 | ||||
9091 | // Gets the list of features as simple string-refs with no +/- or 'no-'. | |||
9092 | // Only adds the items to 'Out' that are additions. | |||
9093 | void getAddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const { | |||
9094 | StringRef Features = getFeaturesStr(); | |||
9095 | if (Features == "default") return; | |||
9096 | ||||
9097 | SmallVector<StringRef, 1> AttrFeatures; | |||
9098 | Features.split(AttrFeatures, ","); | |||
9099 | ||||
9100 | for (auto &Feature : AttrFeatures) { | |||
9101 | Feature = Feature.trim(); | |||
9102 | ||||
9103 | if (!Feature.startswith("no-") && !Feature.startswith("arch=") && | |||
9104 | !Feature.startswith("fpmath=") && !Feature.startswith("tune=")) | |||
9105 | Out.push_back(Feature); | |||
9106 | } | |||
9107 | } | |||
9108 | ||||
9109 | template<class Compare> | |||
9110 | ParsedTargetAttr parse(Compare cmp) const { | |||
9111 | ParsedTargetAttr Attrs = parse(); | |||
9112 | llvm::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp); | |||
9113 | return Attrs; | |||
9114 | } | |||
9115 | ||||
9116 | bool isDefaultVersion() const { return getFeaturesStr() == "default"; } | |||
9117 | ||||
9118 | static ParsedTargetAttr parse(StringRef Features) { | |||
9119 | ParsedTargetAttr Ret; | |||
9120 | if (Features == "default") return Ret; | |||
9121 | SmallVector<StringRef, 1> AttrFeatures; | |||
9122 | Features.split(AttrFeatures, ","); | |||
9123 | ||||
9124 | // Grab the various features and prepend a "+" to turn on the feature to | |||
9125 | // the backend and add them to our existing set of features. | |||
9126 | for (auto &Feature : AttrFeatures) { | |||
9127 | // Go ahead and trim whitespace rather than either erroring or | |||
9128 | // accepting it weirdly. | |||
9129 | Feature = Feature.trim(); | |||
9130 | ||||
9131 | // We don't support cpu tuning this way currently. | |||
9132 | // TODO: Support the fpmath option. It will require checking | |||
9133 | // overall feature validity for the function with the rest of the | |||
9134 | // attributes on the function. | |||
9135 | if (Feature.startswith("fpmath=") || Feature.startswith("tune=")) | |||
9136 | continue; | |||
9137 | ||||
9138 | // While we're here iterating check for a different target cpu. | |||
9139 | if (Feature.startswith("arch=")) { | |||
9140 | if (!Ret.Architecture.empty()) | |||
9141 | Ret.DuplicateArchitecture = true; | |||
9142 | else | |||
9143 | Ret.Architecture = Feature.split("=").second.trim(); | |||
9144 | } else if (Feature.startswith("no-")) | |||
9145 | Ret.Features.push_back("-" + Feature.split("-").second.str()); | |||
9146 | else | |||
9147 | Ret.Features.push_back("+" + Feature.str()); | |||
9148 | } | |||
9149 | return Ret; | |||
9150 | } | |||
9151 | ||||
9152 | ||||
9153 | static bool classof(const Attr *A) { return A->getKind() == attr::Target; } | |||
9154 | }; | |||
9155 | ||||
9156 | class TestTypestateAttr : public InheritableAttr { | |||
9157 | public: | |||
9158 | enum ConsumedState { | |||
9159 | Consumed, | |||
9160 | Unconsumed | |||
9161 | }; | |||
9162 | private: | |||
9163 | ConsumedState testState; | |||
9164 | ||||
9165 | public: | |||
9166 | static TestTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState TestState, SourceRange Loc = SourceRange()) { | |||
9167 | auto *A = new (Ctx) TestTypestateAttr(Loc, Ctx, TestState, 0); | |||
9168 | A->setImplicit(true); | |||
9169 | return A; | |||
9170 | } | |||
9171 | ||||
9172 | TestTypestateAttr(SourceRange R, ASTContext &Ctx | |||
9173 | , ConsumedState TestState | |||
9174 | , unsigned SI | |||
9175 | ) | |||
9176 | : InheritableAttr(attr::TestTypestate, R, SI, false, false) | |||
9177 | , testState(TestState) | |||
9178 | { | |||
9179 | } | |||
9180 | ||||
9181 | TestTypestateAttr *clone(ASTContext &C) const; | |||
9182 | void printPretty(raw_ostream &OS, | |||
9183 | const PrintingPolicy &Policy) const; | |||
9184 | const char *getSpelling() const; | |||
9185 | ConsumedState getTestState() const { | |||
9186 | return testState; | |||
9187 | } | |||
9188 | ||||
9189 | static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) { | |||
9190 | Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val) | |||
9191 | .Case("consumed", TestTypestateAttr::Consumed) | |||
9192 | .Case("unconsumed", TestTypestateAttr::Unconsumed) | |||
9193 | .Default(Optional<ConsumedState>()); | |||
9194 | if (R) { | |||
9195 | Out = *R; | |||
9196 | return true; | |||
9197 | } | |||
9198 | return false; | |||
9199 | } | |||
9200 | ||||
9201 | static const char *ConvertConsumedStateToStr(ConsumedState Val) { | |||
9202 | switch(Val) { | |||
9203 | case TestTypestateAttr::Consumed: return "consumed"; | |||
9204 | case TestTypestateAttr::Unconsumed: return "unconsumed"; | |||
9205 | } | |||
9206 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9206); | |||
9207 | } | |||
9208 | ||||
9209 | ||||
9210 | static bool classof(const Attr *A) { return A->getKind() == attr::TestTypestate; } | |||
9211 | }; | |||
9212 | ||||
9213 | class ThisCallAttr : public InheritableAttr { | |||
9214 | public: | |||
9215 | static ThisCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9216 | auto *A = new (Ctx) ThisCallAttr(Loc, Ctx, 0); | |||
9217 | A->setImplicit(true); | |||
9218 | return A; | |||
9219 | } | |||
9220 | ||||
9221 | ThisCallAttr(SourceRange R, ASTContext &Ctx | |||
9222 | , unsigned SI | |||
9223 | ) | |||
9224 | : InheritableAttr(attr::ThisCall, R, SI, false, false) | |||
9225 | { | |||
9226 | } | |||
9227 | ||||
9228 | ThisCallAttr *clone(ASTContext &C) const; | |||
9229 | void printPretty(raw_ostream &OS, | |||
9230 | const PrintingPolicy &Policy) const; | |||
9231 | const char *getSpelling() const; | |||
9232 | ||||
9233 | ||||
9234 | static bool classof(const Attr *A) { return A->getKind() == attr::ThisCall; } | |||
9235 | }; | |||
9236 | ||||
9237 | class ThreadAttr : public Attr { | |||
9238 | public: | |||
9239 | static ThreadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9240 | auto *A = new (Ctx) ThreadAttr(Loc, Ctx, 0); | |||
9241 | A->setImplicit(true); | |||
9242 | return A; | |||
9243 | } | |||
9244 | ||||
9245 | ThreadAttr(SourceRange R, ASTContext &Ctx | |||
9246 | , unsigned SI | |||
9247 | ) | |||
9248 | : Attr(attr::Thread, R, SI, false) | |||
9249 | { | |||
9250 | } | |||
9251 | ||||
9252 | ThreadAttr *clone(ASTContext &C) const; | |||
9253 | void printPretty(raw_ostream &OS, | |||
9254 | const PrintingPolicy &Policy) const; | |||
9255 | const char *getSpelling() const; | |||
9256 | ||||
9257 | ||||
9258 | static bool classof(const Attr *A) { return A->getKind() == attr::Thread; } | |||
9259 | }; | |||
9260 | ||||
9261 | class TransparentUnionAttr : public InheritableAttr { | |||
9262 | public: | |||
9263 | static TransparentUnionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9264 | auto *A = new (Ctx) TransparentUnionAttr(Loc, Ctx, 0); | |||
9265 | A->setImplicit(true); | |||
9266 | return A; | |||
9267 | } | |||
9268 | ||||
9269 | TransparentUnionAttr(SourceRange R, ASTContext &Ctx | |||
9270 | , unsigned SI | |||
9271 | ) | |||
9272 | : InheritableAttr(attr::TransparentUnion, R, SI, false, false) | |||
9273 | { | |||
9274 | } | |||
9275 | ||||
9276 | TransparentUnionAttr *clone(ASTContext &C) const; | |||
9277 | void printPretty(raw_ostream &OS, | |||
9278 | const PrintingPolicy &Policy) const; | |||
9279 | const char *getSpelling() const; | |||
9280 | ||||
9281 | ||||
9282 | static bool classof(const Attr *A) { return A->getKind() == attr::TransparentUnion; } | |||
9283 | }; | |||
9284 | ||||
9285 | class TrivialABIAttr : public InheritableAttr { | |||
9286 | public: | |||
9287 | static TrivialABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9288 | auto *A = new (Ctx) TrivialABIAttr(Loc, Ctx, 0); | |||
9289 | A->setImplicit(true); | |||
9290 | return A; | |||
9291 | } | |||
9292 | ||||
9293 | TrivialABIAttr(SourceRange R, ASTContext &Ctx | |||
9294 | , unsigned SI | |||
9295 | ) | |||
9296 | : InheritableAttr(attr::TrivialABI, R, SI, false, false) | |||
9297 | { | |||
9298 | } | |||
9299 | ||||
9300 | TrivialABIAttr *clone(ASTContext &C) const; | |||
9301 | void printPretty(raw_ostream &OS, | |||
9302 | const PrintingPolicy &Policy) const; | |||
9303 | const char *getSpelling() const; | |||
9304 | ||||
9305 | ||||
9306 | static bool classof(const Attr *A) { return A->getKind() == attr::TrivialABI; } | |||
9307 | }; | |||
9308 | ||||
9309 | class TryAcquireCapabilityAttr : public InheritableAttr { | |||
9310 | Expr * successValue; | |||
9311 | ||||
9312 | unsigned args_Size; | |||
9313 | Expr * *args_; | |||
9314 | ||||
9315 | public: | |||
9316 | enum Spelling { | |||
9317 | GNU_try_acquire_capability = 0, | |||
9318 | CXX11_clang_try_acquire_capability = 1, | |||
9319 | GNU_try_acquire_shared_capability = 2, | |||
9320 | CXX11_clang_try_acquire_shared_capability = 3 | |||
9321 | }; | |||
9322 | ||||
9323 | static TryAcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) { | |||
9324 | auto *A = new (Ctx) TryAcquireCapabilityAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, S); | |||
9325 | A->setImplicit(true); | |||
9326 | return A; | |||
9327 | } | |||
9328 | ||||
9329 | TryAcquireCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
9330 | , Expr * SuccessValue | |||
9331 | , Expr * *Args, unsigned ArgsSize | |||
9332 | , unsigned SI | |||
9333 | ) | |||
9334 | : InheritableAttr(attr::TryAcquireCapability, R, SI, true, true) | |||
9335 | , successValue(SuccessValue) | |||
9336 | , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size]) | |||
9337 | { | |||
9338 | std::copy(Args, Args + args_Size, args_); | |||
9339 | } | |||
9340 | ||||
9341 | TryAcquireCapabilityAttr(SourceRange R, ASTContext &Ctx | |||
9342 | , Expr * SuccessValue | |||
9343 | , unsigned SI | |||
9344 | ) | |||
9345 | : InheritableAttr(attr::TryAcquireCapability, R, SI, true, true) | |||
9346 | , successValue(SuccessValue) | |||
9347 | , args_Size(0), args_(nullptr) | |||
9348 | { | |||
9349 | } | |||
9350 | ||||
9351 | TryAcquireCapabilityAttr *clone(ASTContext &C) const; | |||
9352 | void printPretty(raw_ostream &OS, | |||
9353 | const PrintingPolicy &Policy) const; | |||
9354 | const char *getSpelling() const; | |||
9355 | Spelling getSemanticSpelling() const { | |||
9356 | switch (SpellingListIndex) { | |||
9357 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9357); | |||
9358 | case 0: return GNU_try_acquire_capability; | |||
9359 | case 1: return CXX11_clang_try_acquire_capability; | |||
9360 | case 2: return GNU_try_acquire_shared_capability; | |||
9361 | case 3: return CXX11_clang_try_acquire_shared_capability; | |||
9362 | } | |||
9363 | } | |||
9364 | bool isShared() const { return SpellingListIndex == 2 || | |||
9365 | SpellingListIndex == 3; } | |||
9366 | Expr * getSuccessValue() const { | |||
9367 | return successValue; | |||
9368 | } | |||
9369 | ||||
9370 | typedef Expr ** args_iterator; | |||
9371 | args_iterator args_begin() const { return args_; } | |||
9372 | args_iterator args_end() const { return args_ + args_Size; } | |||
9373 | unsigned args_size() const { return args_Size; } | |||
9374 | llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); } | |||
9375 | ||||
9376 | ||||
9377 | ||||
9378 | ||||
9379 | static bool classof(const Attr *A) { return A->getKind() == attr::TryAcquireCapability; } | |||
9380 | }; | |||
9381 | ||||
9382 | class TypeNonNullAttr : public TypeAttr { | |||
9383 | public: | |||
9384 | static TypeNonNullAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9385 | auto *A = new (Ctx) TypeNonNullAttr(Loc, Ctx, 0); | |||
9386 | A->setImplicit(true); | |||
9387 | return A; | |||
9388 | } | |||
9389 | ||||
9390 | TypeNonNullAttr(SourceRange R, ASTContext &Ctx | |||
9391 | , unsigned SI | |||
9392 | ) | |||
9393 | : TypeAttr(attr::TypeNonNull, R, SI, false) | |||
9394 | { | |||
9395 | } | |||
9396 | ||||
9397 | TypeNonNullAttr *clone(ASTContext &C) const; | |||
9398 | void printPretty(raw_ostream &OS, | |||
9399 | const PrintingPolicy &Policy) const; | |||
9400 | const char *getSpelling() const; | |||
9401 | ||||
9402 | ||||
9403 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeNonNull; } | |||
9404 | }; | |||
9405 | ||||
9406 | class TypeNullUnspecifiedAttr : public TypeAttr { | |||
9407 | public: | |||
9408 | static TypeNullUnspecifiedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9409 | auto *A = new (Ctx) TypeNullUnspecifiedAttr(Loc, Ctx, 0); | |||
9410 | A->setImplicit(true); | |||
9411 | return A; | |||
9412 | } | |||
9413 | ||||
9414 | TypeNullUnspecifiedAttr(SourceRange R, ASTContext &Ctx | |||
9415 | , unsigned SI | |||
9416 | ) | |||
9417 | : TypeAttr(attr::TypeNullUnspecified, R, SI, false) | |||
9418 | { | |||
9419 | } | |||
9420 | ||||
9421 | TypeNullUnspecifiedAttr *clone(ASTContext &C) const; | |||
9422 | void printPretty(raw_ostream &OS, | |||
9423 | const PrintingPolicy &Policy) const; | |||
9424 | const char *getSpelling() const; | |||
9425 | ||||
9426 | ||||
9427 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeNullUnspecified; } | |||
9428 | }; | |||
9429 | ||||
9430 | class TypeNullableAttr : public TypeAttr { | |||
9431 | public: | |||
9432 | static TypeNullableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9433 | auto *A = new (Ctx) TypeNullableAttr(Loc, Ctx, 0); | |||
9434 | A->setImplicit(true); | |||
9435 | return A; | |||
9436 | } | |||
9437 | ||||
9438 | TypeNullableAttr(SourceRange R, ASTContext &Ctx | |||
9439 | , unsigned SI | |||
9440 | ) | |||
9441 | : TypeAttr(attr::TypeNullable, R, SI, false) | |||
9442 | { | |||
9443 | } | |||
9444 | ||||
9445 | TypeNullableAttr *clone(ASTContext &C) const; | |||
9446 | void printPretty(raw_ostream &OS, | |||
9447 | const PrintingPolicy &Policy) const; | |||
9448 | const char *getSpelling() const; | |||
9449 | ||||
9450 | ||||
9451 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeNullable; } | |||
9452 | }; | |||
9453 | ||||
9454 | class TypeTagForDatatypeAttr : public InheritableAttr { | |||
9455 | IdentifierInfo * argumentKind; | |||
9456 | ||||
9457 | TypeSourceInfo * matchingCType; | |||
9458 | ||||
9459 | bool layoutCompatible; | |||
9460 | ||||
9461 | bool mustBeNull; | |||
9462 | ||||
9463 | public: | |||
9464 | static TypeTagForDatatypeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * ArgumentKind, TypeSourceInfo * MatchingCType, bool LayoutCompatible, bool MustBeNull, SourceRange Loc = SourceRange()) { | |||
9465 | auto *A = new (Ctx) TypeTagForDatatypeAttr(Loc, Ctx, ArgumentKind, MatchingCType, LayoutCompatible, MustBeNull, 0); | |||
9466 | A->setImplicit(true); | |||
9467 | return A; | |||
9468 | } | |||
9469 | ||||
9470 | TypeTagForDatatypeAttr(SourceRange R, ASTContext &Ctx | |||
9471 | , IdentifierInfo * ArgumentKind | |||
9472 | , TypeSourceInfo * MatchingCType | |||
9473 | , bool LayoutCompatible | |||
9474 | , bool MustBeNull | |||
9475 | , unsigned SI | |||
9476 | ) | |||
9477 | : InheritableAttr(attr::TypeTagForDatatype, R, SI, false, false) | |||
9478 | , argumentKind(ArgumentKind) | |||
9479 | , matchingCType(MatchingCType) | |||
9480 | , layoutCompatible(LayoutCompatible) | |||
9481 | , mustBeNull(MustBeNull) | |||
9482 | { | |||
9483 | } | |||
9484 | ||||
9485 | TypeTagForDatatypeAttr *clone(ASTContext &C) const; | |||
9486 | void printPretty(raw_ostream &OS, | |||
9487 | const PrintingPolicy &Policy) const; | |||
9488 | const char *getSpelling() const; | |||
9489 | IdentifierInfo * getArgumentKind() const { | |||
9490 | return argumentKind; | |||
9491 | } | |||
9492 | ||||
9493 | QualType getMatchingCType() const { | |||
9494 | return matchingCType->getType(); | |||
9495 | } TypeSourceInfo * getMatchingCTypeLoc() const { | |||
9496 | return matchingCType; | |||
9497 | } | |||
9498 | ||||
9499 | bool getLayoutCompatible() const { | |||
9500 | return layoutCompatible; | |||
9501 | } | |||
9502 | ||||
9503 | bool getMustBeNull() const { | |||
9504 | return mustBeNull; | |||
9505 | } | |||
9506 | ||||
9507 | ||||
9508 | ||||
9509 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeTagForDatatype; } | |||
9510 | }; | |||
9511 | ||||
9512 | class TypeVisibilityAttr : public InheritableAttr { | |||
9513 | public: | |||
9514 | enum VisibilityType { | |||
9515 | Default, | |||
9516 | Hidden, | |||
9517 | Protected | |||
9518 | }; | |||
9519 | private: | |||
9520 | VisibilityType visibility; | |||
9521 | ||||
9522 | public: | |||
9523 | static TypeVisibilityAttr *CreateImplicit(ASTContext &Ctx, VisibilityType Visibility, SourceRange Loc = SourceRange()) { | |||
9524 | auto *A = new (Ctx) TypeVisibilityAttr(Loc, Ctx, Visibility, 0); | |||
9525 | A->setImplicit(true); | |||
9526 | return A; | |||
9527 | } | |||
9528 | ||||
9529 | TypeVisibilityAttr(SourceRange R, ASTContext &Ctx | |||
9530 | , VisibilityType Visibility | |||
9531 | , unsigned SI | |||
9532 | ) | |||
9533 | : InheritableAttr(attr::TypeVisibility, R, SI, false, false) | |||
9534 | , visibility(Visibility) | |||
9535 | { | |||
9536 | } | |||
9537 | ||||
9538 | TypeVisibilityAttr *clone(ASTContext &C) const; | |||
9539 | void printPretty(raw_ostream &OS, | |||
9540 | const PrintingPolicy &Policy) const; | |||
9541 | const char *getSpelling() const; | |||
9542 | VisibilityType getVisibility() const { | |||
9543 | return visibility; | |||
9544 | } | |||
9545 | ||||
9546 | static bool ConvertStrToVisibilityType(StringRef Val, VisibilityType &Out) { | |||
9547 | Optional<VisibilityType> R = llvm::StringSwitch<Optional<VisibilityType>>(Val) | |||
9548 | .Case("default", TypeVisibilityAttr::Default) | |||
9549 | .Case("hidden", TypeVisibilityAttr::Hidden) | |||
9550 | .Case("internal", TypeVisibilityAttr::Hidden) | |||
9551 | .Case("protected", TypeVisibilityAttr::Protected) | |||
9552 | .Default(Optional<VisibilityType>()); | |||
9553 | if (R) { | |||
9554 | Out = *R; | |||
9555 | return true; | |||
9556 | } | |||
9557 | return false; | |||
9558 | } | |||
9559 | ||||
9560 | static const char *ConvertVisibilityTypeToStr(VisibilityType Val) { | |||
9561 | switch(Val) { | |||
9562 | case TypeVisibilityAttr::Default: return "default"; | |||
9563 | case TypeVisibilityAttr::Hidden: return "hidden"; | |||
9564 | case TypeVisibilityAttr::Protected: return "protected"; | |||
9565 | } | |||
9566 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9566); | |||
9567 | } | |||
9568 | ||||
9569 | ||||
9570 | static bool classof(const Attr *A) { return A->getKind() == attr::TypeVisibility; } | |||
9571 | }; | |||
9572 | ||||
9573 | class UPtrAttr : public TypeAttr { | |||
9574 | public: | |||
9575 | static UPtrAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9576 | auto *A = new (Ctx) UPtrAttr(Loc, Ctx, 0); | |||
9577 | A->setImplicit(true); | |||
9578 | return A; | |||
9579 | } | |||
9580 | ||||
9581 | UPtrAttr(SourceRange R, ASTContext &Ctx | |||
9582 | , unsigned SI | |||
9583 | ) | |||
9584 | : TypeAttr(attr::UPtr, R, SI, false) | |||
9585 | { | |||
9586 | } | |||
9587 | ||||
9588 | UPtrAttr *clone(ASTContext &C) const; | |||
9589 | void printPretty(raw_ostream &OS, | |||
9590 | const PrintingPolicy &Policy) const; | |||
9591 | const char *getSpelling() const; | |||
9592 | ||||
9593 | ||||
9594 | static bool classof(const Attr *A) { return A->getKind() == attr::UPtr; } | |||
9595 | }; | |||
9596 | ||||
9597 | class UnavailableAttr : public InheritableAttr { | |||
9598 | unsigned messageLength; | |||
9599 | char *message; | |||
9600 | ||||
9601 | public: | |||
9602 | enum ImplicitReason { | |||
9603 | IR_None, | |||
9604 | IR_ARCForbiddenType, | |||
9605 | IR_ForbiddenWeak, | |||
9606 | IR_ARCForbiddenConversion, | |||
9607 | IR_ARCInitReturnsUnrelated, | |||
9608 | IR_ARCFieldWithOwnership | |||
9609 | }; | |||
9610 | private: | |||
9611 | ImplicitReason implicitReason; | |||
9612 | ||||
9613 | public: | |||
9614 | static UnavailableAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, ImplicitReason ImplicitReason, SourceRange Loc = SourceRange()) { | |||
9615 | auto *A = new (Ctx) UnavailableAttr(Loc, Ctx, Message, ImplicitReason, 0); | |||
9616 | A->setImplicit(true); | |||
9617 | return A; | |||
9618 | } | |||
9619 | ||||
9620 | static UnavailableAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, SourceRange Loc = SourceRange()) { | |||
9621 | auto *A = new (Ctx) UnavailableAttr(Loc, Ctx, Message, 0); | |||
9622 | A->setImplicit(true); | |||
9623 | return A; | |||
9624 | } | |||
9625 | ||||
9626 | UnavailableAttr(SourceRange R, ASTContext &Ctx | |||
9627 | , llvm::StringRef Message | |||
9628 | , ImplicitReason ImplicitReason | |||
9629 | , unsigned SI | |||
9630 | ) | |||
9631 | : InheritableAttr(attr::Unavailable, R, SI, false, false) | |||
9632 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
9633 | , implicitReason(ImplicitReason) | |||
9634 | { | |||
9635 | if (!Message.empty()) | |||
9636 | std::memcpy(message, Message.data(), messageLength); | |||
9637 | } | |||
9638 | ||||
9639 | UnavailableAttr(SourceRange R, ASTContext &Ctx | |||
9640 | , llvm::StringRef Message | |||
9641 | , unsigned SI | |||
9642 | ) | |||
9643 | : InheritableAttr(attr::Unavailable, R, SI, false, false) | |||
9644 | , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength]) | |||
9645 | , implicitReason(ImplicitReason(0)) | |||
9646 | { | |||
9647 | if (!Message.empty()) | |||
9648 | std::memcpy(message, Message.data(), messageLength); | |||
9649 | } | |||
9650 | ||||
9651 | UnavailableAttr(SourceRange R, ASTContext &Ctx | |||
9652 | , unsigned SI | |||
9653 | ) | |||
9654 | : InheritableAttr(attr::Unavailable, R, SI, false, false) | |||
9655 | , messageLength(0),message(nullptr) | |||
9656 | , implicitReason(ImplicitReason(0)) | |||
9657 | { | |||
9658 | } | |||
9659 | ||||
9660 | UnavailableAttr *clone(ASTContext &C) const; | |||
9661 | void printPretty(raw_ostream &OS, | |||
9662 | const PrintingPolicy &Policy) const; | |||
9663 | const char *getSpelling() const; | |||
9664 | llvm::StringRef getMessage() const { | |||
9665 | return llvm::StringRef(message, messageLength); | |||
9666 | } | |||
9667 | unsigned getMessageLength() const { | |||
9668 | return messageLength; | |||
9669 | } | |||
9670 | void setMessage(ASTContext &C, llvm::StringRef S) { | |||
9671 | messageLength = S.size(); | |||
9672 | this->message = new (C, 1) char [messageLength]; | |||
9673 | if (!S.empty()) | |||
9674 | std::memcpy(this->message, S.data(), messageLength); | |||
9675 | } | |||
9676 | ||||
9677 | ImplicitReason getImplicitReason() const { | |||
9678 | return implicitReason; | |||
9679 | } | |||
9680 | ||||
9681 | ||||
9682 | ||||
9683 | static bool classof(const Attr *A) { return A->getKind() == attr::Unavailable; } | |||
9684 | }; | |||
9685 | ||||
9686 | class UninitializedAttr : public InheritableAttr { | |||
9687 | public: | |||
9688 | static UninitializedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9689 | auto *A = new (Ctx) UninitializedAttr(Loc, Ctx, 0); | |||
9690 | A->setImplicit(true); | |||
9691 | return A; | |||
9692 | } | |||
9693 | ||||
9694 | UninitializedAttr(SourceRange R, ASTContext &Ctx | |||
9695 | , unsigned SI | |||
9696 | ) | |||
9697 | : InheritableAttr(attr::Uninitialized, R, SI, false, false) | |||
9698 | { | |||
9699 | } | |||
9700 | ||||
9701 | UninitializedAttr *clone(ASTContext &C) const; | |||
9702 | void printPretty(raw_ostream &OS, | |||
9703 | const PrintingPolicy &Policy) const; | |||
9704 | const char *getSpelling() const; | |||
9705 | ||||
9706 | ||||
9707 | static bool classof(const Attr *A) { return A->getKind() == attr::Uninitialized; } | |||
9708 | }; | |||
9709 | ||||
9710 | class UnusedAttr : public InheritableAttr { | |||
9711 | public: | |||
9712 | enum Spelling { | |||
9713 | CXX11_maybe_unused = 0, | |||
9714 | GNU_unused = 1, | |||
9715 | CXX11_gnu_unused = 2, | |||
9716 | C2x_maybe_unused = 3 | |||
9717 | }; | |||
9718 | ||||
9719 | static UnusedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
9720 | auto *A = new (Ctx) UnusedAttr(Loc, Ctx, S); | |||
9721 | A->setImplicit(true); | |||
9722 | return A; | |||
9723 | } | |||
9724 | ||||
9725 | UnusedAttr(SourceRange R, ASTContext &Ctx | |||
9726 | , unsigned SI | |||
9727 | ) | |||
9728 | : InheritableAttr(attr::Unused, R, SI, false, false) | |||
9729 | { | |||
9730 | } | |||
9731 | ||||
9732 | UnusedAttr *clone(ASTContext &C) const; | |||
9733 | void printPretty(raw_ostream &OS, | |||
9734 | const PrintingPolicy &Policy) const; | |||
9735 | const char *getSpelling() const; | |||
9736 | Spelling getSemanticSpelling() const { | |||
9737 | switch (SpellingListIndex) { | |||
9738 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9738); | |||
9739 | case 0: return CXX11_maybe_unused; | |||
9740 | case 1: return GNU_unused; | |||
9741 | case 2: return CXX11_gnu_unused; | |||
9742 | case 3: return C2x_maybe_unused; | |||
9743 | } | |||
9744 | } | |||
9745 | ||||
9746 | ||||
9747 | static bool classof(const Attr *A) { return A->getKind() == attr::Unused; } | |||
9748 | }; | |||
9749 | ||||
9750 | class UsedAttr : public InheritableAttr { | |||
9751 | public: | |||
9752 | static UsedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9753 | auto *A = new (Ctx) UsedAttr(Loc, Ctx, 0); | |||
9754 | A->setImplicit(true); | |||
9755 | return A; | |||
9756 | } | |||
9757 | ||||
9758 | UsedAttr(SourceRange R, ASTContext &Ctx | |||
9759 | , unsigned SI | |||
9760 | ) | |||
9761 | : InheritableAttr(attr::Used, R, SI, false, false) | |||
9762 | { | |||
9763 | } | |||
9764 | ||||
9765 | UsedAttr *clone(ASTContext &C) const; | |||
9766 | void printPretty(raw_ostream &OS, | |||
9767 | const PrintingPolicy &Policy) const; | |||
9768 | const char *getSpelling() const; | |||
9769 | ||||
9770 | ||||
9771 | static bool classof(const Attr *A) { return A->getKind() == attr::Used; } | |||
9772 | }; | |||
9773 | ||||
9774 | class UuidAttr : public InheritableAttr { | |||
9775 | unsigned guidLength; | |||
9776 | char *guid; | |||
9777 | ||||
9778 | public: | |||
9779 | static UuidAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Guid, SourceRange Loc = SourceRange()) { | |||
9780 | auto *A = new (Ctx) UuidAttr(Loc, Ctx, Guid, 0); | |||
9781 | A->setImplicit(true); | |||
9782 | return A; | |||
9783 | } | |||
9784 | ||||
9785 | UuidAttr(SourceRange R, ASTContext &Ctx | |||
9786 | , llvm::StringRef Guid | |||
9787 | , unsigned SI | |||
9788 | ) | |||
9789 | : InheritableAttr(attr::Uuid, R, SI, false, false) | |||
9790 | , guidLength(Guid.size()),guid(new (Ctx, 1) char[guidLength]) | |||
9791 | { | |||
9792 | if (!Guid.empty()) | |||
9793 | std::memcpy(guid, Guid.data(), guidLength); | |||
9794 | } | |||
9795 | ||||
9796 | UuidAttr *clone(ASTContext &C) const; | |||
9797 | void printPretty(raw_ostream &OS, | |||
9798 | const PrintingPolicy &Policy) const; | |||
9799 | const char *getSpelling() const; | |||
9800 | llvm::StringRef getGuid() const { | |||
9801 | return llvm::StringRef(guid, guidLength); | |||
9802 | } | |||
9803 | unsigned getGuidLength() const { | |||
9804 | return guidLength; | |||
9805 | } | |||
9806 | void setGuid(ASTContext &C, llvm::StringRef S) { | |||
9807 | guidLength = S.size(); | |||
9808 | this->guid = new (C, 1) char [guidLength]; | |||
9809 | if (!S.empty()) | |||
9810 | std::memcpy(this->guid, S.data(), guidLength); | |||
9811 | } | |||
9812 | ||||
9813 | ||||
9814 | ||||
9815 | static bool classof(const Attr *A) { return A->getKind() == attr::Uuid; } | |||
9816 | }; | |||
9817 | ||||
9818 | class VecReturnAttr : public InheritableAttr { | |||
9819 | public: | |||
9820 | static VecReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9821 | auto *A = new (Ctx) VecReturnAttr(Loc, Ctx, 0); | |||
9822 | A->setImplicit(true); | |||
9823 | return A; | |||
9824 | } | |||
9825 | ||||
9826 | VecReturnAttr(SourceRange R, ASTContext &Ctx | |||
9827 | , unsigned SI | |||
9828 | ) | |||
9829 | : InheritableAttr(attr::VecReturn, R, SI, false, false) | |||
9830 | { | |||
9831 | } | |||
9832 | ||||
9833 | VecReturnAttr *clone(ASTContext &C) const; | |||
9834 | void printPretty(raw_ostream &OS, | |||
9835 | const PrintingPolicy &Policy) const; | |||
9836 | const char *getSpelling() const; | |||
9837 | ||||
9838 | ||||
9839 | static bool classof(const Attr *A) { return A->getKind() == attr::VecReturn; } | |||
9840 | }; | |||
9841 | ||||
9842 | class VecTypeHintAttr : public InheritableAttr { | |||
9843 | TypeSourceInfo * typeHint; | |||
9844 | ||||
9845 | public: | |||
9846 | static VecTypeHintAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * TypeHint, SourceRange Loc = SourceRange()) { | |||
9847 | auto *A = new (Ctx) VecTypeHintAttr(Loc, Ctx, TypeHint, 0); | |||
9848 | A->setImplicit(true); | |||
9849 | return A; | |||
9850 | } | |||
9851 | ||||
9852 | VecTypeHintAttr(SourceRange R, ASTContext &Ctx | |||
9853 | , TypeSourceInfo * TypeHint | |||
9854 | , unsigned SI | |||
9855 | ) | |||
9856 | : InheritableAttr(attr::VecTypeHint, R, SI, false, false) | |||
9857 | , typeHint(TypeHint) | |||
9858 | { | |||
9859 | } | |||
9860 | ||||
9861 | VecTypeHintAttr *clone(ASTContext &C) const; | |||
9862 | void printPretty(raw_ostream &OS, | |||
9863 | const PrintingPolicy &Policy) const; | |||
9864 | const char *getSpelling() const; | |||
9865 | QualType getTypeHint() const { | |||
9866 | return typeHint->getType(); | |||
9867 | } TypeSourceInfo * getTypeHintLoc() const { | |||
9868 | return typeHint; | |||
9869 | } | |||
9870 | ||||
9871 | ||||
9872 | ||||
9873 | static bool classof(const Attr *A) { return A->getKind() == attr::VecTypeHint; } | |||
9874 | }; | |||
9875 | ||||
9876 | class VectorCallAttr : public InheritableAttr { | |||
9877 | public: | |||
9878 | static VectorCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9879 | auto *A = new (Ctx) VectorCallAttr(Loc, Ctx, 0); | |||
9880 | A->setImplicit(true); | |||
9881 | return A; | |||
9882 | } | |||
9883 | ||||
9884 | VectorCallAttr(SourceRange R, ASTContext &Ctx | |||
9885 | , unsigned SI | |||
9886 | ) | |||
9887 | : InheritableAttr(attr::VectorCall, R, SI, false, false) | |||
9888 | { | |||
9889 | } | |||
9890 | ||||
9891 | VectorCallAttr *clone(ASTContext &C) const; | |||
9892 | void printPretty(raw_ostream &OS, | |||
9893 | const PrintingPolicy &Policy) const; | |||
9894 | const char *getSpelling() const; | |||
9895 | ||||
9896 | ||||
9897 | static bool classof(const Attr *A) { return A->getKind() == attr::VectorCall; } | |||
9898 | }; | |||
9899 | ||||
9900 | class VisibilityAttr : public InheritableAttr { | |||
9901 | public: | |||
9902 | enum VisibilityType { | |||
9903 | Default, | |||
9904 | Hidden, | |||
9905 | Protected | |||
9906 | }; | |||
9907 | private: | |||
9908 | VisibilityType visibility; | |||
9909 | ||||
9910 | public: | |||
9911 | static VisibilityAttr *CreateImplicit(ASTContext &Ctx, VisibilityType Visibility, SourceRange Loc = SourceRange()) { | |||
9912 | auto *A = new (Ctx) VisibilityAttr(Loc, Ctx, Visibility, 0); | |||
9913 | A->setImplicit(true); | |||
9914 | return A; | |||
9915 | } | |||
9916 | ||||
9917 | VisibilityAttr(SourceRange R, ASTContext &Ctx | |||
9918 | , VisibilityType Visibility | |||
9919 | , unsigned SI | |||
9920 | ) | |||
9921 | : InheritableAttr(attr::Visibility, R, SI, false, false) | |||
9922 | , visibility(Visibility) | |||
9923 | { | |||
9924 | } | |||
9925 | ||||
9926 | VisibilityAttr *clone(ASTContext &C) const; | |||
9927 | void printPretty(raw_ostream &OS, | |||
9928 | const PrintingPolicy &Policy) const; | |||
9929 | const char *getSpelling() const; | |||
9930 | VisibilityType getVisibility() const { | |||
9931 | return visibility; | |||
9932 | } | |||
9933 | ||||
9934 | static bool ConvertStrToVisibilityType(StringRef Val, VisibilityType &Out) { | |||
9935 | Optional<VisibilityType> R = llvm::StringSwitch<Optional<VisibilityType>>(Val) | |||
9936 | .Case("default", VisibilityAttr::Default) | |||
9937 | .Case("hidden", VisibilityAttr::Hidden) | |||
9938 | .Case("internal", VisibilityAttr::Hidden) | |||
9939 | .Case("protected", VisibilityAttr::Protected) | |||
9940 | .Default(Optional<VisibilityType>()); | |||
9941 | if (R) { | |||
9942 | Out = *R; | |||
9943 | return true; | |||
9944 | } | |||
9945 | return false; | |||
9946 | } | |||
9947 | ||||
9948 | static const char *ConvertVisibilityTypeToStr(VisibilityType Val) { | |||
9949 | switch(Val) { | |||
9950 | case VisibilityAttr::Default: return "default"; | |||
9951 | case VisibilityAttr::Hidden: return "hidden"; | |||
9952 | case VisibilityAttr::Protected: return "protected"; | |||
9953 | } | |||
9954 | llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 9954); | |||
9955 | } | |||
9956 | ||||
9957 | ||||
9958 | static bool classof(const Attr *A) { return A->getKind() == attr::Visibility; } | |||
9959 | }; | |||
9960 | ||||
9961 | class WarnUnusedAttr : public InheritableAttr { | |||
9962 | public: | |||
9963 | static WarnUnusedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
9964 | auto *A = new (Ctx) WarnUnusedAttr(Loc, Ctx, 0); | |||
9965 | A->setImplicit(true); | |||
9966 | return A; | |||
9967 | } | |||
9968 | ||||
9969 | WarnUnusedAttr(SourceRange R, ASTContext &Ctx | |||
9970 | , unsigned SI | |||
9971 | ) | |||
9972 | : InheritableAttr(attr::WarnUnused, R, SI, false, false) | |||
9973 | { | |||
9974 | } | |||
9975 | ||||
9976 | WarnUnusedAttr *clone(ASTContext &C) const; | |||
9977 | void printPretty(raw_ostream &OS, | |||
9978 | const PrintingPolicy &Policy) const; | |||
9979 | const char *getSpelling() const; | |||
9980 | ||||
9981 | ||||
9982 | static bool classof(const Attr *A) { return A->getKind() == attr::WarnUnused; } | |||
9983 | }; | |||
9984 | ||||
9985 | class WarnUnusedResultAttr : public InheritableAttr { | |||
9986 | public: | |||
9987 | enum Spelling { | |||
9988 | CXX11_nodiscard = 0, | |||
9989 | C2x_nodiscard = 1, | |||
9990 | CXX11_clang_warn_unused_result = 2, | |||
9991 | GNU_warn_unused_result = 3, | |||
9992 | CXX11_gnu_warn_unused_result = 4 | |||
9993 | }; | |||
9994 | ||||
9995 | static WarnUnusedResultAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
9996 | auto *A = new (Ctx) WarnUnusedResultAttr(Loc, Ctx, S); | |||
9997 | A->setImplicit(true); | |||
9998 | return A; | |||
9999 | } | |||
10000 | ||||
10001 | WarnUnusedResultAttr(SourceRange R, ASTContext &Ctx | |||
10002 | , unsigned SI | |||
10003 | ) | |||
10004 | : InheritableAttr(attr::WarnUnusedResult, R, SI, false, false) | |||
10005 | { | |||
10006 | } | |||
10007 | ||||
10008 | WarnUnusedResultAttr *clone(ASTContext &C) const; | |||
10009 | void printPretty(raw_ostream &OS, | |||
10010 | const PrintingPolicy &Policy) const; | |||
10011 | const char *getSpelling() const; | |||
10012 | Spelling getSemanticSpelling() const { | |||
10013 | switch (SpellingListIndex) { | |||
10014 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 10014); | |||
10015 | case 0: return CXX11_nodiscard; | |||
10016 | case 1: return C2x_nodiscard; | |||
10017 | case 2: return CXX11_clang_warn_unused_result; | |||
10018 | case 3: return GNU_warn_unused_result; | |||
10019 | case 4: return CXX11_gnu_warn_unused_result; | |||
10020 | } | |||
10021 | } | |||
10022 | ||||
10023 | ||||
10024 | static bool classof(const Attr *A) { return A->getKind() == attr::WarnUnusedResult; } | |||
10025 | }; | |||
10026 | ||||
10027 | class WeakAttr : public InheritableAttr { | |||
10028 | public: | |||
10029 | static WeakAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
10030 | auto *A = new (Ctx) WeakAttr(Loc, Ctx, 0); | |||
10031 | A->setImplicit(true); | |||
10032 | return A; | |||
10033 | } | |||
10034 | ||||
10035 | WeakAttr(SourceRange R, ASTContext &Ctx | |||
10036 | , unsigned SI | |||
10037 | ) | |||
10038 | : InheritableAttr(attr::Weak, R, SI, false, false) | |||
10039 | { | |||
10040 | } | |||
10041 | ||||
10042 | WeakAttr *clone(ASTContext &C) const; | |||
10043 | void printPretty(raw_ostream &OS, | |||
10044 | const PrintingPolicy &Policy) const; | |||
10045 | const char *getSpelling() const; | |||
10046 | ||||
10047 | ||||
10048 | static bool classof(const Attr *A) { return A->getKind() == attr::Weak; } | |||
10049 | }; | |||
10050 | ||||
10051 | class WeakImportAttr : public InheritableAttr { | |||
10052 | public: | |||
10053 | static WeakImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
10054 | auto *A = new (Ctx) WeakImportAttr(Loc, Ctx, 0); | |||
10055 | A->setImplicit(true); | |||
10056 | return A; | |||
10057 | } | |||
10058 | ||||
10059 | WeakImportAttr(SourceRange R, ASTContext &Ctx | |||
10060 | , unsigned SI | |||
10061 | ) | |||
10062 | : InheritableAttr(attr::WeakImport, R, SI, false, false) | |||
10063 | { | |||
10064 | } | |||
10065 | ||||
10066 | WeakImportAttr *clone(ASTContext &C) const; | |||
10067 | void printPretty(raw_ostream &OS, | |||
10068 | const PrintingPolicy &Policy) const; | |||
10069 | const char *getSpelling() const; | |||
10070 | ||||
10071 | ||||
10072 | static bool classof(const Attr *A) { return A->getKind() == attr::WeakImport; } | |||
10073 | }; | |||
10074 | ||||
10075 | class WeakRefAttr : public InheritableAttr { | |||
10076 | unsigned aliaseeLength; | |||
10077 | char *aliasee; | |||
10078 | ||||
10079 | public: | |||
10080 | static WeakRefAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) { | |||
10081 | auto *A = new (Ctx) WeakRefAttr(Loc, Ctx, Aliasee, 0); | |||
10082 | A->setImplicit(true); | |||
10083 | return A; | |||
10084 | } | |||
10085 | ||||
10086 | WeakRefAttr(SourceRange R, ASTContext &Ctx | |||
10087 | , llvm::StringRef Aliasee | |||
10088 | , unsigned SI | |||
10089 | ) | |||
10090 | : InheritableAttr(attr::WeakRef, R, SI, false, false) | |||
10091 | , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength]) | |||
10092 | { | |||
10093 | if (!Aliasee.empty()) | |||
10094 | std::memcpy(aliasee, Aliasee.data(), aliaseeLength); | |||
10095 | } | |||
10096 | ||||
10097 | WeakRefAttr(SourceRange R, ASTContext &Ctx | |||
10098 | , unsigned SI | |||
10099 | ) | |||
10100 | : InheritableAttr(attr::WeakRef, R, SI, false, false) | |||
10101 | , aliaseeLength(0),aliasee(nullptr) | |||
10102 | { | |||
10103 | } | |||
10104 | ||||
10105 | WeakRefAttr *clone(ASTContext &C) const; | |||
10106 | void printPretty(raw_ostream &OS, | |||
10107 | const PrintingPolicy &Policy) const; | |||
10108 | const char *getSpelling() const; | |||
10109 | llvm::StringRef getAliasee() const { | |||
10110 | return llvm::StringRef(aliasee, aliaseeLength); | |||
10111 | } | |||
10112 | unsigned getAliaseeLength() const { | |||
10113 | return aliaseeLength; | |||
10114 | } | |||
10115 | void setAliasee(ASTContext &C, llvm::StringRef S) { | |||
10116 | aliaseeLength = S.size(); | |||
10117 | this->aliasee = new (C, 1) char [aliaseeLength]; | |||
10118 | if (!S.empty()) | |||
10119 | std::memcpy(this->aliasee, S.data(), aliaseeLength); | |||
10120 | } | |||
10121 | ||||
10122 | ||||
10123 | ||||
10124 | static bool classof(const Attr *A) { return A->getKind() == attr::WeakRef; } | |||
10125 | }; | |||
10126 | ||||
10127 | class WebAssemblyImportModuleAttr : public InheritableAttr { | |||
10128 | unsigned importModuleLength; | |||
10129 | char *importModule; | |||
10130 | ||||
10131 | public: | |||
10132 | static WebAssemblyImportModuleAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef ImportModule, SourceRange Loc = SourceRange()) { | |||
10133 | auto *A = new (Ctx) WebAssemblyImportModuleAttr(Loc, Ctx, ImportModule, 0); | |||
10134 | A->setImplicit(true); | |||
10135 | return A; | |||
10136 | } | |||
10137 | ||||
10138 | WebAssemblyImportModuleAttr(SourceRange R, ASTContext &Ctx | |||
10139 | , llvm::StringRef ImportModule | |||
10140 | , unsigned SI | |||
10141 | ) | |||
10142 | : InheritableAttr(attr::WebAssemblyImportModule, R, SI, false, false) | |||
10143 | , importModuleLength(ImportModule.size()),importModule(new (Ctx, 1) char[importModuleLength]) | |||
10144 | { | |||
10145 | if (!ImportModule.empty()) | |||
10146 | std::memcpy(importModule, ImportModule.data(), importModuleLength); | |||
10147 | } | |||
10148 | ||||
10149 | WebAssemblyImportModuleAttr *clone(ASTContext &C) const; | |||
10150 | void printPretty(raw_ostream &OS, | |||
10151 | const PrintingPolicy &Policy) const; | |||
10152 | const char *getSpelling() const; | |||
10153 | llvm::StringRef getImportModule() const { | |||
10154 | return llvm::StringRef(importModule, importModuleLength); | |||
10155 | } | |||
10156 | unsigned getImportModuleLength() const { | |||
10157 | return importModuleLength; | |||
10158 | } | |||
10159 | void setImportModule(ASTContext &C, llvm::StringRef S) { | |||
10160 | importModuleLength = S.size(); | |||
10161 | this->importModule = new (C, 1) char [importModuleLength]; | |||
10162 | if (!S.empty()) | |||
10163 | std::memcpy(this->importModule, S.data(), importModuleLength); | |||
10164 | } | |||
10165 | ||||
10166 | ||||
10167 | ||||
10168 | static bool classof(const Attr *A) { return A->getKind() == attr::WebAssemblyImportModule; } | |||
10169 | }; | |||
10170 | ||||
10171 | class WebAssemblyImportNameAttr : public InheritableAttr { | |||
10172 | unsigned importNameLength; | |||
10173 | char *importName; | |||
10174 | ||||
10175 | public: | |||
10176 | static WebAssemblyImportNameAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef ImportName, SourceRange Loc = SourceRange()) { | |||
10177 | auto *A = new (Ctx) WebAssemblyImportNameAttr(Loc, Ctx, ImportName, 0); | |||
10178 | A->setImplicit(true); | |||
10179 | return A; | |||
10180 | } | |||
10181 | ||||
10182 | WebAssemblyImportNameAttr(SourceRange R, ASTContext &Ctx | |||
10183 | , llvm::StringRef ImportName | |||
10184 | , unsigned SI | |||
10185 | ) | |||
10186 | : InheritableAttr(attr::WebAssemblyImportName, R, SI, false, false) | |||
10187 | , importNameLength(ImportName.size()),importName(new (Ctx, 1) char[importNameLength]) | |||
10188 | { | |||
10189 | if (!ImportName.empty()) | |||
10190 | std::memcpy(importName, ImportName.data(), importNameLength); | |||
10191 | } | |||
10192 | ||||
10193 | WebAssemblyImportNameAttr *clone(ASTContext &C) const; | |||
10194 | void printPretty(raw_ostream &OS, | |||
10195 | const PrintingPolicy &Policy) const; | |||
10196 | const char *getSpelling() const; | |||
10197 | llvm::StringRef getImportName() const { | |||
10198 | return llvm::StringRef(importName, importNameLength); | |||
10199 | } | |||
10200 | unsigned getImportNameLength() const { | |||
10201 | return importNameLength; | |||
10202 | } | |||
10203 | void setImportName(ASTContext &C, llvm::StringRef S) { | |||
10204 | importNameLength = S.size(); | |||
10205 | this->importName = new (C, 1) char [importNameLength]; | |||
10206 | if (!S.empty()) | |||
10207 | std::memcpy(this->importName, S.data(), importNameLength); | |||
10208 | } | |||
10209 | ||||
10210 | ||||
10211 | ||||
10212 | static bool classof(const Attr *A) { return A->getKind() == attr::WebAssemblyImportName; } | |||
10213 | }; | |||
10214 | ||||
10215 | class WorkGroupSizeHintAttr : public InheritableAttr { | |||
10216 | unsigned xDim; | |||
10217 | ||||
10218 | unsigned yDim; | |||
10219 | ||||
10220 | unsigned zDim; | |||
10221 | ||||
10222 | public: | |||
10223 | static WorkGroupSizeHintAttr *CreateImplicit(ASTContext &Ctx, unsigned XDim, unsigned YDim, unsigned ZDim, SourceRange Loc = SourceRange()) { | |||
10224 | auto *A = new (Ctx) WorkGroupSizeHintAttr(Loc, Ctx, XDim, YDim, ZDim, 0); | |||
10225 | A->setImplicit(true); | |||
10226 | return A; | |||
10227 | } | |||
10228 | ||||
10229 | WorkGroupSizeHintAttr(SourceRange R, ASTContext &Ctx | |||
10230 | , unsigned XDim | |||
10231 | , unsigned YDim | |||
10232 | , unsigned ZDim | |||
10233 | , unsigned SI | |||
10234 | ) | |||
10235 | : InheritableAttr(attr::WorkGroupSizeHint, R, SI, false, false) | |||
10236 | , xDim(XDim) | |||
10237 | , yDim(YDim) | |||
10238 | , zDim(ZDim) | |||
10239 | { | |||
10240 | } | |||
10241 | ||||
10242 | WorkGroupSizeHintAttr *clone(ASTContext &C) const; | |||
10243 | void printPretty(raw_ostream &OS, | |||
10244 | const PrintingPolicy &Policy) const; | |||
10245 | const char *getSpelling() const; | |||
10246 | unsigned getXDim() const { | |||
10247 | return xDim; | |||
10248 | } | |||
10249 | ||||
10250 | unsigned getYDim() const { | |||
10251 | return yDim; | |||
10252 | } | |||
10253 | ||||
10254 | unsigned getZDim() const { | |||
10255 | return zDim; | |||
10256 | } | |||
10257 | ||||
10258 | ||||
10259 | ||||
10260 | static bool classof(const Attr *A) { return A->getKind() == attr::WorkGroupSizeHint; } | |||
10261 | }; | |||
10262 | ||||
10263 | class X86ForceAlignArgPointerAttr : public InheritableAttr { | |||
10264 | public: | |||
10265 | static X86ForceAlignArgPointerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) { | |||
10266 | auto *A = new (Ctx) X86ForceAlignArgPointerAttr(Loc, Ctx, 0); | |||
10267 | A->setImplicit(true); | |||
10268 | return A; | |||
10269 | } | |||
10270 | ||||
10271 | X86ForceAlignArgPointerAttr(SourceRange R, ASTContext &Ctx | |||
10272 | , unsigned SI | |||
10273 | ) | |||
10274 | : InheritableAttr(attr::X86ForceAlignArgPointer, R, SI, false, false) | |||
10275 | { | |||
10276 | } | |||
10277 | ||||
10278 | X86ForceAlignArgPointerAttr *clone(ASTContext &C) const; | |||
10279 | void printPretty(raw_ostream &OS, | |||
10280 | const PrintingPolicy &Policy) const; | |||
10281 | const char *getSpelling() const; | |||
10282 | ||||
10283 | ||||
10284 | static bool classof(const Attr *A) { return A->getKind() == attr::X86ForceAlignArgPointer; } | |||
10285 | }; | |||
10286 | ||||
10287 | class XRayInstrumentAttr : public InheritableAttr { | |||
10288 | public: | |||
10289 | enum Spelling { | |||
10290 | GNU_xray_always_instrument = 0, | |||
10291 | CXX11_clang_xray_always_instrument = 1, | |||
10292 | C2x_clang_xray_always_instrument = 2, | |||
10293 | GNU_xray_never_instrument = 3, | |||
10294 | CXX11_clang_xray_never_instrument = 4, | |||
10295 | C2x_clang_xray_never_instrument = 5 | |||
10296 | }; | |||
10297 | ||||
10298 | static XRayInstrumentAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) { | |||
10299 | auto *A = new (Ctx) XRayInstrumentAttr(Loc, Ctx, S); | |||
10300 | A->setImplicit(true); | |||
10301 | return A; | |||
10302 | } | |||
10303 | ||||
10304 | XRayInstrumentAttr(SourceRange R, ASTContext &Ctx | |||
10305 | , unsigned SI | |||
10306 | ) | |||
10307 | : InheritableAttr(attr::XRayInstrument, R, SI, false, false) | |||
10308 | { | |||
10309 | } | |||
10310 | ||||
10311 | XRayInstrumentAttr *clone(ASTContext &C) const; | |||
10312 | void printPretty(raw_ostream &OS, | |||
10313 | const PrintingPolicy &Policy) const; | |||
10314 | const char *getSpelling() const; | |||
10315 | Spelling getSemanticSpelling() const { | |||
10316 | switch (SpellingListIndex) { | |||
10317 | default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index" , "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc" , 10317); | |||
10318 | case 0: return GNU_xray_always_instrument; | |||
10319 | case 1: return CXX11_clang_xray_always_instrument; | |||
10320 | case 2: return C2x_clang_xray_always_instrument; | |||
10321 | case 3: return GNU_xray_never_instrument; | |||
10322 | case 4: return CXX11_clang_xray_never_instrument; | |||
10323 | case 5: return C2x_clang_xray_never_instrument; | |||
10324 | } | |||
10325 | } | |||
10326 | bool alwaysXRayInstrument() const { return SpellingListIndex == 0 || | |||
10327 | SpellingListIndex == 1 || | |||
10328 | SpellingListIndex == 2; } | |||
10329 | bool neverXRayInstrument() const { return SpellingListIndex == 3 || | |||
10330 | SpellingListIndex == 4 || | |||
10331 | SpellingListIndex == 5; } | |||
10332 | ||||
10333 | ||||
10334 | static bool classof(const Attr *A) { return A->getKind() == attr::XRayInstrument; } | |||
10335 | }; | |||
10336 | ||||
10337 | class XRayLogArgsAttr : public InheritableAttr { | |||
10338 | unsigned argumentCount; | |||
10339 | ||||
10340 | public: | |||
10341 | static XRayLogArgsAttr *CreateImplicit(ASTContext &Ctx, unsigned ArgumentCount, SourceRange Loc = SourceRange()) { | |||
10342 | auto *A = new (Ctx) XRayLogArgsAttr(Loc, Ctx, ArgumentCount, 0); | |||
10343 | A->setImplicit(true); | |||
10344 | return A; | |||
10345 | } | |||
10346 | ||||
10347 | XRayLogArgsAttr(SourceRange R, ASTContext &Ctx | |||
10348 | , unsigned ArgumentCount | |||
10349 | , unsigned SI | |||
10350 | ) | |||
10351 | : InheritableAttr(attr::XRayLogArgs, R, SI, false, false) | |||
10352 | , argumentCount(ArgumentCount) | |||
10353 | { | |||
10354 | } | |||
10355 | ||||
10356 | XRayLogArgsAttr *clone(ASTContext &C) const; | |||
10357 | void printPretty(raw_ostream &OS, | |||
10358 | const PrintingPolicy &Policy) const; | |||
10359 | const char *getSpelling() const; | |||
10360 | unsigned getArgumentCount() const { | |||
10361 | return argumentCount; | |||
10362 | } | |||
10363 | ||||
10364 | ||||
10365 | ||||
10366 | static bool classof(const Attr *A) { return A->getKind() == attr::XRayLogArgs; } | |||
10367 | }; | |||
10368 | ||||
10369 | #endif // LLVM_CLANG_ATTR_CLASSES_INC |