1//===- TypeLoc.h - Type Source Info Wrapper ---------------------*- C++ -*-===//
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/// \file
10/// Defines the clang::TypeLoc interface and its subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_TYPELOC_H
15#define LLVM_CLANG_AST_TYPELOC_H
16
17#include "clang/AST/ASTConcept.h"
18#include "clang/AST/DeclarationName.h"
19#include "clang/AST/NestedNameSpecifierBase.h"
20#include "clang/AST/TemplateBase.h"
21#include "clang/AST/TypeBase.h"
22#include "clang/Basic/LLVM.h"
23#include "clang/Basic/SourceLocation.h"
24#include "clang/Basic/Specifiers.h"
25#include "llvm/ADT/ArrayRef.h"
26#include "llvm/Support/Casting.h"
27#include "llvm/Support/Compiler.h"
28#include "llvm/Support/MathExtras.h"
29#include <algorithm>
30#include <cassert>
31#include <cstdint>
32#include <cstring>
33
34namespace clang {
35
36class Attr;
37class ASTContext;
38class CXXRecordDecl;
39class ConceptDecl;
40class Expr;
41class ObjCInterfaceDecl;
42class ObjCProtocolDecl;
43class ObjCTypeParamDecl;
44class ParmVarDecl;
45class TemplateTypeParmDecl;
46class UnqualTypeLoc;
47class UnresolvedUsingTypenameDecl;
48
49// Predeclare all the type nodes.
50#define ABSTRACT_TYPELOC(Class, Base)
51#define TYPELOC(Class, Base) \
52 class Class##TypeLoc;
53#include "clang/AST/TypeLocNodes.def"
54
55/// Base wrapper for a particular "section" of type source info.
56///
57/// A client should use the TypeLoc subclasses through castAs()/getAs()
58/// in order to get at the actual information.
59class TypeLoc {
60protected:
61 // The correctness of this relies on the property that, for Type *Ty,
62 // QualType(Ty, 0).getAsOpaquePtr() == (void*) Ty
63 const void *Ty = nullptr;
64 void *Data = nullptr;
65
66public:
67 TypeLoc() = default;
68 TypeLoc(QualType ty, void *opaqueData)
69 : Ty(ty.getAsOpaquePtr()), Data(opaqueData) {}
70 TypeLoc(const Type *ty, void *opaqueData)
71 : Ty(ty), Data(opaqueData) {}
72
73 /// Convert to the specified TypeLoc type, asserting that this TypeLoc
74 /// is of the desired type.
75 ///
76 /// \pre T::isKind(*this)
77 template<typename T>
78 T castAs() const {
79 assert(T::isKind(*this));
80 T t;
81 TypeLoc& tl = t;
82 tl = *this;
83 return t;
84 }
85
86 /// Convert to the specified TypeLoc type, returning a null TypeLoc if
87 /// this TypeLoc is not of the desired type.
88 template<typename T>
89 T getAs() const {
90 if (!T::isKind(*this))
91 return {};
92 T t;
93 TypeLoc& tl = t;
94 tl = *this;
95 return t;
96 }
97
98 /// Convert to the specified TypeLoc type, returning a null TypeLoc if
99 /// this TypeLoc is not of the desired type. It will consider type
100 /// adjustments from a type that was written as a T to another type that is
101 /// still canonically a T (ignores parens, attributes, elaborated types, etc).
102 template <typename T>
103 T getAsAdjusted() const;
104
105 /// The kinds of TypeLocs. Equivalent to the Type::TypeClass enum,
106 /// except it also defines a Qualified enum that corresponds to the
107 /// QualifiedLoc class.
108 enum TypeLocClass {
109#define ABSTRACT_TYPE(Class, Base)
110#define TYPE(Class, Base) \
111 Class = Type::Class,
112#include "clang/AST/TypeNodes.inc"
113 Qualified
114 };
115
116 TypeLocClass getTypeLocClass() const {
117 if (getType().hasLocalQualifiers()) return Qualified;
118 return (TypeLocClass) getType()->getTypeClass();
119 }
120
121 bool isNull() const { return !Ty; }
122 explicit operator bool() const { return Ty; }
123
124 /// Returns the size of type source info data block for the given type.
125 static unsigned getFullDataSizeForType(QualType Ty);
126
127 /// Returns the alignment of type source info data block for
128 /// the given type.
129 static unsigned getLocalAlignmentForType(QualType Ty);
130
131 /// Get the type for which this source info wrapper provides
132 /// information.
133 QualType getType() const {
134 return QualType::getFromOpaquePtr(Ptr: Ty);
135 }
136
137 const Type *getTypePtr() const {
138 return QualType::getFromOpaquePtr(Ptr: Ty).getTypePtr();
139 }
140
141 /// Get the pointer where source information is stored.
142 // FIXME: This should provide a type-safe interface.
143 void *getOpaqueData() const {
144 return Data;
145 }
146
147 /// Get the begin source location.
148 SourceLocation getBeginLoc() const;
149
150 /// Get the end source location.
151 SourceLocation getEndLoc() const;
152
153 /// Get the full source range.
154 SourceRange getSourceRange() const LLVM_READONLY {
155 return SourceRange(getBeginLoc(), getEndLoc());
156 }
157
158
159 /// Get the local source range.
160 SourceRange getLocalSourceRange() const {
161 return getLocalSourceRangeImpl(TL: *this);
162 }
163
164 /// Returns the size of the type source info data block.
165 unsigned getFullDataSize() const {
166 return getFullDataSizeForType(Ty: getType());
167 }
168
169 /// Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the
170 /// TypeLoc is a PointerLoc and next TypeLoc is for "int".
171 TypeLoc getNextTypeLoc() const {
172 return getNextTypeLocImpl(TL: *this);
173 }
174
175 /// Skips past any qualifiers, if this is qualified.
176 UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header
177
178 TypeLoc IgnoreParens() const;
179
180 /// Find a type with the location of an explicit type qualifier.
181 ///
182 /// The result, if non-null, will be one of:
183 /// QualifiedTypeLoc
184 /// AtomicTypeLoc
185 /// AttributedTypeLoc, for those type attributes that behave as qualifiers
186 TypeLoc findExplicitQualifierLoc() const;
187
188 /// Get the typeloc of an AutoType whose type will be deduced for a variable
189 /// with an initializer of this type. This looks through declarators like
190 /// pointer types, but not through decltype or typedefs.
191 AutoTypeLoc getContainedAutoTypeLoc() const;
192
193 /// Get the SourceLocation of the template keyword (if any).
194 SourceLocation getTemplateKeywordLoc() const;
195
196 /// If this type represents a qualified-id, this returns it's nested name
197 /// specifier. For example, for the qualified-id "foo::bar::baz", this returns
198 /// "foo::bar". Returns null if this type represents an unqualified-id.
199 NestedNameSpecifierLoc getPrefix() const;
200
201 /// This returns the position of the type after any elaboration, such as the
202 /// 'struct' keyword. This may be the position of the name qualifiers,
203 /// 'template' keyword, or the name location otherwise.
204 SourceLocation getNonElaboratedBeginLoc() const;
205
206 /// Initializes this to state that every location in this
207 /// type is the given location.
208 ///
209 /// This method exists to provide a simple transition for code that
210 /// relies on location-less types.
211 void initialize(ASTContext &Context, SourceLocation Loc) const {
212 initializeImpl(Context, TL: *this, Loc);
213 }
214
215 /// Initializes this by copying its information from another
216 /// TypeLoc of the same type.
217 void initializeFullCopy(TypeLoc Other) {
218 assert(getType() == Other.getType());
219 copy(other: Other);
220 }
221
222 /// Initializes this by copying its information from another
223 /// TypeLoc of the same type. The given size must be the full data
224 /// size.
225 void initializeFullCopy(TypeLoc Other, unsigned Size) {
226 assert(getType() == Other.getType());
227 assert(getFullDataSize() == Size);
228 copy(other: Other);
229 }
230
231 /// Copies the other type loc into this one.
232 void copy(TypeLoc other);
233
234 friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) {
235 return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data;
236 }
237
238 friend bool operator!=(const TypeLoc &LHS, const TypeLoc &RHS) {
239 return !(LHS == RHS);
240 }
241
242 /// Find the location of the nullability specifier (__nonnull,
243 /// __nullable, or __null_unspecifier), if there is one.
244 SourceLocation findNullabilityLoc() const;
245
246 void dump() const;
247 void dump(llvm::raw_ostream &, const ASTContext &) const;
248
249private:
250 static bool isKind(const TypeLoc&) {
251 return true;
252 }
253
254 static void initializeImpl(ASTContext &Context, TypeLoc TL,
255 SourceLocation Loc);
256 static TypeLoc getNextTypeLocImpl(TypeLoc TL);
257 static TypeLoc IgnoreParensImpl(TypeLoc TL);
258 static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
259};
260
261inline TypeSourceInfo::TypeSourceInfo(QualType ty, size_t DataSize) : Ty(ty) {
262 // Init data attached to the object. See getTypeLoc.
263 memset(s: static_cast<void *>(this + 1), c: 0, n: DataSize);
264}
265
266/// Return the TypeLoc for a type source info.
267inline TypeLoc TypeSourceInfo::getTypeLoc() const {
268 // TODO: is this alignment already sufficient?
269 return TypeLoc(Ty, const_cast<void*>(static_cast<const void*>(this + 1)));
270}
271
272/// Wrapper of type source information for a type with
273/// no direct qualifiers.
274class UnqualTypeLoc : public TypeLoc {
275public:
276 UnqualTypeLoc() = default;
277 UnqualTypeLoc(const Type *Ty, void *Data) : TypeLoc(Ty, Data) {}
278
279 const Type *getTypePtr() const {
280 return reinterpret_cast<const Type*>(Ty);
281 }
282
283 TypeLocClass getTypeLocClass() const {
284 return (TypeLocClass) getTypePtr()->getTypeClass();
285 }
286
287private:
288 friend class TypeLoc;
289
290 static bool isKind(const TypeLoc &TL) {
291 return !TL.getType().hasLocalQualifiers();
292 }
293};
294
295/// Wrapper of type source information for a type with
296/// non-trivial direct qualifiers.
297///
298/// Currently, we intentionally do not provide source location for
299/// type qualifiers.
300class QualifiedTypeLoc : public TypeLoc {
301public:
302 SourceRange getLocalSourceRange() const { return {}; }
303
304 UnqualTypeLoc getUnqualifiedLoc() const {
305 unsigned align =
306 TypeLoc::getLocalAlignmentForType(Ty: QualType(getTypePtr(), 0));
307 auto dataInt = reinterpret_cast<uintptr_t>(Data);
308 dataInt = llvm::alignTo(Value: dataInt, Align: align);
309 return UnqualTypeLoc(getTypePtr(), reinterpret_cast<void*>(dataInt));
310 }
311
312 /// Initializes the local data of this type source info block to
313 /// provide no information.
314 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
315 // do nothing
316 }
317
318 void copyLocal(TypeLoc other) {
319 // do nothing
320 }
321
322 TypeLoc getNextTypeLoc() const {
323 return getUnqualifiedLoc();
324 }
325
326 /// Returns the size of the type source info data block that is
327 /// specific to this type.
328 unsigned getLocalDataSize() const {
329 // In fact, we don't currently preserve any location information
330 // for qualifiers.
331 return 0;
332 }
333
334 /// Returns the alignment of the type source info data block that is
335 /// specific to this type.
336 unsigned getLocalDataAlignment() const {
337 // We don't preserve any location information.
338 return 1;
339 }
340
341private:
342 friend class TypeLoc;
343
344 static bool isKind(const TypeLoc &TL) {
345 return TL.getType().hasLocalQualifiers();
346 }
347};
348
349inline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {
350 if (QualifiedTypeLoc Loc = getAs<QualifiedTypeLoc>())
351 return Loc.getUnqualifiedLoc();
352 return castAs<UnqualTypeLoc>();
353}
354
355/// A metaprogramming base class for TypeLoc classes which correspond
356/// to a particular Type subclass. It is accepted for a single
357/// TypeLoc class to correspond to multiple Type classes.
358///
359/// \tparam Base a class from which to derive
360/// \tparam Derived the class deriving from this one
361/// \tparam TypeClass the concrete Type subclass associated with this
362/// location type
363/// \tparam LocalData the structure type of local location data for
364/// this type
365///
366/// TypeLocs with non-constant amounts of local data should override
367/// getExtraLocalDataSize(); getExtraLocalData() will then point to
368/// this extra memory.
369///
370/// TypeLocs with an inner type should define
371/// QualType getInnerType() const
372/// and getInnerTypeLoc() will then point to this inner type's
373/// location data.
374///
375/// A word about hierarchies: this template is not designed to be
376/// derived from multiple times in a hierarchy. It is also not
377/// designed to be used for classes where subtypes might provide
378/// different amounts of source information. It should be subclassed
379/// only at the deepest portion of the hierarchy where all children
380/// have identical source information; if that's an abstract type,
381/// then further descendents should inherit from
382/// InheritingConcreteTypeLoc instead.
383template <class Base, class Derived, class TypeClass, class LocalData>
384class ConcreteTypeLoc : public Base {
385 friend class TypeLoc;
386
387 const Derived *asDerived() const {
388 return static_cast<const Derived*>(this);
389 }
390
391 static bool isKind(const TypeLoc &TL) {
392 return !TL.getType().hasLocalQualifiers() &&
393 Derived::classofType(TL.getTypePtr());
394 }
395
396 static bool classofType(const Type *Ty) {
397 return TypeClass::classof(Ty);
398 }
399
400public:
401 unsigned getLocalDataAlignment() const {
402 return std::max(unsigned(alignof(LocalData)),
403 asDerived()->getExtraLocalDataAlignment());
404 }
405
406 unsigned getLocalDataSize() const {
407 unsigned size = sizeof(LocalData);
408 unsigned extraAlign = asDerived()->getExtraLocalDataAlignment();
409 size = llvm::alignTo(Value: size, Align: extraAlign);
410 size += asDerived()->getExtraLocalDataSize();
411 size = llvm::alignTo(size, asDerived()->getLocalDataAlignment());
412 return size;
413 }
414
415 void copyLocal(Derived other) {
416 // Some subclasses have no data to copy.
417 if (asDerived()->getLocalDataSize() == 0) return;
418
419 // Copy the fixed-sized local data.
420 memcpy(getLocalData(), other.getLocalData(), sizeof(LocalData));
421
422 // Copy the variable-sized local data. We need to do this
423 // separately because the padding in the source and the padding in
424 // the destination might be different.
425 memcpy(getExtraLocalData(), other.getExtraLocalData(),
426 asDerived()->getExtraLocalDataSize());
427 }
428
429 TypeLoc getNextTypeLoc() const {
430 return getNextTypeLoc(asDerived()->getInnerType());
431 }
432
433 const TypeClass *getTypePtr() const {
434 return cast<TypeClass>(Base::getTypePtr());
435 }
436
437protected:
438 unsigned getExtraLocalDataSize() const {
439 return 0;
440 }
441
442 unsigned getExtraLocalDataAlignment() const {
443 return 1;
444 }
445
446 LocalData *getLocalData() const {
447 return static_cast<LocalData*>(Base::Data);
448 }
449
450 /// Gets a pointer past the Info structure; useful for classes with
451 /// local data that can't be captured in the Info (e.g. because it's
452 /// of variable size).
453 void *getExtraLocalData() const {
454 unsigned size = sizeof(LocalData);
455 unsigned extraAlign = asDerived()->getExtraLocalDataAlignment();
456 size = llvm::alignTo(Value: size, Align: extraAlign);
457 return reinterpret_cast<char *>(Base::Data) + size;
458 }
459
460 void *getNonLocalData() const {
461 auto data = reinterpret_cast<uintptr_t>(Base::Data);
462 data += asDerived()->getLocalDataSize();
463 data = llvm::alignTo(data, getNextTypeAlign());
464 return reinterpret_cast<void*>(data);
465 }
466
467 struct HasNoInnerType {};
468 HasNoInnerType getInnerType() const { return HasNoInnerType(); }
469
470 TypeLoc getInnerTypeLoc() const {
471 return TypeLoc(asDerived()->getInnerType(), getNonLocalData());
472 }
473
474private:
475 unsigned getInnerTypeSize() const {
476 return getInnerTypeSize(asDerived()->getInnerType());
477 }
478
479 unsigned getInnerTypeSize(HasNoInnerType _) const {
480 return 0;
481 }
482
483 unsigned getInnerTypeSize(QualType _) const {
484 return getInnerTypeLoc().getFullDataSize();
485 }
486
487 unsigned getNextTypeAlign() const {
488 return getNextTypeAlign(asDerived()->getInnerType());
489 }
490
491 unsigned getNextTypeAlign(HasNoInnerType _) const {
492 return 1;
493 }
494
495 unsigned getNextTypeAlign(QualType T) const {
496 return TypeLoc::getLocalAlignmentForType(Ty: T);
497 }
498
499 TypeLoc getNextTypeLoc(HasNoInnerType _) const { return {}; }
500
501 TypeLoc getNextTypeLoc(QualType T) const {
502 return TypeLoc(T, getNonLocalData());
503 }
504};
505
506/// A metaprogramming class designed for concrete subtypes of abstract
507/// types where all subtypes share equivalently-structured source
508/// information. See the note on ConcreteTypeLoc.
509template <class Base, class Derived, class TypeClass>
510class InheritingConcreteTypeLoc : public Base {
511 friend class TypeLoc;
512
513 static bool classofType(const Type *Ty) {
514 return TypeClass::classof(Ty);
515 }
516
517 static bool isKind(const TypeLoc &TL) {
518 return !TL.getType().hasLocalQualifiers() &&
519 Derived::classofType(TL.getTypePtr());
520 }
521 static bool isKind(const UnqualTypeLoc &TL) {
522 return Derived::classofType(TL.getTypePtr());
523 }
524
525public:
526 const TypeClass *getTypePtr() const {
527 return cast<TypeClass>(Base::getTypePtr());
528 }
529};
530
531struct TypeSpecLocInfo {
532 SourceLocation NameLoc;
533};
534
535/// A reasonable base class for TypeLocs that correspond to
536/// types that are written as a type-specifier.
537class TypeSpecTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
538 TypeSpecTypeLoc,
539 Type,
540 TypeSpecLocInfo> {
541public:
542 enum {
543 LocalDataSize = sizeof(TypeSpecLocInfo),
544 LocalDataAlignment = alignof(TypeSpecLocInfo)
545 };
546
547 SourceLocation getNameLoc() const {
548 return this->getLocalData()->NameLoc;
549 }
550
551 void setNameLoc(SourceLocation Loc) {
552 this->getLocalData()->NameLoc = Loc;
553 }
554
555 SourceRange getLocalSourceRange() const {
556 return SourceRange(getNameLoc(), getNameLoc());
557 }
558
559 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
560 setNameLoc(Loc);
561 }
562
563private:
564 friend class TypeLoc;
565
566 static bool isKind(const TypeLoc &TL);
567};
568
569struct BuiltinLocInfo {
570 SourceRange BuiltinRange;
571};
572
573/// Wrapper for source info for builtin types.
574class BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
575 BuiltinTypeLoc,
576 BuiltinType,
577 BuiltinLocInfo> {
578public:
579 SourceLocation getBuiltinLoc() const {
580 return getLocalData()->BuiltinRange.getBegin();
581 }
582
583 void setBuiltinLoc(SourceLocation Loc) {
584 getLocalData()->BuiltinRange = Loc;
585 }
586
587 void expandBuiltinRange(SourceRange Range) {
588 SourceRange &BuiltinRange = getLocalData()->BuiltinRange;
589 if (!BuiltinRange.getBegin().isValid()) {
590 BuiltinRange = Range;
591 } else {
592 BuiltinRange.setBegin(std::min(a: Range.getBegin(), b: BuiltinRange.getBegin()));
593 BuiltinRange.setEnd(std::max(a: Range.getEnd(), b: BuiltinRange.getEnd()));
594 }
595 }
596
597 SourceLocation getNameLoc() const { return getBuiltinLoc(); }
598
599 WrittenBuiltinSpecs& getWrittenBuiltinSpecs() {
600 return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
601 }
602 const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
603 return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
604 }
605
606 bool needsExtraLocalData() const {
607 BuiltinType::Kind bk = getTypePtr()->getKind();
608 return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128) ||
609 (bk >= BuiltinType::Short && bk <= BuiltinType::Ibm128) ||
610 bk == BuiltinType::UChar || bk == BuiltinType::SChar;
611 }
612
613 unsigned getExtraLocalDataSize() const {
614 return needsExtraLocalData() ? sizeof(WrittenBuiltinSpecs) : 0;
615 }
616
617 unsigned getExtraLocalDataAlignment() const {
618 return needsExtraLocalData() ? alignof(WrittenBuiltinSpecs) : 1;
619 }
620
621 SourceRange getLocalSourceRange() const {
622 return getLocalData()->BuiltinRange;
623 }
624
625 TypeSpecifierSign getWrittenSignSpec() const {
626 if (needsExtraLocalData())
627 return static_cast<TypeSpecifierSign>(getWrittenBuiltinSpecs().Sign);
628 else
629 return TypeSpecifierSign::Unspecified;
630 }
631
632 bool hasWrittenSignSpec() const {
633 return getWrittenSignSpec() != TypeSpecifierSign::Unspecified;
634 }
635
636 void setWrittenSignSpec(TypeSpecifierSign written) {
637 if (needsExtraLocalData())
638 getWrittenBuiltinSpecs().Sign = static_cast<unsigned>(written);
639 }
640
641 TypeSpecifierWidth getWrittenWidthSpec() const {
642 if (needsExtraLocalData())
643 return static_cast<TypeSpecifierWidth>(getWrittenBuiltinSpecs().Width);
644 else
645 return TypeSpecifierWidth::Unspecified;
646 }
647
648 bool hasWrittenWidthSpec() const {
649 return getWrittenWidthSpec() != TypeSpecifierWidth::Unspecified;
650 }
651
652 void setWrittenWidthSpec(TypeSpecifierWidth written) {
653 if (needsExtraLocalData())
654 getWrittenBuiltinSpecs().Width = static_cast<unsigned>(written);
655 }
656
657 TypeSpecifierType getWrittenTypeSpec() const;
658
659 bool hasWrittenTypeSpec() const {
660 return getWrittenTypeSpec() != TST_unspecified;
661 }
662
663 void setWrittenTypeSpec(TypeSpecifierType written) {
664 if (needsExtraLocalData())
665 getWrittenBuiltinSpecs().Type = written;
666 }
667
668 bool hasModeAttr() const {
669 if (needsExtraLocalData())
670 return getWrittenBuiltinSpecs().ModeAttr;
671 else
672 return false;
673 }
674
675 void setModeAttr(bool written) {
676 if (needsExtraLocalData())
677 getWrittenBuiltinSpecs().ModeAttr = written;
678 }
679
680 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
681 setBuiltinLoc(Loc);
682 if (needsExtraLocalData()) {
683 WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs();
684 wbs.Sign = static_cast<unsigned>(TypeSpecifierSign::Unspecified);
685 wbs.Width = static_cast<unsigned>(TypeSpecifierWidth::Unspecified);
686 wbs.Type = TST_unspecified;
687 wbs.ModeAttr = false;
688 }
689 }
690};
691
692struct ElaboratedNameLocInfo {
693 SourceLocation NameLoc;
694 SourceLocation ElaboratedKeywordLoc;
695
696 ElaboratedNameLocInfo() = default;
697 ElaboratedNameLocInfo(SourceLocation ElaboratedKeywordLoc,
698 NestedNameSpecifierLoc QualifierLoc,
699 SourceLocation NameLoc)
700 : NameLoc(NameLoc), ElaboratedKeywordLoc(ElaboratedKeywordLoc),
701 QualifierData(QualifierLoc.getOpaqueData()) {}
702 ElaboratedNameLocInfo(ASTContext &Context, ElaboratedTypeKeyword Keyword,
703 NestedNameSpecifier Qualifier, SourceLocation Loc)
704 : NameLoc(Loc),
705 ElaboratedKeywordLoc(
706 Keyword != ElaboratedTypeKeyword::None ? Loc : SourceLocation()),
707 QualifierData(getTrivialQualifierData(Context, Qualifier, Loc)) {}
708
709 NestedNameSpecifierLoc getQualifierLoc(NestedNameSpecifier Qualifier) const {
710 assert(!Qualifier == !QualifierData);
711 return NestedNameSpecifierLoc(Qualifier, QualifierData);
712 }
713
714 SourceRange getLocalSourceRange(NestedNameSpecifier Qualifier) const {
715 SourceLocation BeginLoc = ElaboratedKeywordLoc;
716 if (NestedNameSpecifierLoc QualifierLoc = getQualifierLoc(Qualifier);
717 BeginLoc.isInvalid() && Qualifier)
718 BeginLoc = QualifierLoc.getBeginLoc();
719 if (BeginLoc.isInvalid())
720 BeginLoc = NameLoc;
721 return SourceRange(BeginLoc, NameLoc);
722 }
723
724private:
725 void *QualifierData;
726
727 static void *getTrivialQualifierData(ASTContext &Context,
728 NestedNameSpecifier Qualifier,
729 SourceLocation Loc) {
730 if (!Qualifier)
731 return nullptr;
732 NestedNameSpecifierLocBuilder Builder;
733 Builder.MakeTrivial(Context, Qualifier, R: Loc);
734 return Builder.getWithLocInContext(Context).getOpaqueData();
735 }
736};
737
738template <class TL, class T>
739class ElaboratedNameTypeLoc
740 : public ConcreteTypeLoc<UnqualTypeLoc, TL, T, ElaboratedNameLocInfo> {
741public:
742 auto *getDecl() const { return this->getTypePtr()->getDecl(); }
743
744 void set(SourceLocation ElaboratedKeywordLoc,
745 NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc) {
746 assert(QualifierLoc.getNestedNameSpecifier() ==
747 this->getTypePtr()->getQualifier());
748 *this->getLocalData() =
749 ElaboratedNameLocInfo(ElaboratedKeywordLoc, QualifierLoc, NameLoc);
750 }
751
752 SourceLocation getElaboratedKeywordLoc() const {
753 return this->getLocalData()->ElaboratedKeywordLoc;
754 }
755
756 NestedNameSpecifierLoc getQualifierLoc() const {
757 return this->getLocalData()->getQualifierLoc(
758 this->getTypePtr()->getQualifier());
759 }
760
761 SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; }
762
763 SourceRange getLocalSourceRange() const {
764 return this->getLocalData()->getLocalSourceRange(
765 this->getTypePtr()->getQualifier());
766 }
767
768 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
769 const auto *Ptr = this->getTypePtr();
770 *this->getLocalData() = ElaboratedNameLocInfo(Context, Ptr->getKeyword(),
771 Ptr->getQualifier(), Loc);
772 }
773};
774
775/// Wrapper for source info for typedefs.
776class TypedefTypeLoc
777 : public ElaboratedNameTypeLoc<TypedefTypeLoc, TypedefType> {};
778
779/// Wrapper for source info for unresolved typename using decls.
780class UnresolvedUsingTypeLoc
781 : public ElaboratedNameTypeLoc<UnresolvedUsingTypeLoc,
782 UnresolvedUsingType> {};
783
784/// Wrapper for source info for types used via transparent aliases.
785class UsingTypeLoc : public ElaboratedNameTypeLoc<UsingTypeLoc, UsingType> {};
786
787struct TagTypeLocInfo {
788 SourceLocation NameLoc;
789 SourceLocation ElaboratedKWLoc;
790 void *QualifierData;
791};
792
793class TagTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, TagTypeLoc, TagType,
794 TagTypeLocInfo> {
795public:
796 TagDecl *getDecl() const { return getTypePtr()->getDecl(); }
797
798 /// True if the tag was defined in this type specifier.
799 bool isDefinition() const;
800
801 SourceLocation getElaboratedKeywordLoc() const {
802 return getLocalData()->ElaboratedKWLoc;
803 }
804
805 void setElaboratedKeywordLoc(SourceLocation Loc) {
806 getLocalData()->ElaboratedKWLoc = Loc;
807 }
808
809 NestedNameSpecifierLoc getQualifierLoc() const {
810 NestedNameSpecifier Qualifier = getTypePtr()->getQualifier();
811 void *QualifierData = getLocalData()->QualifierData;
812 assert(!Qualifier == !QualifierData);
813 return NestedNameSpecifierLoc(Qualifier, QualifierData);
814 }
815
816 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
817 assert(QualifierLoc.getNestedNameSpecifier() ==
818 getTypePtr()->getQualifier());
819 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
820 }
821
822 SourceLocation getNameLoc() const { return getLocalData()->NameLoc; }
823
824 void setNameLoc(SourceLocation Loc) { getLocalData()->NameLoc = Loc; }
825
826 SourceRange getLocalSourceRange() const {
827 SourceLocation BeginLoc = getElaboratedKeywordLoc();
828 if (NestedNameSpecifierLoc Qualifier = getQualifierLoc();
829 BeginLoc.isInvalid() && Qualifier)
830 BeginLoc = Qualifier.getBeginLoc();
831 if (BeginLoc.isInvalid())
832 BeginLoc = getNameLoc();
833 return SourceRange(BeginLoc, getNameLoc());
834 }
835
836 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
837 setElaboratedKeywordLoc(getTypePtr()->getKeyword() !=
838 ElaboratedTypeKeyword::None
839 ? Loc
840 : SourceLocation());
841 if (NestedNameSpecifier Qualifier = getTypePtr()->getQualifier()) {
842 NestedNameSpecifierLocBuilder Builder;
843 Builder.MakeTrivial(Context, Qualifier, R: Loc);
844 setQualifierLoc(Builder.getWithLocInContext(Context));
845 } else {
846 getLocalData()->QualifierData = nullptr;
847 }
848 setNameLoc(Loc);
849 }
850};
851
852/// Wrapper for source info for record types.
853class RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
854 RecordTypeLoc,
855 RecordType> {
856public:
857 RecordDecl *getDecl() const { return getTypePtr()->getDecl(); }
858};
859
860/// Wrapper for source info for enum types.
861class EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
862 EnumTypeLoc,
863 EnumType> {
864public:
865 EnumDecl *getDecl() const { return getTypePtr()->getDecl(); }
866};
867
868/// Wrapper for source info for injected class names of class
869/// templates.
870class InjectedClassNameTypeLoc
871 : public InheritingConcreteTypeLoc<TagTypeLoc, InjectedClassNameTypeLoc,
872 InjectedClassNameType> {
873public:
874 CXXRecordDecl *getDecl() const { return getTypePtr()->getDecl(); }
875};
876
877/// Wrapper for template type parameters.
878class TemplateTypeParmTypeLoc :
879 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
880 TemplateTypeParmTypeLoc,
881 TemplateTypeParmType> {
882public:
883 TemplateTypeParmDecl *getDecl() const { return getTypePtr()->getDecl(); }
884};
885
886struct ObjCTypeParamTypeLocInfo {
887 SourceLocation NameLoc;
888};
889
890/// ProtocolLAngleLoc, ProtocolRAngleLoc, and the source locations for
891/// protocol qualifiers are stored after Info.
892class ObjCTypeParamTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
893 ObjCTypeParamTypeLoc,
894 ObjCTypeParamType,
895 ObjCTypeParamTypeLocInfo> {
896 // SourceLocations are stored after Info, one for each protocol qualifier.
897 SourceLocation *getProtocolLocArray() const {
898 return (SourceLocation*)this->getExtraLocalData() + 2;
899 }
900
901public:
902 ObjCTypeParamDecl *getDecl() const { return getTypePtr()->getDecl(); }
903
904 SourceLocation getNameLoc() const {
905 return this->getLocalData()->NameLoc;
906 }
907
908 void setNameLoc(SourceLocation Loc) {
909 this->getLocalData()->NameLoc = Loc;
910 }
911
912 SourceLocation getProtocolLAngleLoc() const {
913 return getNumProtocols() ?
914 *((SourceLocation*)this->getExtraLocalData()) :
915 SourceLocation();
916 }
917
918 void setProtocolLAngleLoc(SourceLocation Loc) {
919 *((SourceLocation*)this->getExtraLocalData()) = Loc;
920 }
921
922 SourceLocation getProtocolRAngleLoc() const {
923 return getNumProtocols() ?
924 *((SourceLocation*)this->getExtraLocalData() + 1) :
925 SourceLocation();
926 }
927
928 void setProtocolRAngleLoc(SourceLocation Loc) {
929 *((SourceLocation*)this->getExtraLocalData() + 1) = Loc;
930 }
931
932 unsigned getNumProtocols() const {
933 return this->getTypePtr()->getNumProtocols();
934 }
935
936 SourceLocation getProtocolLoc(unsigned i) const {
937 assert(i < getNumProtocols() && "Index is out of bounds!");
938 return getProtocolLocArray()[i];
939 }
940
941 void setProtocolLoc(unsigned i, SourceLocation Loc) {
942 assert(i < getNumProtocols() && "Index is out of bounds!");
943 getProtocolLocArray()[i] = Loc;
944 }
945
946 ObjCProtocolDecl *getProtocol(unsigned i) const {
947 assert(i < getNumProtocols() && "Index is out of bounds!");
948 return *(this->getTypePtr()->qual_begin() + i);
949 }
950
951 ArrayRef<SourceLocation> getProtocolLocs() const {
952 return {getProtocolLocArray(), getNumProtocols()};
953 }
954
955 void initializeLocal(ASTContext &Context, SourceLocation Loc);
956
957 unsigned getExtraLocalDataSize() const {
958 if (!this->getNumProtocols()) return 0;
959 // When there are protocol qualifers, we have LAngleLoc and RAngleLoc
960 // as well.
961 return (this->getNumProtocols() + 2) * sizeof(SourceLocation) ;
962 }
963
964 unsigned getExtraLocalDataAlignment() const {
965 return alignof(SourceLocation);
966 }
967
968 SourceRange getLocalSourceRange() const {
969 SourceLocation start = getNameLoc();
970 SourceLocation end = getProtocolRAngleLoc();
971 if (end.isInvalid()) return SourceRange(start, start);
972 return SourceRange(start, end);
973 }
974};
975
976/// Wrapper for substituted template type parameters.
977class SubstTemplateTypeParmTypeLoc :
978 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
979 SubstTemplateTypeParmTypeLoc,
980 SubstTemplateTypeParmType> {
981};
982
983/// Abstract type representing delayed type pack expansions.
984class SubstPackTypeLoc
985 : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, SubstPackTypeLoc,
986 SubstPackType> {};
987
988/// Wrapper for substituted template type parameters.
989class SubstTemplateTypeParmPackTypeLoc
990 : public InheritingConcreteTypeLoc<SubstPackTypeLoc,
991 SubstTemplateTypeParmPackTypeLoc,
992 SubstTemplateTypeParmPackType> {};
993
994/// Wrapper for substituted template type parameters.
995class SubstBuiltinTemplatePackTypeLoc
996 : public InheritingConcreteTypeLoc<SubstPackTypeLoc,
997 SubstBuiltinTemplatePackTypeLoc,
998 SubstBuiltinTemplatePackType> {};
999
1000struct AttributedLocInfo {
1001 const Attr *TypeAttr;
1002};
1003
1004/// Type source information for an attributed type.
1005class AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1006 AttributedTypeLoc,
1007 AttributedType,
1008 AttributedLocInfo> {
1009public:
1010 attr::Kind getAttrKind() const {
1011 return getTypePtr()->getAttrKind();
1012 }
1013
1014 bool isQualifier() const {
1015 return getTypePtr()->isQualifier();
1016 }
1017
1018 /// The modified type, which is generally canonically different from
1019 /// the attribute type.
1020 /// int main(int, char**) __attribute__((noreturn))
1021 /// ~~~ ~~~~~~~~~~~~~
1022 TypeLoc getModifiedLoc() const {
1023 return getInnerTypeLoc();
1024 }
1025
1026 TypeLoc getEquivalentTypeLoc() const {
1027 return TypeLoc(getTypePtr()->getEquivalentType(), getNonLocalData());
1028 }
1029
1030 /// The type attribute.
1031 const Attr *getAttr() const {
1032 return getLocalData()->TypeAttr;
1033 }
1034 void setAttr(const Attr *A) {
1035 getLocalData()->TypeAttr = A;
1036 }
1037
1038 template<typename T> const T *getAttrAs() {
1039 return dyn_cast_or_null<T>(getAttr());
1040 }
1041
1042 SourceRange getLocalSourceRange() const;
1043
1044 void initializeLocal(ASTContext &Context, SourceLocation loc) {
1045 setAttr(nullptr);
1046 }
1047
1048 QualType getInnerType() const {
1049 return getTypePtr()->getModifiedType();
1050 }
1051};
1052
1053struct BTFTagAttributedLocInfo {}; // Nothing.
1054
1055/// Type source information for an btf_tag attributed type.
1056class BTFTagAttributedTypeLoc
1057 : public ConcreteTypeLoc<UnqualTypeLoc, BTFTagAttributedTypeLoc,
1058 BTFTagAttributedType, BTFTagAttributedLocInfo> {
1059public:
1060 TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
1061
1062 /// The btf_type_tag attribute.
1063 const BTFTypeTagAttr *getAttr() const { return getTypePtr()->getAttr(); }
1064
1065 template <typename T> T *getAttrAs() {
1066 return dyn_cast_or_null<T>(getAttr());
1067 }
1068
1069 SourceRange getLocalSourceRange() const;
1070
1071 void initializeLocal(ASTContext &Context, SourceLocation loc) {}
1072
1073 QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
1074};
1075
1076struct OverflowBehaviorLocInfo {
1077 SourceLocation AttrLoc;
1078};
1079
1080class OverflowBehaviorTypeLoc
1081 : public ConcreteTypeLoc<UnqualTypeLoc, OverflowBehaviorTypeLoc,
1082 OverflowBehaviorType, OverflowBehaviorLocInfo> {
1083public:
1084 TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
1085
1086 /// The no_sanitize type attribute.
1087 OverflowBehaviorType::OverflowBehaviorKind getBehaviorKind() const {
1088 return getTypePtr()->getBehaviorKind();
1089 }
1090
1091 SourceRange getLocalSourceRange() const;
1092
1093 void initializeLocal(ASTContext &Context, SourceLocation loc) {
1094 setAttrLoc(loc);
1095 }
1096
1097 SourceLocation getAttrLoc() const { return getLocalData()->AttrLoc; }
1098
1099 void setAttrLoc(SourceLocation loc) { getLocalData()->AttrLoc = loc; }
1100
1101 QualType getInnerType() const { return getTypePtr()->getUnderlyingType(); }
1102};
1103
1104struct HLSLAttributedResourceLocInfo {
1105 SourceRange Range;
1106 TypeSourceInfo *ContainedTyInfo;
1107};
1108
1109/// Type source information for HLSL attributed resource type.
1110class HLSLAttributedResourceTypeLoc
1111 : public ConcreteTypeLoc<UnqualTypeLoc, HLSLAttributedResourceTypeLoc,
1112 HLSLAttributedResourceType,
1113 HLSLAttributedResourceLocInfo> {
1114public:
1115 TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
1116
1117 TypeSourceInfo *getContainedTypeSourceInfo() const {
1118 return getLocalData()->ContainedTyInfo;
1119 }
1120 void setContainedTypeSourceInfo(TypeSourceInfo *TSI) const {
1121 getLocalData()->ContainedTyInfo = TSI;
1122 }
1123
1124 void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
1125 SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
1126 void initializeLocal(ASTContext &Context, SourceLocation loc) {
1127 setSourceRange(SourceRange(loc));
1128 setContainedTypeSourceInfo(nullptr);
1129 }
1130 QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
1131 unsigned getLocalDataSize() const {
1132 return sizeof(HLSLAttributedResourceLocInfo);
1133 }
1134};
1135
1136struct HLSLInlineSpirvTypeLocInfo {
1137 SourceLocation Loc;
1138}; // Nothing.
1139
1140class HLSLInlineSpirvTypeLoc
1141 : public ConcreteTypeLoc<UnqualTypeLoc, HLSLInlineSpirvTypeLoc,
1142 HLSLInlineSpirvType, HLSLInlineSpirvTypeLocInfo> {
1143public:
1144 SourceLocation getSpirvTypeLoc() const { return getLocalData()->Loc; }
1145 void setSpirvTypeLoc(SourceLocation loc) const { getLocalData()->Loc = loc; }
1146
1147 SourceRange getLocalSourceRange() const {
1148 return SourceRange(getSpirvTypeLoc(), getSpirvTypeLoc());
1149 }
1150 void initializeLocal(ASTContext &Context, SourceLocation loc) {
1151 setSpirvTypeLoc(loc);
1152 }
1153};
1154
1155struct ObjCObjectTypeLocInfo {
1156 SourceLocation TypeArgsLAngleLoc;
1157 SourceLocation TypeArgsRAngleLoc;
1158 SourceLocation ProtocolLAngleLoc;
1159 SourceLocation ProtocolRAngleLoc;
1160 bool HasBaseTypeAsWritten;
1161};
1162
1163// A helper class for defining ObjC TypeLocs that can qualified with
1164// protocols.
1165//
1166// TypeClass basically has to be either ObjCInterfaceType or
1167// ObjCObjectPointerType.
1168class ObjCObjectTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1169 ObjCObjectTypeLoc,
1170 ObjCObjectType,
1171 ObjCObjectTypeLocInfo> {
1172 // TypeSourceInfo*'s are stored after Info, one for each type argument.
1173 TypeSourceInfo **getTypeArgLocArray() const {
1174 return (TypeSourceInfo**)this->getExtraLocalData();
1175 }
1176
1177 // SourceLocations are stored after the type argument information, one for
1178 // each Protocol.
1179 SourceLocation *getProtocolLocArray() const {
1180 return (SourceLocation*)(getTypeArgLocArray() + getNumTypeArgs());
1181 }
1182
1183public:
1184 SourceLocation getTypeArgsLAngleLoc() const {
1185 return this->getLocalData()->TypeArgsLAngleLoc;
1186 }
1187
1188 void setTypeArgsLAngleLoc(SourceLocation Loc) {
1189 this->getLocalData()->TypeArgsLAngleLoc = Loc;
1190 }
1191
1192 SourceLocation getTypeArgsRAngleLoc() const {
1193 return this->getLocalData()->TypeArgsRAngleLoc;
1194 }
1195
1196 void setTypeArgsRAngleLoc(SourceLocation Loc) {
1197 this->getLocalData()->TypeArgsRAngleLoc = Loc;
1198 }
1199
1200 unsigned getNumTypeArgs() const {
1201 return this->getTypePtr()->getTypeArgsAsWritten().size();
1202 }
1203
1204 TypeSourceInfo *getTypeArgTInfo(unsigned i) const {
1205 assert(i < getNumTypeArgs() && "Index is out of bounds!");
1206 return getTypeArgLocArray()[i];
1207 }
1208
1209 void setTypeArgTInfo(unsigned i, TypeSourceInfo *TInfo) {
1210 assert(i < getNumTypeArgs() && "Index is out of bounds!");
1211 getTypeArgLocArray()[i] = TInfo;
1212 }
1213
1214 SourceLocation getProtocolLAngleLoc() const {
1215 return this->getLocalData()->ProtocolLAngleLoc;
1216 }
1217
1218 void setProtocolLAngleLoc(SourceLocation Loc) {
1219 this->getLocalData()->ProtocolLAngleLoc = Loc;
1220 }
1221
1222 SourceLocation getProtocolRAngleLoc() const {
1223 return this->getLocalData()->ProtocolRAngleLoc;
1224 }
1225
1226 void setProtocolRAngleLoc(SourceLocation Loc) {
1227 this->getLocalData()->ProtocolRAngleLoc = Loc;
1228 }
1229
1230 unsigned getNumProtocols() const {
1231 return this->getTypePtr()->getNumProtocols();
1232 }
1233
1234 SourceLocation getProtocolLoc(unsigned i) const {
1235 assert(i < getNumProtocols() && "Index is out of bounds!");
1236 return getProtocolLocArray()[i];
1237 }
1238
1239 void setProtocolLoc(unsigned i, SourceLocation Loc) {
1240 assert(i < getNumProtocols() && "Index is out of bounds!");
1241 getProtocolLocArray()[i] = Loc;
1242 }
1243
1244 ObjCProtocolDecl *getProtocol(unsigned i) const {
1245 assert(i < getNumProtocols() && "Index is out of bounds!");
1246 return *(this->getTypePtr()->qual_begin() + i);
1247 }
1248
1249
1250 ArrayRef<SourceLocation> getProtocolLocs() const {
1251 return {getProtocolLocArray(), getNumProtocols()};
1252 }
1253
1254 bool hasBaseTypeAsWritten() const {
1255 return getLocalData()->HasBaseTypeAsWritten;
1256 }
1257
1258 void setHasBaseTypeAsWritten(bool HasBaseType) {
1259 getLocalData()->HasBaseTypeAsWritten = HasBaseType;
1260 }
1261
1262 TypeLoc getBaseLoc() const {
1263 return getInnerTypeLoc();
1264 }
1265
1266 SourceRange getLocalSourceRange() const {
1267 SourceLocation start = getTypeArgsLAngleLoc();
1268 if (start.isInvalid())
1269 start = getProtocolLAngleLoc();
1270 SourceLocation end = getProtocolRAngleLoc();
1271 if (end.isInvalid())
1272 end = getTypeArgsRAngleLoc();
1273 return SourceRange(start, end);
1274 }
1275
1276 void initializeLocal(ASTContext &Context, SourceLocation Loc);
1277
1278 unsigned getExtraLocalDataSize() const {
1279 return this->getNumTypeArgs() * sizeof(TypeSourceInfo *)
1280 + this->getNumProtocols() * sizeof(SourceLocation);
1281 }
1282
1283 unsigned getExtraLocalDataAlignment() const {
1284 static_assert(alignof(ObjCObjectTypeLoc) >= alignof(TypeSourceInfo *),
1285 "not enough alignment for tail-allocated data");
1286 return alignof(TypeSourceInfo *);
1287 }
1288
1289 QualType getInnerType() const {
1290 return getTypePtr()->getBaseType();
1291 }
1292};
1293
1294struct ObjCInterfaceLocInfo {
1295 SourceLocation NameLoc;
1296 SourceLocation NameEndLoc;
1297};
1298
1299/// Wrapper for source info for ObjC interfaces.
1300class ObjCInterfaceTypeLoc : public ConcreteTypeLoc<ObjCObjectTypeLoc,
1301 ObjCInterfaceTypeLoc,
1302 ObjCInterfaceType,
1303 ObjCInterfaceLocInfo> {
1304public:
1305 ObjCInterfaceDecl *getIFaceDecl() const {
1306 return getTypePtr()->getDecl();
1307 }
1308
1309 SourceLocation getNameLoc() const {
1310 return getLocalData()->NameLoc;
1311 }
1312
1313 void setNameLoc(SourceLocation Loc) {
1314 getLocalData()->NameLoc = Loc;
1315 }
1316
1317 SourceRange getLocalSourceRange() const {
1318 return SourceRange(getNameLoc(), getNameEndLoc());
1319 }
1320
1321 SourceLocation getNameEndLoc() const {
1322 return getLocalData()->NameEndLoc;
1323 }
1324
1325 void setNameEndLoc(SourceLocation Loc) {
1326 getLocalData()->NameEndLoc = Loc;
1327 }
1328
1329 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1330 setNameLoc(Loc);
1331 setNameEndLoc(Loc);
1332 }
1333};
1334
1335struct BoundsAttributedLocInfo {};
1336class BoundsAttributedTypeLoc
1337 : public ConcreteTypeLoc<UnqualTypeLoc, BoundsAttributedTypeLoc,
1338 BoundsAttributedType, BoundsAttributedLocInfo> {
1339public:
1340 TypeLoc getInnerLoc() const { return getInnerTypeLoc(); }
1341 QualType getInnerType() const { return getTypePtr()->desugar(); }
1342 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1343 // nothing to do
1344 }
1345 // LocalData is empty and TypeLocBuilder doesn't handle DataSize 1.
1346 unsigned getLocalDataSize() const { return 0; }
1347};
1348
1349class CountAttributedTypeLoc final
1350 : public InheritingConcreteTypeLoc<BoundsAttributedTypeLoc,
1351 CountAttributedTypeLoc,
1352 CountAttributedType> {
1353public:
1354 Expr *getCountExpr() const { return getTypePtr()->getCountExpr(); }
1355 bool isCountInBytes() const { return getTypePtr()->isCountInBytes(); }
1356 bool isOrNull() const { return getTypePtr()->isOrNull(); }
1357
1358 SourceRange getLocalSourceRange() const;
1359};
1360
1361struct MacroQualifiedLocInfo {
1362 SourceLocation ExpansionLoc;
1363};
1364
1365class MacroQualifiedTypeLoc
1366 : public ConcreteTypeLoc<UnqualTypeLoc, MacroQualifiedTypeLoc,
1367 MacroQualifiedType, MacroQualifiedLocInfo> {
1368public:
1369 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1370 setExpansionLoc(Loc);
1371 }
1372
1373 TypeLoc getInnerLoc() const { return getInnerTypeLoc(); }
1374
1375 const IdentifierInfo *getMacroIdentifier() const {
1376 return getTypePtr()->getMacroIdentifier();
1377 }
1378
1379 SourceLocation getExpansionLoc() const {
1380 return this->getLocalData()->ExpansionLoc;
1381 }
1382
1383 void setExpansionLoc(SourceLocation Loc) {
1384 this->getLocalData()->ExpansionLoc = Loc;
1385 }
1386
1387 QualType getInnerType() const { return getTypePtr()->getUnderlyingType(); }
1388
1389 SourceRange getLocalSourceRange() const {
1390 return getInnerLoc().getLocalSourceRange();
1391 }
1392};
1393
1394struct ParenLocInfo {
1395 SourceLocation LParenLoc;
1396 SourceLocation RParenLoc;
1397};
1398
1399class ParenTypeLoc
1400 : public ConcreteTypeLoc<UnqualTypeLoc, ParenTypeLoc, ParenType,
1401 ParenLocInfo> {
1402public:
1403 SourceLocation getLParenLoc() const {
1404 return this->getLocalData()->LParenLoc;
1405 }
1406
1407 SourceLocation getRParenLoc() const {
1408 return this->getLocalData()->RParenLoc;
1409 }
1410
1411 void setLParenLoc(SourceLocation Loc) {
1412 this->getLocalData()->LParenLoc = Loc;
1413 }
1414
1415 void setRParenLoc(SourceLocation Loc) {
1416 this->getLocalData()->RParenLoc = Loc;
1417 }
1418
1419 SourceRange getLocalSourceRange() const {
1420 return SourceRange(getLParenLoc(), getRParenLoc());
1421 }
1422
1423 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1424 setLParenLoc(Loc);
1425 setRParenLoc(Loc);
1426 }
1427
1428 TypeLoc getInnerLoc() const {
1429 return getInnerTypeLoc();
1430 }
1431
1432 QualType getInnerType() const {
1433 return this->getTypePtr()->getInnerType();
1434 }
1435};
1436
1437inline TypeLoc TypeLoc::IgnoreParens() const {
1438 if (ParenTypeLoc::isKind(TL: *this))
1439 return IgnoreParensImpl(TL: *this);
1440 return *this;
1441}
1442
1443struct AdjustedLocInfo {}; // Nothing.
1444
1445class AdjustedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, AdjustedTypeLoc,
1446 AdjustedType, AdjustedLocInfo> {
1447public:
1448 TypeLoc getOriginalLoc() const {
1449 return getInnerTypeLoc();
1450 }
1451
1452 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1453 // do nothing
1454 }
1455
1456 QualType getInnerType() const {
1457 // The inner type is the undecayed type, since that's what we have source
1458 // location information for.
1459 return getTypePtr()->getOriginalType();
1460 }
1461
1462 SourceRange getLocalSourceRange() const { return {}; }
1463
1464 unsigned getLocalDataSize() const {
1465 // sizeof(AdjustedLocInfo) is 1, but we don't need its address to be unique
1466 // anyway. TypeLocBuilder can't handle data sizes of 1.
1467 return 0; // No data.
1468 }
1469};
1470
1471/// Wrapper for source info for pointers decayed from arrays and
1472/// functions.
1473class DecayedTypeLoc : public InheritingConcreteTypeLoc<
1474 AdjustedTypeLoc, DecayedTypeLoc, DecayedType> {
1475};
1476
1477struct PointerLikeLocInfo {
1478 SourceLocation StarLoc;
1479};
1480
1481/// A base class for
1482template <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo>
1483class PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived,
1484 TypeClass, LocalData> {
1485public:
1486 SourceLocation getSigilLoc() const {
1487 return this->getLocalData()->StarLoc;
1488 }
1489
1490 void setSigilLoc(SourceLocation Loc) {
1491 this->getLocalData()->StarLoc = Loc;
1492 }
1493
1494 TypeLoc getPointeeLoc() const {
1495 return this->getInnerTypeLoc();
1496 }
1497
1498 SourceRange getLocalSourceRange() const {
1499 return SourceRange(getSigilLoc(), getSigilLoc());
1500 }
1501
1502 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1503 setSigilLoc(Loc);
1504 }
1505
1506 QualType getInnerType() const {
1507 return this->getTypePtr()->getPointeeType();
1508 }
1509};
1510
1511/// Wrapper for source info for pointers.
1512class PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc,
1513 PointerType> {
1514public:
1515 SourceLocation getStarLoc() const {
1516 return getSigilLoc();
1517 }
1518
1519 void setStarLoc(SourceLocation Loc) {
1520 setSigilLoc(Loc);
1521 }
1522};
1523
1524/// Wrapper for source info for block pointers.
1525class BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc,
1526 BlockPointerType> {
1527public:
1528 SourceLocation getCaretLoc() const {
1529 return getSigilLoc();
1530 }
1531
1532 void setCaretLoc(SourceLocation Loc) {
1533 setSigilLoc(Loc);
1534 }
1535};
1536
1537struct MemberPointerLocInfo : public PointerLikeLocInfo {
1538 void *QualifierData = nullptr;
1539};
1540
1541/// Wrapper for source info for member pointers.
1542class MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc,
1543 MemberPointerType,
1544 MemberPointerLocInfo> {
1545public:
1546 SourceLocation getStarLoc() const {
1547 return getSigilLoc();
1548 }
1549
1550 void setStarLoc(SourceLocation Loc) {
1551 setSigilLoc(Loc);
1552 }
1553
1554 NestedNameSpecifierLoc getQualifierLoc() const {
1555 return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
1556 getLocalData()->QualifierData);
1557 }
1558
1559 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1560 assert(QualifierLoc.getNestedNameSpecifier() ==
1561 getTypePtr()->getQualifier() &&
1562 "Inconsistent nested-name-specifier pointer");
1563 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1564 }
1565
1566 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1567 setSigilLoc(Loc);
1568 if (NestedNameSpecifier Qualifier = getTypePtr()->getQualifier()) {
1569 NestedNameSpecifierLocBuilder Builder;
1570 Builder.MakeTrivial(Context, Qualifier, R: Loc);
1571 setQualifierLoc(Builder.getWithLocInContext(Context));
1572 } else
1573 getLocalData()->QualifierData = nullptr;
1574 }
1575
1576 SourceRange getLocalSourceRange() const {
1577 if (NestedNameSpecifierLoc QL = getQualifierLoc())
1578 return SourceRange(QL.getBeginLoc(), getStarLoc());
1579 return SourceRange(getStarLoc());
1580 }
1581};
1582
1583/// Wraps an ObjCPointerType with source location information.
1584class ObjCObjectPointerTypeLoc :
1585 public PointerLikeTypeLoc<ObjCObjectPointerTypeLoc,
1586 ObjCObjectPointerType> {
1587public:
1588 SourceLocation getStarLoc() const {
1589 return getSigilLoc();
1590 }
1591
1592 void setStarLoc(SourceLocation Loc) {
1593 setSigilLoc(Loc);
1594 }
1595};
1596
1597class ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc,
1598 ReferenceType> {
1599public:
1600 QualType getInnerType() const {
1601 return getTypePtr()->getPointeeTypeAsWritten();
1602 }
1603};
1604
1605class LValueReferenceTypeLoc :
1606 public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1607 LValueReferenceTypeLoc,
1608 LValueReferenceType> {
1609public:
1610 SourceLocation getAmpLoc() const {
1611 return getSigilLoc();
1612 }
1613
1614 void setAmpLoc(SourceLocation Loc) {
1615 setSigilLoc(Loc);
1616 }
1617};
1618
1619class RValueReferenceTypeLoc :
1620 public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1621 RValueReferenceTypeLoc,
1622 RValueReferenceType> {
1623public:
1624 SourceLocation getAmpAmpLoc() const {
1625 return getSigilLoc();
1626 }
1627
1628 void setAmpAmpLoc(SourceLocation Loc) {
1629 setSigilLoc(Loc);
1630 }
1631};
1632
1633struct FunctionLocInfo {
1634 SourceLocation LocalRangeBegin;
1635 SourceLocation LParenLoc;
1636 SourceLocation RParenLoc;
1637 SourceLocation LocalRangeEnd;
1638};
1639
1640/// Wrapper for source info for functions.
1641class FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1642 FunctionTypeLoc,
1643 FunctionType,
1644 FunctionLocInfo> {
1645 bool hasExceptionSpec() const {
1646 if (auto *FPT = dyn_cast<FunctionProtoType>(Val: getTypePtr())) {
1647 return FPT->hasExceptionSpec();
1648 }
1649 return false;
1650 }
1651
1652 SourceRange *getExceptionSpecRangePtr() const {
1653 assert(hasExceptionSpec() && "No exception spec range");
1654 // After the Info comes the ParmVarDecl array, and after that comes the
1655 // exception specification information.
1656 return (SourceRange *)(getParmArray() + getNumParams());
1657 }
1658
1659public:
1660 SourceLocation getLocalRangeBegin() const {
1661 return getLocalData()->LocalRangeBegin;
1662 }
1663
1664 void setLocalRangeBegin(SourceLocation L) {
1665 getLocalData()->LocalRangeBegin = L;
1666 }
1667
1668 SourceLocation getLocalRangeEnd() const {
1669 return getLocalData()->LocalRangeEnd;
1670 }
1671
1672 void setLocalRangeEnd(SourceLocation L) {
1673 getLocalData()->LocalRangeEnd = L;
1674 }
1675
1676 SourceLocation getLParenLoc() const {
1677 return this->getLocalData()->LParenLoc;
1678 }
1679
1680 void setLParenLoc(SourceLocation Loc) {
1681 this->getLocalData()->LParenLoc = Loc;
1682 }
1683
1684 SourceLocation getRParenLoc() const {
1685 return this->getLocalData()->RParenLoc;
1686 }
1687
1688 void setRParenLoc(SourceLocation Loc) {
1689 this->getLocalData()->RParenLoc = Loc;
1690 }
1691
1692 SourceRange getParensRange() const {
1693 return SourceRange(getLParenLoc(), getRParenLoc());
1694 }
1695
1696 SourceRange getExceptionSpecRange() const {
1697 if (hasExceptionSpec())
1698 return *getExceptionSpecRangePtr();
1699 return {};
1700 }
1701
1702 void setExceptionSpecRange(SourceRange R) {
1703 if (hasExceptionSpec())
1704 *getExceptionSpecRangePtr() = R;
1705 }
1706
1707 ArrayRef<ParmVarDecl *> getParams() const {
1708 return {getParmArray(), getNumParams()};
1709 }
1710
1711 // ParmVarDecls* are stored after Info, one for each parameter.
1712 ParmVarDecl **getParmArray() const {
1713 return (ParmVarDecl**) getExtraLocalData();
1714 }
1715
1716 unsigned getNumParams() const {
1717 if (isa<FunctionNoProtoType>(Val: getTypePtr()))
1718 return 0;
1719 return cast<FunctionProtoType>(Val: getTypePtr())->getNumParams();
1720 }
1721
1722 ParmVarDecl *getParam(unsigned i) const { return getParmArray()[i]; }
1723 void setParam(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; }
1724
1725 TypeLoc getReturnLoc() const {
1726 return getInnerTypeLoc();
1727 }
1728
1729 SourceRange getLocalSourceRange() const {
1730 return SourceRange(getLocalRangeBegin(), getLocalRangeEnd());
1731 }
1732
1733 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1734 setLocalRangeBegin(Loc);
1735 setLParenLoc(Loc);
1736 setRParenLoc(Loc);
1737 setLocalRangeEnd(Loc);
1738 for (unsigned i = 0, e = getNumParams(); i != e; ++i)
1739 setParam(i, VD: nullptr);
1740 if (hasExceptionSpec())
1741 setExceptionSpecRange(Loc);
1742 }
1743
1744 /// Returns the size of the type source info data block that is
1745 /// specific to this type.
1746 unsigned getExtraLocalDataSize() const {
1747 unsigned ExceptSpecSize = hasExceptionSpec() ? sizeof(SourceRange) : 0;
1748 return (getNumParams() * sizeof(ParmVarDecl *)) + ExceptSpecSize;
1749 }
1750
1751 unsigned getExtraLocalDataAlignment() const { return alignof(ParmVarDecl *); }
1752
1753 QualType getInnerType() const { return getTypePtr()->getReturnType(); }
1754};
1755
1756class FunctionProtoTypeLoc :
1757 public InheritingConcreteTypeLoc<FunctionTypeLoc,
1758 FunctionProtoTypeLoc,
1759 FunctionProtoType> {
1760};
1761
1762class FunctionNoProtoTypeLoc :
1763 public InheritingConcreteTypeLoc<FunctionTypeLoc,
1764 FunctionNoProtoTypeLoc,
1765 FunctionNoProtoType> {
1766};
1767
1768struct ArrayLocInfo {
1769 SourceLocation LBracketLoc, RBracketLoc;
1770 Expr *Size;
1771};
1772
1773/// Wrapper for source info for arrays.
1774class ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1775 ArrayTypeLoc,
1776 ArrayType,
1777 ArrayLocInfo> {
1778public:
1779 SourceLocation getLBracketLoc() const {
1780 return getLocalData()->LBracketLoc;
1781 }
1782
1783 void setLBracketLoc(SourceLocation Loc) {
1784 getLocalData()->LBracketLoc = Loc;
1785 }
1786
1787 SourceLocation getRBracketLoc() const {
1788 return getLocalData()->RBracketLoc;
1789 }
1790
1791 void setRBracketLoc(SourceLocation Loc) {
1792 getLocalData()->RBracketLoc = Loc;
1793 }
1794
1795 SourceRange getBracketsRange() const {
1796 return SourceRange(getLBracketLoc(), getRBracketLoc());
1797 }
1798
1799 Expr *getSizeExpr() const {
1800 return getLocalData()->Size;
1801 }
1802
1803 void setSizeExpr(Expr *Size) {
1804 getLocalData()->Size = Size;
1805 }
1806
1807 TypeLoc getElementLoc() const {
1808 return getInnerTypeLoc();
1809 }
1810
1811 SourceRange getLocalSourceRange() const {
1812 return SourceRange(getLBracketLoc(), getRBracketLoc());
1813 }
1814
1815 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1816 setLBracketLoc(Loc);
1817 setRBracketLoc(Loc);
1818 setSizeExpr(nullptr);
1819 }
1820
1821 QualType getInnerType() const { return getTypePtr()->getElementType(); }
1822};
1823
1824class ConstantArrayTypeLoc :
1825 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1826 ConstantArrayTypeLoc,
1827 ConstantArrayType> {
1828};
1829
1830/// Wrapper for source info for array parameter types.
1831class ArrayParameterTypeLoc
1832 : public InheritingConcreteTypeLoc<
1833 ConstantArrayTypeLoc, ArrayParameterTypeLoc, ArrayParameterType> {};
1834
1835class IncompleteArrayTypeLoc :
1836 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1837 IncompleteArrayTypeLoc,
1838 IncompleteArrayType> {
1839};
1840
1841class DependentSizedArrayTypeLoc :
1842 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1843 DependentSizedArrayTypeLoc,
1844 DependentSizedArrayType> {
1845public:
1846 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1847 ArrayTypeLoc::initializeLocal(Context, Loc);
1848 setSizeExpr(getTypePtr()->getSizeExpr());
1849 }
1850};
1851
1852class VariableArrayTypeLoc :
1853 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1854 VariableArrayTypeLoc,
1855 VariableArrayType> {
1856};
1857
1858// Location information for a TemplateName. Rudimentary for now.
1859struct TemplateNameLocInfo {
1860 SourceLocation NameLoc;
1861};
1862
1863struct TemplateSpecializationLocInfo : TemplateNameLocInfo {
1864 SourceRange SR;
1865 SourceLocation ElaboratedKWLoc;
1866 SourceLocation TemplateKWLoc;
1867 SourceLocation LAngleLoc;
1868 void *QualifierData;
1869};
1870
1871class TemplateSpecializationTypeLoc :
1872 public ConcreteTypeLoc<UnqualTypeLoc,
1873 TemplateSpecializationTypeLoc,
1874 TemplateSpecializationType,
1875 TemplateSpecializationLocInfo> {
1876public:
1877 void set(SourceLocation ElaboratedKeywordLoc,
1878 NestedNameSpecifierLoc QualifierLoc,
1879 SourceLocation TemplateKeywordLoc, SourceLocation NameLoc,
1880 SourceLocation LAngleLoc, SourceLocation RAngleLoc);
1881
1882 void set(SourceLocation ElaboratedKeywordLoc,
1883 NestedNameSpecifierLoc QualifierLoc,
1884 SourceLocation TemplateKeywordLoc, SourceLocation NameLoc,
1885 const TemplateArgumentListInfo &TAL);
1886
1887 SourceLocation getElaboratedKeywordLoc() const {
1888 return getLocalData()->ElaboratedKWLoc;
1889 }
1890
1891 NestedNameSpecifierLoc getQualifierLoc() const {
1892 if (!getLocalData()->QualifierData)
1893 return NestedNameSpecifierLoc();
1894
1895 NestedNameSpecifier Qualifier =
1896 getTypePtr()->getTemplateName().getQualifier();
1897 assert(Qualifier && "missing qualification");
1898 return NestedNameSpecifierLoc(Qualifier, getLocalData()->QualifierData);
1899 }
1900
1901 SourceLocation getTemplateKeywordLoc() const {
1902 return getLocalData()->TemplateKWLoc;
1903 }
1904
1905 SourceLocation getTemplateNameLoc() const { return getLocalData()->NameLoc; }
1906
1907 SourceLocation getLAngleLoc() const { return getLocalData()->LAngleLoc; }
1908
1909 unsigned getNumArgs() const {
1910 return getTypePtr()->template_arguments().size();
1911 }
1912
1913 MutableArrayRef<TemplateArgumentLocInfo> getArgLocInfos() {
1914 return {getArgInfos(), getNumArgs()};
1915 }
1916
1917 TemplateArgumentLoc getArgLoc(unsigned i) const {
1918 return TemplateArgumentLoc(getTypePtr()->template_arguments()[i],
1919 getArgInfos()[i]);
1920 }
1921
1922 SourceLocation getRAngleLoc() const { return getLocalData()->SR.getEnd(); }
1923
1924 /// - Copy the location information from the given info.
1925 void copy(TemplateSpecializationTypeLoc Loc) {
1926 unsigned size = getFullDataSize();
1927 assert(size == Loc.getFullDataSize());
1928
1929 // We're potentially copying Expr references here. We don't
1930 // bother retaining them because TypeSourceInfos live forever, so
1931 // as long as the Expr was retained when originally written into
1932 // the TypeLoc, we're okay.
1933 memcpy(dest: Data, src: Loc.Data, n: size);
1934 }
1935
1936 SourceRange getLocalSourceRange() const { return getLocalData()->SR; }
1937
1938 void initializeLocal(ASTContext &Context, SourceLocation Loc);
1939
1940 static void initializeArgLocs(ASTContext &Context,
1941 ArrayRef<TemplateArgument> Args,
1942 TemplateArgumentLocInfo *ArgInfos,
1943 SourceLocation Loc);
1944
1945 unsigned getExtraLocalDataSize() const {
1946 return getNumArgs() * sizeof(TemplateArgumentLocInfo);
1947 }
1948
1949 unsigned getExtraLocalDataAlignment() const {
1950 return alignof(TemplateArgumentLocInfo);
1951 }
1952
1953private:
1954 TemplateArgumentLocInfo *getArgInfos() const {
1955 return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
1956 }
1957};
1958
1959struct DependentAddressSpaceLocInfo {
1960 Expr *ExprOperand;
1961 SourceRange OperandParens;
1962 SourceLocation AttrLoc;
1963};
1964
1965class DependentAddressSpaceTypeLoc
1966 : public ConcreteTypeLoc<UnqualTypeLoc,
1967 DependentAddressSpaceTypeLoc,
1968 DependentAddressSpaceType,
1969 DependentAddressSpaceLocInfo> {
1970public:
1971 /// The location of the attribute name, i.e.
1972 /// int * __attribute__((address_space(11)))
1973 /// ^~~~~~~~~~~~~
1974 SourceLocation getAttrNameLoc() const {
1975 return getLocalData()->AttrLoc;
1976 }
1977 void setAttrNameLoc(SourceLocation loc) {
1978 getLocalData()->AttrLoc = loc;
1979 }
1980
1981 /// The attribute's expression operand, if it has one.
1982 /// int * __attribute__((address_space(11)))
1983 /// ^~
1984 Expr *getAttrExprOperand() const {
1985 return getLocalData()->ExprOperand;
1986 }
1987 void setAttrExprOperand(Expr *e) {
1988 getLocalData()->ExprOperand = e;
1989 }
1990
1991 /// The location of the parentheses around the operand, if there is
1992 /// an operand.
1993 /// int * __attribute__((address_space(11)))
1994 /// ^ ^
1995 SourceRange getAttrOperandParensRange() const {
1996 return getLocalData()->OperandParens;
1997 }
1998 void setAttrOperandParensRange(SourceRange range) {
1999 getLocalData()->OperandParens = range;
2000 }
2001
2002 SourceRange getLocalSourceRange() const {
2003 SourceRange range(getAttrNameLoc());
2004 range.setEnd(getAttrOperandParensRange().getEnd());
2005 return range;
2006 }
2007
2008 /// Returns the type before the address space attribute application
2009 /// area.
2010 /// int * __attribute__((address_space(11))) *
2011 /// ^ ^
2012 QualType getInnerType() const {
2013 return this->getTypePtr()->getPointeeType();
2014 }
2015
2016 TypeLoc getPointeeTypeLoc() const {
2017 return this->getInnerTypeLoc();
2018 }
2019
2020 void initializeLocal(ASTContext &Context, SourceLocation loc) {
2021 setAttrNameLoc(loc);
2022 setAttrOperandParensRange(loc);
2023 setAttrOperandParensRange(SourceRange(loc));
2024 setAttrExprOperand(getTypePtr()->getAddrSpaceExpr());
2025 }
2026};
2027
2028//===----------------------------------------------------------------------===//
2029//
2030// All of these need proper implementations.
2031//
2032//===----------------------------------------------------------------------===//
2033
2034// FIXME: size expression and attribute locations (or keyword if we
2035// ever fully support altivec syntax).
2036struct VectorTypeLocInfo {
2037 SourceLocation NameLoc;
2038};
2039
2040class VectorTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, VectorTypeLoc,
2041 VectorType, VectorTypeLocInfo> {
2042public:
2043 SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; }
2044
2045 void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; }
2046
2047 SourceRange getLocalSourceRange() const {
2048 return SourceRange(getNameLoc(), getNameLoc());
2049 }
2050
2051 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2052 setNameLoc(Loc);
2053 }
2054
2055 TypeLoc getElementLoc() const { return getInnerTypeLoc(); }
2056
2057 QualType getInnerType() const { return this->getTypePtr()->getElementType(); }
2058};
2059
2060// FIXME: size expression and attribute locations (or keyword if we
2061// ever fully support altivec syntax).
2062class DependentVectorTypeLoc
2063 : public ConcreteTypeLoc<UnqualTypeLoc, DependentVectorTypeLoc,
2064 DependentVectorType, VectorTypeLocInfo> {
2065public:
2066 SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; }
2067
2068 void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; }
2069
2070 SourceRange getLocalSourceRange() const {
2071 return SourceRange(getNameLoc(), getNameLoc());
2072 }
2073
2074 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2075 setNameLoc(Loc);
2076 }
2077
2078 TypeLoc getElementLoc() const { return getInnerTypeLoc(); }
2079
2080 QualType getInnerType() const { return this->getTypePtr()->getElementType(); }
2081};
2082
2083// FIXME: size expression and attribute locations.
2084class ExtVectorTypeLoc
2085 : public InheritingConcreteTypeLoc<VectorTypeLoc, ExtVectorTypeLoc,
2086 ExtVectorType> {};
2087
2088// FIXME: attribute locations.
2089// For some reason, this isn't a subtype of VectorType.
2090class DependentSizedExtVectorTypeLoc
2091 : public ConcreteTypeLoc<UnqualTypeLoc, DependentSizedExtVectorTypeLoc,
2092 DependentSizedExtVectorType, VectorTypeLocInfo> {
2093public:
2094 SourceLocation getNameLoc() const { return this->getLocalData()->NameLoc; }
2095
2096 void setNameLoc(SourceLocation Loc) { this->getLocalData()->NameLoc = Loc; }
2097
2098 SourceRange getLocalSourceRange() const {
2099 return SourceRange(getNameLoc(), getNameLoc());
2100 }
2101
2102 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2103 setNameLoc(Loc);
2104 }
2105
2106 TypeLoc getElementLoc() const { return getInnerTypeLoc(); }
2107
2108 QualType getInnerType() const { return this->getTypePtr()->getElementType(); }
2109};
2110
2111struct MatrixTypeLocInfo {
2112 SourceLocation AttrLoc;
2113 SourceRange OperandParens;
2114 Expr *RowOperand;
2115 Expr *ColumnOperand;
2116};
2117
2118class MatrixTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, MatrixTypeLoc,
2119 MatrixType, MatrixTypeLocInfo> {
2120public:
2121 /// The location of the attribute name, i.e.
2122 /// float __attribute__((matrix_type(4, 2)))
2123 /// ^~~~~~~~~~~~~~~~~
2124 SourceLocation getAttrNameLoc() const { return getLocalData()->AttrLoc; }
2125 void setAttrNameLoc(SourceLocation loc) { getLocalData()->AttrLoc = loc; }
2126
2127 /// The attribute's row operand, if it has one.
2128 /// float __attribute__((matrix_type(4, 2)))
2129 /// ^
2130 Expr *getAttrRowOperand() const { return getLocalData()->RowOperand; }
2131 void setAttrRowOperand(Expr *e) { getLocalData()->RowOperand = e; }
2132
2133 /// The attribute's column operand, if it has one.
2134 /// float __attribute__((matrix_type(4, 2)))
2135 /// ^
2136 Expr *getAttrColumnOperand() const { return getLocalData()->ColumnOperand; }
2137 void setAttrColumnOperand(Expr *e) { getLocalData()->ColumnOperand = e; }
2138
2139 /// The location of the parentheses around the operand, if there is
2140 /// an operand.
2141 /// float __attribute__((matrix_type(4, 2)))
2142 /// ^ ^
2143 SourceRange getAttrOperandParensRange() const {
2144 return getLocalData()->OperandParens;
2145 }
2146 void setAttrOperandParensRange(SourceRange range) {
2147 getLocalData()->OperandParens = range;
2148 }
2149
2150 SourceRange getLocalSourceRange() const {
2151 SourceRange range(getAttrNameLoc());
2152 range.setEnd(getAttrOperandParensRange().getEnd());
2153 return range;
2154 }
2155
2156 void initializeLocal(ASTContext &Context, SourceLocation loc) {
2157 setAttrNameLoc(loc);
2158 setAttrOperandParensRange(loc);
2159 setAttrRowOperand(nullptr);
2160 setAttrColumnOperand(nullptr);
2161 }
2162};
2163
2164class ConstantMatrixTypeLoc
2165 : public InheritingConcreteTypeLoc<MatrixTypeLoc, ConstantMatrixTypeLoc,
2166 ConstantMatrixType> {};
2167
2168class DependentSizedMatrixTypeLoc
2169 : public InheritingConcreteTypeLoc<MatrixTypeLoc,
2170 DependentSizedMatrixTypeLoc,
2171 DependentSizedMatrixType> {};
2172
2173// FIXME: location of the '_Complex' keyword.
2174class ComplexTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
2175 ComplexTypeLoc,
2176 ComplexType> {
2177};
2178
2179struct TypeofLocInfo {
2180 SourceLocation TypeofLoc;
2181 SourceLocation LParenLoc;
2182 SourceLocation RParenLoc;
2183};
2184
2185struct TypeOfExprTypeLocInfo : public TypeofLocInfo {
2186};
2187
2188struct TypeOfTypeLocInfo : public TypeofLocInfo {
2189 TypeSourceInfo *UnmodifiedTInfo;
2190};
2191
2192template <class Derived, class TypeClass, class LocalData = TypeofLocInfo>
2193class TypeofLikeTypeLoc
2194 : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> {
2195public:
2196 SourceLocation getTypeofLoc() const {
2197 return this->getLocalData()->TypeofLoc;
2198 }
2199
2200 void setTypeofLoc(SourceLocation Loc) {
2201 this->getLocalData()->TypeofLoc = Loc;
2202 }
2203
2204 SourceLocation getLParenLoc() const {
2205 return this->getLocalData()->LParenLoc;
2206 }
2207
2208 void setLParenLoc(SourceLocation Loc) {
2209 this->getLocalData()->LParenLoc = Loc;
2210 }
2211
2212 SourceLocation getRParenLoc() const {
2213 return this->getLocalData()->RParenLoc;
2214 }
2215
2216 void setRParenLoc(SourceLocation Loc) {
2217 this->getLocalData()->RParenLoc = Loc;
2218 }
2219
2220 SourceRange getParensRange() const {
2221 return SourceRange(getLParenLoc(), getRParenLoc());
2222 }
2223
2224 void setParensRange(SourceRange range) {
2225 setLParenLoc(range.getBegin());
2226 setRParenLoc(range.getEnd());
2227 }
2228
2229 SourceRange getLocalSourceRange() const {
2230 return SourceRange(getTypeofLoc(), getRParenLoc());
2231 }
2232
2233 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2234 setTypeofLoc(Loc);
2235 setLParenLoc(Loc);
2236 setRParenLoc(Loc);
2237 }
2238};
2239
2240class TypeOfExprTypeLoc : public TypeofLikeTypeLoc<TypeOfExprTypeLoc,
2241 TypeOfExprType,
2242 TypeOfExprTypeLocInfo> {
2243public:
2244 Expr* getUnderlyingExpr() const {
2245 return getTypePtr()->getUnderlyingExpr();
2246 }
2247
2248 // Reimplemented to account for GNU/C++ extension
2249 // typeof unary-expression
2250 // where there are no parentheses.
2251 SourceRange getLocalSourceRange() const;
2252};
2253
2254class TypeOfTypeLoc
2255 : public TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo> {
2256public:
2257 QualType getUnmodifiedType() const {
2258 return this->getTypePtr()->getUnmodifiedType();
2259 }
2260
2261 TypeSourceInfo *getUnmodifiedTInfo() const {
2262 return this->getLocalData()->UnmodifiedTInfo;
2263 }
2264
2265 void setUnmodifiedTInfo(TypeSourceInfo *TI) const {
2266 this->getLocalData()->UnmodifiedTInfo = TI;
2267 }
2268
2269 void initializeLocal(ASTContext &Context, SourceLocation Loc);
2270};
2271
2272// decltype(expression) abc;
2273// ~~~~~~~~ DecltypeLoc
2274// ~ RParenLoc
2275// FIXME: add LParenLoc, it is tricky to support due to the limitation of
2276// annotated-decltype token.
2277struct DecltypeTypeLocInfo {
2278 SourceLocation DecltypeLoc;
2279 SourceLocation RParenLoc;
2280};
2281class DecltypeTypeLoc
2282 : public ConcreteTypeLoc<UnqualTypeLoc, DecltypeTypeLoc, DecltypeType,
2283 DecltypeTypeLocInfo> {
2284public:
2285 Expr *getUnderlyingExpr() const { return getTypePtr()->getUnderlyingExpr(); }
2286
2287 SourceLocation getDecltypeLoc() const { return getLocalData()->DecltypeLoc; }
2288 void setDecltypeLoc(SourceLocation Loc) { getLocalData()->DecltypeLoc = Loc; }
2289
2290 SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
2291 void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
2292
2293 SourceRange getLocalSourceRange() const {
2294 return SourceRange(getDecltypeLoc(), getRParenLoc());
2295 }
2296
2297 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2298 setDecltypeLoc(Loc);
2299 setRParenLoc(Loc);
2300 }
2301};
2302
2303struct PackIndexingTypeLocInfo {
2304 SourceLocation EllipsisLoc;
2305};
2306
2307class PackIndexingTypeLoc
2308 : public ConcreteTypeLoc<UnqualTypeLoc, PackIndexingTypeLoc,
2309 PackIndexingType, PackIndexingTypeLocInfo> {
2310
2311public:
2312 Expr *getIndexExpr() const { return getTypePtr()->getIndexExpr(); }
2313 QualType getPattern() const { return getTypePtr()->getPattern(); }
2314
2315 SourceLocation getEllipsisLoc() const { return getLocalData()->EllipsisLoc; }
2316 void setEllipsisLoc(SourceLocation Loc) { getLocalData()->EllipsisLoc = Loc; }
2317
2318 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2319 setEllipsisLoc(Loc);
2320 }
2321
2322 TypeLoc getPatternLoc() const { return getInnerTypeLoc(); }
2323
2324 QualType getInnerType() const { return this->getTypePtr()->getPattern(); }
2325
2326 SourceRange getLocalSourceRange() const {
2327 return SourceRange(getEllipsisLoc(), getEllipsisLoc());
2328 }
2329};
2330
2331struct UnaryTransformTypeLocInfo {
2332 // FIXME: While there's only one unary transform right now, future ones may
2333 // need different representations
2334 SourceLocation KWLoc, LParenLoc, RParenLoc;
2335 TypeSourceInfo *UnderlyingTInfo;
2336};
2337
2338class UnaryTransformTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
2339 UnaryTransformTypeLoc,
2340 UnaryTransformType,
2341 UnaryTransformTypeLocInfo> {
2342public:
2343 SourceLocation getKWLoc() const { return getLocalData()->KWLoc; }
2344 void setKWLoc(SourceLocation Loc) { getLocalData()->KWLoc = Loc; }
2345
2346 SourceLocation getLParenLoc() const { return getLocalData()->LParenLoc; }
2347 void setLParenLoc(SourceLocation Loc) { getLocalData()->LParenLoc = Loc; }
2348
2349 SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
2350 void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
2351
2352 TypeSourceInfo* getUnderlyingTInfo() const {
2353 return getLocalData()->UnderlyingTInfo;
2354 }
2355
2356 void setUnderlyingTInfo(TypeSourceInfo *TInfo) {
2357 getLocalData()->UnderlyingTInfo = TInfo;
2358 }
2359
2360 SourceRange getLocalSourceRange() const {
2361 return SourceRange(getKWLoc(), getRParenLoc());
2362 }
2363
2364 SourceRange getParensRange() const {
2365 return SourceRange(getLParenLoc(), getRParenLoc());
2366 }
2367
2368 void setParensRange(SourceRange Range) {
2369 setLParenLoc(Range.getBegin());
2370 setRParenLoc(Range.getEnd());
2371 }
2372
2373 void initializeLocal(ASTContext &Context, SourceLocation Loc);
2374};
2375
2376class DeducedTypeLoc
2377 : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, DeducedTypeLoc,
2378 DeducedType> {};
2379
2380struct AutoTypeLocInfo : TypeSpecLocInfo {
2381 // For decltype(auto).
2382 SourceLocation RParenLoc;
2383
2384 ConceptReference *CR = nullptr;
2385};
2386
2387class AutoTypeLoc
2388 : public ConcreteTypeLoc<DeducedTypeLoc,
2389 AutoTypeLoc,
2390 AutoType,
2391 AutoTypeLocInfo> {
2392public:
2393 AutoTypeKeyword getAutoKeyword() const {
2394 return getTypePtr()->getKeyword();
2395 }
2396
2397 bool isDecltypeAuto() const { return getTypePtr()->isDecltypeAuto(); }
2398 SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
2399 void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
2400
2401 bool isConstrained() const {
2402 return getTypePtr()->isConstrained();
2403 }
2404
2405 void setConceptReference(ConceptReference *CR) { getLocalData()->CR = CR; }
2406
2407 ConceptReference *getConceptReference() const { return getLocalData()->CR; }
2408
2409 // FIXME: Several of the following functions can be removed. Instead the
2410 // caller can directly work with the ConceptReference.
2411 const NestedNameSpecifierLoc getNestedNameSpecifierLoc() const {
2412 if (const auto *CR = getConceptReference())
2413 return CR->getNestedNameSpecifierLoc();
2414 return NestedNameSpecifierLoc();
2415 }
2416
2417 SourceLocation getTemplateKWLoc() const {
2418 if (const auto *CR = getConceptReference())
2419 return CR->getTemplateKWLoc();
2420 return SourceLocation();
2421 }
2422
2423 SourceLocation getConceptNameLoc() const {
2424 if (const auto *CR = getConceptReference())
2425 return CR->getConceptNameLoc();
2426 return SourceLocation();
2427 }
2428
2429 NamedDecl *getFoundDecl() const {
2430 if (const auto *CR = getConceptReference())
2431 return CR->getFoundDecl();
2432 return nullptr;
2433 }
2434
2435 TemplateDecl *getNamedConcept() const {
2436 if (const auto *CR = getConceptReference())
2437 return CR->getNamedConcept();
2438 return nullptr;
2439 }
2440
2441 DeclarationNameInfo getConceptNameInfo() const {
2442 return getConceptReference()->getConceptNameInfo();
2443 }
2444
2445 bool hasExplicitTemplateArgs() const {
2446 return (getConceptReference() &&
2447 getConceptReference()->getTemplateArgsAsWritten() &&
2448 getConceptReference()
2449 ->getTemplateArgsAsWritten()
2450 ->getLAngleLoc()
2451 .isValid());
2452 }
2453
2454 SourceLocation getLAngleLoc() const {
2455 if (const auto *CR = getConceptReference())
2456 if (const auto *TAAW = CR->getTemplateArgsAsWritten())
2457 return TAAW->getLAngleLoc();
2458 return SourceLocation();
2459 }
2460
2461 SourceLocation getRAngleLoc() const {
2462 if (const auto *CR = getConceptReference())
2463 if (const auto *TAAW = CR->getTemplateArgsAsWritten())
2464 return TAAW->getRAngleLoc();
2465 return SourceLocation();
2466 }
2467
2468 unsigned getNumArgs() const {
2469 return getTypePtr()->getTypeConstraintArguments().size();
2470 }
2471
2472 TemplateArgumentLoc getArgLoc(unsigned i) const {
2473 const auto *CR = getConceptReference();
2474 assert(CR && "No ConceptReference");
2475 return CR->getTemplateArgsAsWritten()->getTemplateArgs()[i];
2476 }
2477
2478 SourceRange getLocalSourceRange() const {
2479 return {isConstrained()
2480 ? (getNestedNameSpecifierLoc()
2481 ? getNestedNameSpecifierLoc().getBeginLoc()
2482 : (getTemplateKWLoc().isValid() ? getTemplateKWLoc()
2483 : getConceptNameLoc()))
2484 : getNameLoc(),
2485 isDecltypeAuto() ? getRParenLoc() : getNameLoc()};
2486 }
2487
2488 void copy(AutoTypeLoc Loc) {
2489 unsigned size = getFullDataSize();
2490 assert(size == Loc.getFullDataSize());
2491 memcpy(dest: Data, src: Loc.Data, n: size);
2492 }
2493
2494 void initializeLocal(ASTContext &Context, SourceLocation Loc);
2495};
2496
2497struct DeducedTemplateSpecializationLocInfo : TypeSpecLocInfo {
2498 SourceLocation ElaboratedKWLoc;
2499 /// Data associated with the nested-name-specifier location.
2500 void *QualifierData;
2501};
2502
2503class DeducedTemplateSpecializationTypeLoc
2504 : public ConcreteTypeLoc<DeducedTypeLoc,
2505 DeducedTemplateSpecializationTypeLoc,
2506 DeducedTemplateSpecializationType,
2507 DeducedTemplateSpecializationLocInfo> {
2508public:
2509 SourceLocation getElaboratedKeywordLoc() const {
2510 return getLocalData()->ElaboratedKWLoc;
2511 }
2512
2513 void setElaboratedKeywordLoc(SourceLocation Loc) {
2514 getLocalData()->ElaboratedKWLoc = Loc;
2515 }
2516
2517 SourceLocation getTemplateNameLoc() const { return getNameLoc(); }
2518
2519 void setTemplateNameLoc(SourceLocation Loc) { setNameLoc(Loc); }
2520
2521 NestedNameSpecifierLoc getQualifierLoc() const {
2522 void *Data = getLocalData()->QualifierData;
2523 if (!Data)
2524 return NestedNameSpecifierLoc();
2525 NestedNameSpecifier Qualifier =
2526 getTypePtr()->getTemplateName().getQualifier();
2527 assert(Qualifier && "missing qualification");
2528 return NestedNameSpecifierLoc(Qualifier, Data);
2529 }
2530
2531 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
2532 if (!QualifierLoc) {
2533 // Even if we have a nested-name-specifier in the dependent
2534 // template specialization type, we won't record the nested-name-specifier
2535 // location information when this type-source location information is
2536 // part of a nested-name-specifier.
2537 getLocalData()->QualifierData = nullptr;
2538 return;
2539 }
2540
2541 assert(QualifierLoc.getNestedNameSpecifier() ==
2542 getTypePtr()->getTemplateName().getQualifier() &&
2543 "Inconsistent nested-name-specifier pointer");
2544 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
2545 }
2546
2547 SourceRange getLocalSourceRange() const {
2548 SourceLocation BeginLoc = getElaboratedKeywordLoc();
2549 if (BeginLoc.isInvalid())
2550 BeginLoc = getQualifierLoc().getBeginLoc();
2551 if (BeginLoc.isInvalid())
2552 BeginLoc = getNameLoc();
2553 return {BeginLoc, getNameLoc()};
2554 }
2555
2556 void initializeLocal(ASTContext &Context, SourceLocation Loc);
2557};
2558
2559struct ElaboratedLocInfo {
2560 SourceLocation ElaboratedKWLoc;
2561
2562 /// Data associated with the nested-name-specifier location.
2563 void *QualifierData;
2564};
2565
2566// This is exactly the structure of an ElaboratedTypeLoc whose inner
2567// type is some sort of TypeDeclTypeLoc.
2568struct DependentNameLocInfo : ElaboratedLocInfo {
2569 SourceLocation NameLoc;
2570};
2571
2572class DependentNameTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
2573 DependentNameTypeLoc,
2574 DependentNameType,
2575 DependentNameLocInfo> {
2576public:
2577 SourceLocation getElaboratedKeywordLoc() const {
2578 return this->getLocalData()->ElaboratedKWLoc;
2579 }
2580
2581 void setElaboratedKeywordLoc(SourceLocation Loc) {
2582 this->getLocalData()->ElaboratedKWLoc = Loc;
2583 }
2584
2585 NestedNameSpecifierLoc getQualifierLoc() const {
2586 return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
2587 getLocalData()->QualifierData);
2588 }
2589
2590 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
2591 assert(QualifierLoc.getNestedNameSpecifier()
2592 == getTypePtr()->getQualifier() &&
2593 "Inconsistent nested-name-specifier pointer");
2594 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
2595 }
2596
2597 SourceLocation getNameLoc() const {
2598 return this->getLocalData()->NameLoc;
2599 }
2600
2601 void setNameLoc(SourceLocation Loc) {
2602 this->getLocalData()->NameLoc = Loc;
2603 }
2604
2605 SourceRange getLocalSourceRange() const {
2606 if (getElaboratedKeywordLoc().isValid())
2607 return SourceRange(getElaboratedKeywordLoc(), getNameLoc());
2608 else
2609 return SourceRange(getQualifierLoc().getBeginLoc(), getNameLoc());
2610 }
2611
2612 void copy(DependentNameTypeLoc Loc) {
2613 unsigned size = getFullDataSize();
2614 assert(size == Loc.getFullDataSize());
2615 memcpy(dest: Data, src: Loc.Data, n: size);
2616 }
2617
2618 void initializeLocal(ASTContext &Context, SourceLocation Loc);
2619};
2620
2621struct PackExpansionTypeLocInfo {
2622 SourceLocation EllipsisLoc;
2623};
2624
2625class PackExpansionTypeLoc
2626 : public ConcreteTypeLoc<UnqualTypeLoc, PackExpansionTypeLoc,
2627 PackExpansionType, PackExpansionTypeLocInfo> {
2628public:
2629 SourceLocation getEllipsisLoc() const {
2630 return this->getLocalData()->EllipsisLoc;
2631 }
2632
2633 void setEllipsisLoc(SourceLocation Loc) {
2634 this->getLocalData()->EllipsisLoc = Loc;
2635 }
2636
2637 SourceRange getLocalSourceRange() const {
2638 return SourceRange(getEllipsisLoc(), getEllipsisLoc());
2639 }
2640
2641 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2642 setEllipsisLoc(Loc);
2643 }
2644
2645 TypeLoc getPatternLoc() const {
2646 return getInnerTypeLoc();
2647 }
2648
2649 QualType getInnerType() const {
2650 return this->getTypePtr()->getPattern();
2651 }
2652};
2653
2654struct AtomicTypeLocInfo {
2655 SourceLocation KWLoc, LParenLoc, RParenLoc;
2656};
2657
2658class AtomicTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, AtomicTypeLoc,
2659 AtomicType, AtomicTypeLocInfo> {
2660public:
2661 TypeLoc getValueLoc() const {
2662 return this->getInnerTypeLoc();
2663 }
2664
2665 SourceRange getLocalSourceRange() const {
2666 return SourceRange(getKWLoc(), getRParenLoc());
2667 }
2668
2669 SourceLocation getKWLoc() const {
2670 return this->getLocalData()->KWLoc;
2671 }
2672
2673 void setKWLoc(SourceLocation Loc) {
2674 this->getLocalData()->KWLoc = Loc;
2675 }
2676
2677 SourceLocation getLParenLoc() const {
2678 return this->getLocalData()->LParenLoc;
2679 }
2680
2681 void setLParenLoc(SourceLocation Loc) {
2682 this->getLocalData()->LParenLoc = Loc;
2683 }
2684
2685 SourceLocation getRParenLoc() const {
2686 return this->getLocalData()->RParenLoc;
2687 }
2688
2689 void setRParenLoc(SourceLocation Loc) {
2690 this->getLocalData()->RParenLoc = Loc;
2691 }
2692
2693 SourceRange getParensRange() const {
2694 return SourceRange(getLParenLoc(), getRParenLoc());
2695 }
2696
2697 void setParensRange(SourceRange Range) {
2698 setLParenLoc(Range.getBegin());
2699 setRParenLoc(Range.getEnd());
2700 }
2701
2702 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2703 setKWLoc(Loc);
2704 setLParenLoc(Loc);
2705 setRParenLoc(Loc);
2706 }
2707
2708 QualType getInnerType() const {
2709 return this->getTypePtr()->getValueType();
2710 }
2711};
2712
2713struct PipeTypeLocInfo {
2714 SourceLocation KWLoc;
2715};
2716
2717class PipeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, PipeTypeLoc, PipeType,
2718 PipeTypeLocInfo> {
2719public:
2720 TypeLoc getValueLoc() const { return this->getInnerTypeLoc(); }
2721
2722 SourceRange getLocalSourceRange() const { return SourceRange(getKWLoc()); }
2723
2724 SourceLocation getKWLoc() const { return this->getLocalData()->KWLoc; }
2725 void setKWLoc(SourceLocation Loc) { this->getLocalData()->KWLoc = Loc; }
2726
2727 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2728 setKWLoc(Loc);
2729 }
2730
2731 QualType getInnerType() const { return this->getTypePtr()->getElementType(); }
2732};
2733
2734template <typename T>
2735inline T TypeLoc::getAsAdjusted() const {
2736 TypeLoc Cur = *this;
2737 while (!T::isKind(Cur)) {
2738 if (auto PTL = Cur.getAs<ParenTypeLoc>())
2739 Cur = PTL.getInnerLoc();
2740 else if (auto ATL = Cur.getAs<AttributedTypeLoc>())
2741 Cur = ATL.getModifiedLoc();
2742 else if (auto ATL = Cur.getAs<BTFTagAttributedTypeLoc>())
2743 Cur = ATL.getWrappedLoc();
2744 else if (auto ATL = Cur.getAs<HLSLAttributedResourceTypeLoc>())
2745 Cur = ATL.getWrappedLoc();
2746 else if (auto ATL = Cur.getAs<AdjustedTypeLoc>())
2747 Cur = ATL.getOriginalLoc();
2748 else if (auto MQL = Cur.getAs<MacroQualifiedTypeLoc>())
2749 Cur = MQL.getInnerLoc();
2750 else
2751 break;
2752 }
2753 return Cur.getAs<T>();
2754}
2755class BitIntTypeLoc final
2756 : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, BitIntTypeLoc,
2757 BitIntType> {};
2758class DependentBitIntTypeLoc final
2759 : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, DependentBitIntTypeLoc,
2760 DependentBitIntType> {};
2761
2762class ObjCProtocolLoc {
2763 ObjCProtocolDecl *Protocol = nullptr;
2764 SourceLocation Loc = SourceLocation();
2765
2766public:
2767 ObjCProtocolLoc(ObjCProtocolDecl *protocol, SourceLocation loc)
2768 : Protocol(protocol), Loc(loc) {}
2769 ObjCProtocolDecl *getProtocol() const { return Protocol; }
2770 SourceLocation getLocation() const { return Loc; }
2771
2772 /// The source range is just the protocol name.
2773 SourceRange getSourceRange() const LLVM_READONLY {
2774 return SourceRange(Loc, Loc);
2775 }
2776};
2777
2778struct PredefinedSugarTypeLocInfo {}; // Nothing.
2779
2780class PredefinedSugarTypeLoc final
2781 : public ConcreteTypeLoc<UnqualTypeLoc, PredefinedSugarTypeLoc,
2782 PredefinedSugarType, PredefinedSugarTypeLocInfo> {
2783public:
2784 void initializeLocal(ASTContext &Context, SourceLocation loc) {}
2785 SourceRange getLocalSourceRange() const { return {}; }
2786};
2787
2788} // namespace clang
2789
2790#endif // LLVM_CLANG_AST_TYPELOC_H
2791