1 //===--- TypeLoc.h - Type Source Info Wrapper -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the TypeLoc interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_TYPELOC_H
15 #define LLVM_CLANG_AST_TYPELOC_H
17 #include "clang/AST/Type.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/TemplateBase.h"
20 #include "clang/Basic/Specifiers.h"
28 // Predeclare all the type nodes.
29 #define ABSTRACT_TYPELOC(Class, Base)
30 #define TYPELOC(Class, Base) \
32 #include "clang/AST/TypeLocNodes.def"
34 /// \brief Base wrapper for a particular "section" of type source info.
36 /// A client should use the TypeLoc subclasses through cast/dyn_cast in order to
37 /// get at the actual information.
40 // The correctness of this relies on the property that, for Type *Ty,
41 // QualType(Ty, 0).getAsOpaquePtr() == (void*) Ty
46 /// The kinds of TypeLocs. Equivalent to the Type::TypeClass enum,
47 /// except it also defines a Qualified enum that corresponds to the
48 /// QualifiedLoc class.
50 #define ABSTRACT_TYPE(Class, Base)
51 #define TYPE(Class, Base) \
53 #include "clang/AST/TypeNodes.def"
57 TypeLoc() : Ty(0), Data(0) { }
58 TypeLoc(QualType ty, void *opaqueData)
59 : Ty(ty.getAsOpaquePtr()), Data(opaqueData) { }
60 TypeLoc(const Type *ty, void *opaqueData)
61 : Ty(ty), Data(opaqueData) { }
63 TypeLocClass getTypeLocClass() const {
64 if (getType().hasLocalQualifiers()) return Qualified;
65 return (TypeLocClass) getType()->getTypeClass();
68 bool isNull() const { return !Ty; }
69 operator bool() const { return Ty; }
71 /// \brief Returns the size of type source info data block for the given type.
72 static unsigned getFullDataSizeForType(QualType Ty);
74 /// \brief Get the type for which this source info wrapper provides
76 QualType getType() const {
77 return QualType::getFromOpaquePtr(Ty);
80 const Type *getTypePtr() const {
81 return QualType::getFromOpaquePtr(Ty).getTypePtr();
84 /// \brief Get the pointer where source information is stored.
85 void *getOpaqueData() const {
89 /// \brief Get the begin source location.
90 SourceLocation getBeginLoc() const;
92 /// \brief Get the end source location.
93 SourceLocation getEndLoc() const;
95 /// \brief Get the full source range.
96 SourceRange getSourceRange() const {
97 return SourceRange(getBeginLoc(), getEndLoc());
100 /// \brief Get the local source range.
101 SourceRange getLocalSourceRange() const {
102 return getLocalSourceRangeImpl(*this);
105 /// \brief Returns the size of the type source info data block.
106 unsigned getFullDataSize() const {
107 return getFullDataSizeForType(getType());
110 /// \brief Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the
111 /// TypeLoc is a PointerLoc and next TypeLoc is for "int".
112 TypeLoc getNextTypeLoc() const {
113 return getNextTypeLocImpl(*this);
116 /// \brief Skips past any qualifiers, if this is qualified.
117 UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header
119 TypeLoc IgnoreParens() const {
120 if (isa<ParenTypeLoc>(this))
121 return IgnoreParensImpl(*this);
125 /// \brief Initializes this to state that every location in this
126 /// type is the given location.
128 /// This method exists to provide a simple transition for code that
129 /// relies on location-less types.
130 void initialize(ASTContext &Context, SourceLocation Loc) const {
131 initializeImpl(Context, *this, Loc);
134 /// \brief Initializes this by copying its information from another
135 /// TypeLoc of the same type.
136 void initializeFullCopy(TypeLoc Other) const {
137 assert(getType() == Other.getType());
138 size_t Size = getFullDataSize();
139 memcpy(getOpaqueData(), Other.getOpaqueData(), Size);
142 /// \brief Initializes this by copying its information from another
143 /// TypeLoc of the same type. The given size must be the full data
145 void initializeFullCopy(TypeLoc Other, unsigned Size) const {
146 assert(getType() == Other.getType());
147 assert(getFullDataSize() == Size);
148 memcpy(getOpaqueData(), Other.getOpaqueData(), Size);
151 friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) {
152 return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data;
155 friend bool operator!=(const TypeLoc &LHS, const TypeLoc &RHS) {
156 return !(LHS == RHS);
159 static bool classof(const TypeLoc *TL) { return true; }
162 static void initializeImpl(ASTContext &Context, TypeLoc TL, SourceLocation Loc);
163 static TypeLoc getNextTypeLocImpl(TypeLoc TL);
164 static TypeLoc IgnoreParensImpl(TypeLoc TL);
165 static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
168 /// \brief Return the TypeLoc for a type source info.
169 inline TypeLoc TypeSourceInfo::getTypeLoc() const {
170 return TypeLoc(Ty, const_cast<void*>(static_cast<const void*>(this + 1)));
173 /// \brief Wrapper of type source information for a type with
174 /// no direct qualifiers.
175 class UnqualTypeLoc : public TypeLoc {
178 UnqualTypeLoc(const Type *Ty, void *Data) : TypeLoc(Ty, Data) {}
180 const Type *getTypePtr() const {
181 return reinterpret_cast<const Type*>(Ty);
184 TypeLocClass getTypeLocClass() const {
185 return (TypeLocClass) getTypePtr()->getTypeClass();
188 static bool classof(const TypeLoc *TL) {
189 return !TL->getType().hasLocalQualifiers();
191 static bool classof(const UnqualTypeLoc *TL) { return true; }
194 /// \brief Wrapper of type source information for a type with
195 /// non-trivial direct qualifiers.
197 /// Currently, we intentionally do not provide source location for
199 class QualifiedTypeLoc : public TypeLoc {
201 SourceRange getLocalSourceRange() const {
202 return SourceRange();
205 UnqualTypeLoc getUnqualifiedLoc() const {
206 return UnqualTypeLoc(getTypePtr(), Data);
209 /// Initializes the local data of this type source info block to
210 /// provide no information.
211 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
215 TypeLoc getNextTypeLoc() const {
216 return getUnqualifiedLoc();
219 /// \brief Returns the size of the type source info data block that is
220 /// specific to this type.
221 unsigned getLocalDataSize() const {
222 // In fact, we don't currently preserve any location information
227 /// \brief Returns the size of the type source info data block.
228 unsigned getFullDataSize() const {
229 return getLocalDataSize() +
230 getFullDataSizeForType(getType().getLocalUnqualifiedType());
233 static bool classof(const TypeLoc *TL) {
234 return TL->getType().hasLocalQualifiers();
236 static bool classof(const QualifiedTypeLoc *TL) { return true; }
239 inline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {
240 if (isa<QualifiedTypeLoc>(this))
241 return cast<QualifiedTypeLoc>(this)->getUnqualifiedLoc();
242 return cast<UnqualTypeLoc>(*this);
245 /// A metaprogramming base class for TypeLoc classes which correspond
246 /// to a particular Type subclass. It is accepted for a single
247 /// TypeLoc class to correspond to multiple Type classes.
249 /// \param Base a class from which to derive
250 /// \param Derived the class deriving from this one
251 /// \param TypeClass the concrete Type subclass associated with this
253 /// \param LocalData the structure type of local location data for
256 /// sizeof(LocalData) needs to be a multiple of sizeof(void*) or
257 /// else the world will end.
259 /// TypeLocs with non-constant amounts of local data should override
260 /// getExtraLocalDataSize(); getExtraLocalData() will then point to
261 /// this extra memory.
263 /// TypeLocs with an inner type should define
264 /// QualType getInnerType() const
265 /// and getInnerTypeLoc() will then point to this inner type's
268 /// A word about hierarchies: this template is not designed to be
269 /// derived from multiple times in a hierarchy. It is also not
270 /// designed to be used for classes where subtypes might provide
271 /// different amounts of source information. It should be subclassed
272 /// only at the deepest portion of the hierarchy where all children
273 /// have identical source information; if that's an abstract type,
274 /// then further descendents should inherit from
275 /// InheritingConcreteTypeLoc instead.
276 template <class Base, class Derived, class TypeClass, class LocalData>
277 class ConcreteTypeLoc : public Base {
279 const Derived *asDerived() const {
280 return static_cast<const Derived*>(this);
284 unsigned getLocalDataSize() const {
285 return sizeof(LocalData) + asDerived()->getExtraLocalDataSize();
287 // Give a default implementation that's useful for leaf types.
288 unsigned getFullDataSize() const {
289 return asDerived()->getLocalDataSize() + getInnerTypeSize();
292 static bool classofType(const Type *Ty) {
293 return TypeClass::classof(Ty);
296 static bool classof(const TypeLoc *TL) {
297 return Derived::classofType(TL->getTypePtr());
299 static bool classof(const UnqualTypeLoc *TL) {
300 return Derived::classofType(TL->getTypePtr());
302 static bool classof(const Derived *TL) {
306 TypeLoc getNextTypeLoc() const {
307 return getNextTypeLoc(asDerived()->getInnerType());
310 const TypeClass *getTypePtr() const {
311 return cast<TypeClass>(Base::getTypePtr());
315 unsigned getExtraLocalDataSize() const {
319 LocalData *getLocalData() const {
320 return static_cast<LocalData*>(Base::Data);
323 /// Gets a pointer past the Info structure; useful for classes with
324 /// local data that can't be captured in the Info (e.g. because it's
325 /// of variable size).
326 void *getExtraLocalData() const {
327 return getLocalData() + 1;
330 void *getNonLocalData() const {
331 return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize();
334 struct HasNoInnerType {};
335 HasNoInnerType getInnerType() const { return HasNoInnerType(); }
337 TypeLoc getInnerTypeLoc() const {
338 return TypeLoc(asDerived()->getInnerType(), getNonLocalData());
342 unsigned getInnerTypeSize() const {
343 return getInnerTypeSize(asDerived()->getInnerType());
346 unsigned getInnerTypeSize(HasNoInnerType _) const {
350 unsigned getInnerTypeSize(QualType _) const {
351 return getInnerTypeLoc().getFullDataSize();
354 TypeLoc getNextTypeLoc(HasNoInnerType _) const {
358 TypeLoc getNextTypeLoc(QualType T) const {
359 return TypeLoc(T, getNonLocalData());
363 /// A metaprogramming class designed for concrete subtypes of abstract
364 /// types where all subtypes share equivalently-structured source
365 /// information. See the note on ConcreteTypeLoc.
366 template <class Base, class Derived, class TypeClass>
367 class InheritingConcreteTypeLoc : public Base {
369 static bool classofType(const Type *Ty) {
370 return TypeClass::classof(Ty);
373 static bool classof(const TypeLoc *TL) {
374 return Derived::classofType(TL->getTypePtr());
376 static bool classof(const UnqualTypeLoc *TL) {
377 return Derived::classofType(TL->getTypePtr());
379 static bool classof(const Derived *TL) {
383 const TypeClass *getTypePtr() const {
384 return cast<TypeClass>(Base::getTypePtr());
389 struct TypeSpecLocInfo {
390 SourceLocation NameLoc;
393 /// \brief A reasonable base class for TypeLocs that correspond to
394 /// types that are written as a type-specifier.
395 class TypeSpecTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
400 enum { LocalDataSize = sizeof(TypeSpecLocInfo) };
402 SourceLocation getNameLoc() const {
403 return this->getLocalData()->NameLoc;
405 void setNameLoc(SourceLocation Loc) {
406 this->getLocalData()->NameLoc = Loc;
408 SourceRange getLocalSourceRange() const {
409 return SourceRange(getNameLoc(), getNameLoc());
411 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
415 static bool classof(const TypeLoc *TL);
416 static bool classof(const TypeSpecTypeLoc *TL) { return true; }
420 struct BuiltinLocInfo {
421 SourceLocation BuiltinLoc;
424 /// \brief Wrapper for source info for builtin types.
425 class BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
430 enum { LocalDataSize = sizeof(BuiltinLocInfo) };
432 SourceLocation getBuiltinLoc() const {
433 return getLocalData()->BuiltinLoc;
435 void setBuiltinLoc(SourceLocation Loc) {
436 getLocalData()->BuiltinLoc = Loc;
439 SourceLocation getNameLoc() const { return getBuiltinLoc(); }
441 WrittenBuiltinSpecs& getWrittenBuiltinSpecs() {
442 return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
444 const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
445 return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
448 bool needsExtraLocalData() const {
449 BuiltinType::Kind bk = getTypePtr()->getKind();
450 return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128)
451 || (bk >= BuiltinType::Short && bk <= BuiltinType::LongDouble)
452 || bk == BuiltinType::UChar
453 || bk == BuiltinType::SChar;
456 unsigned getExtraLocalDataSize() const {
457 return needsExtraLocalData() ? sizeof(WrittenBuiltinSpecs) : 0;
460 SourceRange getLocalSourceRange() const {
461 return SourceRange(getBuiltinLoc(), getBuiltinLoc());
464 TypeSpecifierSign getWrittenSignSpec() const {
465 if (needsExtraLocalData())
466 return static_cast<TypeSpecifierSign>(getWrittenBuiltinSpecs().Sign);
468 return TSS_unspecified;
470 bool hasWrittenSignSpec() const {
471 return getWrittenSignSpec() != TSS_unspecified;
473 void setWrittenSignSpec(TypeSpecifierSign written) {
474 if (needsExtraLocalData())
475 getWrittenBuiltinSpecs().Sign = written;
478 TypeSpecifierWidth getWrittenWidthSpec() const {
479 if (needsExtraLocalData())
480 return static_cast<TypeSpecifierWidth>(getWrittenBuiltinSpecs().Width);
482 return TSW_unspecified;
484 bool hasWrittenWidthSpec() const {
485 return getWrittenWidthSpec() != TSW_unspecified;
487 void setWrittenWidthSpec(TypeSpecifierWidth written) {
488 if (needsExtraLocalData())
489 getWrittenBuiltinSpecs().Width = written;
492 TypeSpecifierType getWrittenTypeSpec() const;
493 bool hasWrittenTypeSpec() const {
494 return getWrittenTypeSpec() != TST_unspecified;
496 void setWrittenTypeSpec(TypeSpecifierType written) {
497 if (needsExtraLocalData())
498 getWrittenBuiltinSpecs().Type = written;
501 bool hasModeAttr() const {
502 if (needsExtraLocalData())
503 return getWrittenBuiltinSpecs().ModeAttr;
507 void setModeAttr(bool written) {
508 if (needsExtraLocalData())
509 getWrittenBuiltinSpecs().ModeAttr = written;
512 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
514 if (needsExtraLocalData()) {
515 WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs();
516 wbs.Sign = TSS_unspecified;
517 wbs.Width = TSW_unspecified;
518 wbs.Type = TST_unspecified;
519 wbs.ModeAttr = false;
525 /// \brief Wrapper for source info for typedefs.
526 class TypedefTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
530 TypedefNameDecl *getTypedefNameDecl() const {
531 return getTypePtr()->getDecl();
535 /// \brief Wrapper for source info for injected class names of class
537 class InjectedClassNameTypeLoc :
538 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
539 InjectedClassNameTypeLoc,
540 InjectedClassNameType> {
542 CXXRecordDecl *getDecl() const {
543 return getTypePtr()->getDecl();
547 /// \brief Wrapper for source info for unresolved typename using decls.
548 class UnresolvedUsingTypeLoc :
549 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
550 UnresolvedUsingTypeLoc,
551 UnresolvedUsingType> {
553 UnresolvedUsingTypenameDecl *getDecl() const {
554 return getTypePtr()->getDecl();
558 /// \brief Wrapper for source info for tag types. Note that this only
559 /// records source info for the name itself; a type written 'struct foo'
560 /// should be represented as an ElaboratedTypeLoc. We currently
561 /// only do that when C++ is enabled because of the expense of
562 /// creating an ElaboratedType node for so many type references in C.
563 class TagTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
567 TagDecl *getDecl() const { return getTypePtr()->getDecl(); }
569 /// \brief True if the tag was defined in this type specifier.
570 bool isDefinition() const {
571 return getDecl()->isCompleteDefinition() &&
572 (getNameLoc().isInvalid() || getNameLoc() == getDecl()->getLocation());
576 /// \brief Wrapper for source info for record types.
577 class RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
581 RecordDecl *getDecl() const { return getTypePtr()->getDecl(); }
584 /// \brief Wrapper for source info for enum types.
585 class EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
589 EnumDecl *getDecl() const { return getTypePtr()->getDecl(); }
592 /// \brief Wrapper for template type parameters.
593 class TemplateTypeParmTypeLoc :
594 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
595 TemplateTypeParmTypeLoc,
596 TemplateTypeParmType> {
598 TemplateTypeParmDecl *getDecl() const { return getTypePtr()->getDecl(); }
601 /// \brief Wrapper for substituted template type parameters.
602 class SubstTemplateTypeParmTypeLoc :
603 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
604 SubstTemplateTypeParmTypeLoc,
605 SubstTemplateTypeParmType> {
608 /// \brief Wrapper for substituted template type parameters.
609 class SubstTemplateTypeParmPackTypeLoc :
610 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
611 SubstTemplateTypeParmPackTypeLoc,
612 SubstTemplateTypeParmPackType> {
615 struct AttributedLocInfo {
619 /// A raw SourceLocation.
620 unsigned EnumOperandLoc;
623 SourceRange OperandParens;
625 SourceLocation AttrLoc;
628 /// \brief Type source information for an attributed type.
629 class AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
634 AttributedType::Kind getAttrKind() const {
635 return getTypePtr()->getAttrKind();
638 bool hasAttrExprOperand() const {
639 return (getAttrKind() >= AttributedType::FirstExprOperandKind &&
640 getAttrKind() <= AttributedType::LastExprOperandKind);
643 bool hasAttrEnumOperand() const {
644 return (getAttrKind() >= AttributedType::FirstEnumOperandKind &&
645 getAttrKind() <= AttributedType::LastEnumOperandKind);
648 bool hasAttrOperand() const {
649 return hasAttrExprOperand() || hasAttrEnumOperand();
652 /// The modified type, which is generally canonically different from
653 /// the attribute type.
654 /// int main(int, char**) __attribute__((noreturn))
655 /// ~~~ ~~~~~~~~~~~~~
656 TypeLoc getModifiedLoc() const {
657 return getInnerTypeLoc();
660 /// The location of the attribute name, i.e.
661 /// __attribute__((regparm(1000)))
663 SourceLocation getAttrNameLoc() const {
664 return getLocalData()->AttrLoc;
666 void setAttrNameLoc(SourceLocation loc) {
667 getLocalData()->AttrLoc = loc;
670 /// The attribute's expression operand, if it has one.
671 /// void *cur_thread __attribute__((address_space(21)))
673 Expr *getAttrExprOperand() const {
674 assert(hasAttrExprOperand());
675 return getLocalData()->ExprOperand;
677 void setAttrExprOperand(Expr *e) {
678 assert(hasAttrExprOperand());
679 getLocalData()->ExprOperand = e;
682 /// The location of the attribute's enumerated operand, if it has one.
683 /// void * __attribute__((objc_gc(weak)))
685 SourceLocation getAttrEnumOperandLoc() const {
686 assert(hasAttrEnumOperand());
687 return SourceLocation::getFromRawEncoding(getLocalData()->EnumOperandLoc);
689 void setAttrEnumOperandLoc(SourceLocation loc) {
690 assert(hasAttrEnumOperand());
691 getLocalData()->EnumOperandLoc = loc.getRawEncoding();
694 /// The location of the parentheses around the operand, if there is
696 /// void * __attribute__((objc_gc(weak)))
698 SourceRange getAttrOperandParensRange() const {
699 assert(hasAttrOperand());
700 return getLocalData()->OperandParens;
702 void setAttrOperandParensRange(SourceRange range) {
703 assert(hasAttrOperand());
704 getLocalData()->OperandParens = range;
707 SourceRange getLocalSourceRange() const {
708 // Note that this does *not* include the range of the attribute
710 // __attribute__((foo(bar)))
711 // ^~~~~~~~~~~~~~~ ~~
715 // That enclosure doesn't necessarily belong to a single attribute
717 SourceRange range(getAttrNameLoc());
718 if (hasAttrOperand())
719 range.setEnd(getAttrOperandParensRange().getEnd());
723 void initializeLocal(ASTContext &Context, SourceLocation loc) {
725 if (hasAttrExprOperand()) {
726 setAttrOperandParensRange(SourceRange(loc));
727 setAttrExprOperand(0);
728 } else if (hasAttrEnumOperand()) {
729 setAttrOperandParensRange(SourceRange(loc));
730 setAttrEnumOperandLoc(loc);
734 QualType getInnerType() const {
735 return getTypePtr()->getModifiedType();
740 struct ObjCProtocolListLocInfo {
741 SourceLocation LAngleLoc;
742 SourceLocation RAngleLoc;
743 bool HasBaseTypeAsWritten;
746 // A helper class for defining ObjC TypeLocs that can qualified with
749 // TypeClass basically has to be either ObjCInterfaceType or
750 // ObjCObjectPointerType.
751 class ObjCObjectTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
754 ObjCProtocolListLocInfo> {
755 // SourceLocations are stored after Info, one for each Protocol.
756 SourceLocation *getProtocolLocArray() const {
757 return (SourceLocation*) this->getExtraLocalData();
761 SourceLocation getLAngleLoc() const {
762 return this->getLocalData()->LAngleLoc;
764 void setLAngleLoc(SourceLocation Loc) {
765 this->getLocalData()->LAngleLoc = Loc;
768 SourceLocation getRAngleLoc() const {
769 return this->getLocalData()->RAngleLoc;
771 void setRAngleLoc(SourceLocation Loc) {
772 this->getLocalData()->RAngleLoc = Loc;
775 unsigned getNumProtocols() const {
776 return this->getTypePtr()->getNumProtocols();
779 SourceLocation getProtocolLoc(unsigned i) const {
780 assert(i < getNumProtocols() && "Index is out of bounds!");
781 return getProtocolLocArray()[i];
783 void setProtocolLoc(unsigned i, SourceLocation Loc) {
784 assert(i < getNumProtocols() && "Index is out of bounds!");
785 getProtocolLocArray()[i] = Loc;
788 ObjCProtocolDecl *getProtocol(unsigned i) const {
789 assert(i < getNumProtocols() && "Index is out of bounds!");
790 return *(this->getTypePtr()->qual_begin() + i);
793 bool hasBaseTypeAsWritten() const {
794 return getLocalData()->HasBaseTypeAsWritten;
797 void setHasBaseTypeAsWritten(bool HasBaseType) {
798 getLocalData()->HasBaseTypeAsWritten = HasBaseType;
801 TypeLoc getBaseLoc() const {
802 return getInnerTypeLoc();
805 SourceRange getLocalSourceRange() const {
806 return SourceRange(getLAngleLoc(), getRAngleLoc());
809 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
810 setHasBaseTypeAsWritten(true);
813 for (unsigned i = 0, e = getNumProtocols(); i != e; ++i)
814 setProtocolLoc(i, Loc);
817 unsigned getExtraLocalDataSize() const {
818 return this->getNumProtocols() * sizeof(SourceLocation);
821 QualType getInnerType() const {
822 return getTypePtr()->getBaseType();
827 struct ObjCInterfaceLocInfo {
828 SourceLocation NameLoc;
831 /// \brief Wrapper for source info for ObjC interfaces.
832 class ObjCInterfaceTypeLoc : public ConcreteTypeLoc<ObjCObjectTypeLoc,
833 ObjCInterfaceTypeLoc,
835 ObjCInterfaceLocInfo> {
837 ObjCInterfaceDecl *getIFaceDecl() const {
838 return getTypePtr()->getDecl();
841 SourceLocation getNameLoc() const {
842 return getLocalData()->NameLoc;
845 void setNameLoc(SourceLocation Loc) {
846 getLocalData()->NameLoc = Loc;
849 SourceRange getLocalSourceRange() const {
850 return SourceRange(getNameLoc());
853 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
858 struct ParenLocInfo {
859 SourceLocation LParenLoc;
860 SourceLocation RParenLoc;
864 : public ConcreteTypeLoc<UnqualTypeLoc, ParenTypeLoc, ParenType,
867 SourceLocation getLParenLoc() const {
868 return this->getLocalData()->LParenLoc;
870 SourceLocation getRParenLoc() const {
871 return this->getLocalData()->RParenLoc;
873 void setLParenLoc(SourceLocation Loc) {
874 this->getLocalData()->LParenLoc = Loc;
876 void setRParenLoc(SourceLocation Loc) {
877 this->getLocalData()->RParenLoc = Loc;
880 SourceRange getLocalSourceRange() const {
881 return SourceRange(getLParenLoc(), getRParenLoc());
884 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
889 TypeLoc getInnerLoc() const {
890 return getInnerTypeLoc();
893 QualType getInnerType() const {
894 return this->getTypePtr()->getInnerType();
899 struct PointerLikeLocInfo {
900 SourceLocation StarLoc;
904 template <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo>
905 class PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived,
906 TypeClass, LocalData> {
908 SourceLocation getSigilLoc() const {
909 return this->getLocalData()->StarLoc;
911 void setSigilLoc(SourceLocation Loc) {
912 this->getLocalData()->StarLoc = Loc;
915 TypeLoc getPointeeLoc() const {
916 return this->getInnerTypeLoc();
919 SourceRange getLocalSourceRange() const {
920 return SourceRange(getSigilLoc(), getSigilLoc());
923 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
927 QualType getInnerType() const {
928 return this->getTypePtr()->getPointeeType();
933 /// \brief Wrapper for source info for pointers.
934 class PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc,
937 SourceLocation getStarLoc() const {
938 return getSigilLoc();
940 void setStarLoc(SourceLocation Loc) {
946 /// \brief Wrapper for source info for block pointers.
947 class BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc,
950 SourceLocation getCaretLoc() const {
951 return getSigilLoc();
953 void setCaretLoc(SourceLocation Loc) {
958 struct MemberPointerLocInfo : public PointerLikeLocInfo {
959 TypeSourceInfo *ClassTInfo;
962 /// \brief Wrapper for source info for member pointers.
963 class MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc,
965 MemberPointerLocInfo> {
967 SourceLocation getStarLoc() const {
968 return getSigilLoc();
970 void setStarLoc(SourceLocation Loc) {
974 const Type *getClass() const {
975 return getTypePtr()->getClass();
977 TypeSourceInfo *getClassTInfo() const {
978 return getLocalData()->ClassTInfo;
980 void setClassTInfo(TypeSourceInfo* TI) {
981 getLocalData()->ClassTInfo = TI;
984 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
989 SourceRange getLocalSourceRange() const {
990 if (TypeSourceInfo *TI = getClassTInfo())
991 return SourceRange(TI->getTypeLoc().getBeginLoc(), getStarLoc());
993 return SourceRange(getStarLoc());
997 /// Wraps an ObjCPointerType with source location information.
998 class ObjCObjectPointerTypeLoc :
999 public PointerLikeTypeLoc<ObjCObjectPointerTypeLoc,
1000 ObjCObjectPointerType> {
1002 SourceLocation getStarLoc() const {
1003 return getSigilLoc();
1006 void setStarLoc(SourceLocation Loc) {
1012 class ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc,
1015 QualType getInnerType() const {
1016 return getTypePtr()->getPointeeTypeAsWritten();
1020 class LValueReferenceTypeLoc :
1021 public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1022 LValueReferenceTypeLoc,
1023 LValueReferenceType> {
1025 SourceLocation getAmpLoc() const {
1026 return getSigilLoc();
1028 void setAmpLoc(SourceLocation Loc) {
1033 class RValueReferenceTypeLoc :
1034 public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1035 RValueReferenceTypeLoc,
1036 RValueReferenceType> {
1038 SourceLocation getAmpAmpLoc() const {
1039 return getSigilLoc();
1041 void setAmpAmpLoc(SourceLocation Loc) {
1047 struct FunctionLocInfo {
1048 SourceLocation LocalRangeBegin;
1049 SourceLocation LocalRangeEnd;
1050 bool TrailingReturn;
1053 /// \brief Wrapper for source info for functions.
1054 class FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1059 SourceLocation getLocalRangeBegin() const {
1060 return getLocalData()->LocalRangeBegin;
1062 void setLocalRangeBegin(SourceLocation L) {
1063 getLocalData()->LocalRangeBegin = L;
1066 SourceLocation getLocalRangeEnd() const {
1067 return getLocalData()->LocalRangeEnd;
1069 void setLocalRangeEnd(SourceLocation L) {
1070 getLocalData()->LocalRangeEnd = L;
1073 bool getTrailingReturn() const {
1074 return getLocalData()->TrailingReturn;
1076 void setTrailingReturn(bool Trailing) {
1077 getLocalData()->TrailingReturn = Trailing;
1080 // ParmVarDecls* are stored after Info, one for each argument.
1081 ParmVarDecl **getParmArray() const {
1082 return (ParmVarDecl**) getExtraLocalData();
1085 unsigned getNumArgs() const {
1086 if (isa<FunctionNoProtoType>(getTypePtr()))
1088 return cast<FunctionProtoType>(getTypePtr())->getNumArgs();
1090 ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; }
1091 void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; }
1093 TypeLoc getResultLoc() const {
1094 return getInnerTypeLoc();
1097 SourceRange getLocalSourceRange() const {
1098 return SourceRange(getLocalRangeBegin(), getLocalRangeEnd());
1101 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1102 setLocalRangeBegin(Loc);
1103 setLocalRangeEnd(Loc);
1104 setTrailingReturn(false);
1105 for (unsigned i = 0, e = getNumArgs(); i != e; ++i)
1109 /// \brief Returns the size of the type source info data block that is
1110 /// specific to this type.
1111 unsigned getExtraLocalDataSize() const {
1112 return getNumArgs() * sizeof(ParmVarDecl*);
1115 QualType getInnerType() const { return getTypePtr()->getResultType(); }
1118 class FunctionProtoTypeLoc :
1119 public InheritingConcreteTypeLoc<FunctionTypeLoc,
1120 FunctionProtoTypeLoc,
1121 FunctionProtoType> {
1124 class FunctionNoProtoTypeLoc :
1125 public InheritingConcreteTypeLoc<FunctionTypeLoc,
1126 FunctionNoProtoTypeLoc,
1127 FunctionNoProtoType> {
1131 struct ArrayLocInfo {
1132 SourceLocation LBracketLoc, RBracketLoc;
1136 /// \brief Wrapper for source info for arrays.
1137 class ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1142 SourceLocation getLBracketLoc() const {
1143 return getLocalData()->LBracketLoc;
1145 void setLBracketLoc(SourceLocation Loc) {
1146 getLocalData()->LBracketLoc = Loc;
1149 SourceLocation getRBracketLoc() const {
1150 return getLocalData()->RBracketLoc;
1152 void setRBracketLoc(SourceLocation Loc) {
1153 getLocalData()->RBracketLoc = Loc;
1156 SourceRange getBracketsRange() const {
1157 return SourceRange(getLBracketLoc(), getRBracketLoc());
1160 Expr *getSizeExpr() const {
1161 return getLocalData()->Size;
1163 void setSizeExpr(Expr *Size) {
1164 getLocalData()->Size = Size;
1167 TypeLoc getElementLoc() const {
1168 return getInnerTypeLoc();
1171 SourceRange getLocalSourceRange() const {
1172 return SourceRange(getLBracketLoc(), getRBracketLoc());
1175 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1176 setLBracketLoc(Loc);
1177 setRBracketLoc(Loc);
1181 QualType getInnerType() const { return getTypePtr()->getElementType(); }
1184 class ConstantArrayTypeLoc :
1185 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1186 ConstantArrayTypeLoc,
1187 ConstantArrayType> {
1190 class IncompleteArrayTypeLoc :
1191 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1192 IncompleteArrayTypeLoc,
1193 IncompleteArrayType> {
1196 class DependentSizedArrayTypeLoc :
1197 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1198 DependentSizedArrayTypeLoc,
1199 DependentSizedArrayType> {
1203 class VariableArrayTypeLoc :
1204 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1205 VariableArrayTypeLoc,
1206 VariableArrayType> {
1210 // Location information for a TemplateName. Rudimentary for now.
1211 struct TemplateNameLocInfo {
1212 SourceLocation NameLoc;
1215 struct TemplateSpecializationLocInfo : TemplateNameLocInfo {
1216 SourceLocation LAngleLoc;
1217 SourceLocation RAngleLoc;
1220 class TemplateSpecializationTypeLoc :
1221 public ConcreteTypeLoc<UnqualTypeLoc,
1222 TemplateSpecializationTypeLoc,
1223 TemplateSpecializationType,
1224 TemplateSpecializationLocInfo> {
1226 SourceLocation getLAngleLoc() const {
1227 return getLocalData()->LAngleLoc;
1229 void setLAngleLoc(SourceLocation Loc) {
1230 getLocalData()->LAngleLoc = Loc;
1233 SourceLocation getRAngleLoc() const {
1234 return getLocalData()->RAngleLoc;
1236 void setRAngleLoc(SourceLocation Loc) {
1237 getLocalData()->RAngleLoc = Loc;
1240 unsigned getNumArgs() const {
1241 return getTypePtr()->getNumArgs();
1243 void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
1244 getArgInfos()[i] = AI;
1246 TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
1247 return getArgInfos()[i];
1250 TemplateArgumentLoc getArgLoc(unsigned i) const {
1251 return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
1254 SourceLocation getTemplateNameLoc() const {
1255 return getLocalData()->NameLoc;
1257 void setTemplateNameLoc(SourceLocation Loc) {
1258 getLocalData()->NameLoc = Loc;
1261 /// \brief - Copy the location information from the given info.
1262 void copy(TemplateSpecializationTypeLoc Loc) {
1263 unsigned size = getFullDataSize();
1264 assert(size == Loc.getFullDataSize());
1266 // We're potentially copying Expr references here. We don't
1267 // bother retaining them because TypeSourceInfos live forever, so
1268 // as long as the Expr was retained when originally written into
1269 // the TypeLoc, we're okay.
1270 memcpy(Data, Loc.Data, size);
1273 SourceRange getLocalSourceRange() const {
1274 return SourceRange(getTemplateNameLoc(), getRAngleLoc());
1277 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1280 setTemplateNameLoc(Loc);
1281 initializeArgLocs(Context, getNumArgs(), getTypePtr()->getArgs(),
1282 getArgInfos(), Loc);
1285 static void initializeArgLocs(ASTContext &Context, unsigned NumArgs,
1286 const TemplateArgument *Args,
1287 TemplateArgumentLocInfo *ArgInfos,
1288 SourceLocation Loc);
1290 unsigned getExtraLocalDataSize() const {
1291 return getNumArgs() * sizeof(TemplateArgumentLocInfo);
1295 TemplateArgumentLocInfo *getArgInfos() const {
1296 return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
1300 //===----------------------------------------------------------------------===//
1302 // All of these need proper implementations.
1304 //===----------------------------------------------------------------------===//
1306 // FIXME: size expression and attribute locations (or keyword if we
1307 // ever fully support altivec syntax).
1308 class VectorTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1313 // FIXME: size expression and attribute locations.
1314 class ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc,
1319 // FIXME: attribute locations.
1320 // For some reason, this isn't a subtype of VectorType.
1321 class DependentSizedExtVectorTypeLoc :
1322 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1323 DependentSizedExtVectorTypeLoc,
1324 DependentSizedExtVectorType> {
1327 // FIXME: location of the '_Complex' keyword.
1328 class ComplexTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1333 struct TypeofLocInfo {
1334 SourceLocation TypeofLoc;
1335 SourceLocation LParenLoc;
1336 SourceLocation RParenLoc;
1339 struct TypeOfExprTypeLocInfo : public TypeofLocInfo {
1342 struct TypeOfTypeLocInfo : public TypeofLocInfo {
1343 TypeSourceInfo* UnderlyingTInfo;
1346 template <class Derived, class TypeClass, class LocalData = TypeofLocInfo>
1347 class TypeofLikeTypeLoc
1348 : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> {
1350 SourceLocation getTypeofLoc() const {
1351 return this->getLocalData()->TypeofLoc;
1353 void setTypeofLoc(SourceLocation Loc) {
1354 this->getLocalData()->TypeofLoc = Loc;
1357 SourceLocation getLParenLoc() const {
1358 return this->getLocalData()->LParenLoc;
1360 void setLParenLoc(SourceLocation Loc) {
1361 this->getLocalData()->LParenLoc = Loc;
1364 SourceLocation getRParenLoc() const {
1365 return this->getLocalData()->RParenLoc;
1367 void setRParenLoc(SourceLocation Loc) {
1368 this->getLocalData()->RParenLoc = Loc;
1371 SourceRange getParensRange() const {
1372 return SourceRange(getLParenLoc(), getRParenLoc());
1374 void setParensRange(SourceRange range) {
1375 setLParenLoc(range.getBegin());
1376 setRParenLoc(range.getEnd());
1379 SourceRange getLocalSourceRange() const {
1380 return SourceRange(getTypeofLoc(), getRParenLoc());
1383 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1390 class TypeOfExprTypeLoc : public TypeofLikeTypeLoc<TypeOfExprTypeLoc,
1392 TypeOfExprTypeLocInfo> {
1394 Expr* getUnderlyingExpr() const {
1395 return getTypePtr()->getUnderlyingExpr();
1397 // Reimplemented to account for GNU/C++ extension
1398 // typeof unary-expression
1399 // where there are no parentheses.
1400 SourceRange getLocalSourceRange() const;
1404 : public TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo> {
1406 QualType getUnderlyingType() const {
1407 return this->getTypePtr()->getUnderlyingType();
1409 TypeSourceInfo* getUnderlyingTInfo() const {
1410 return this->getLocalData()->UnderlyingTInfo;
1412 void setUnderlyingTInfo(TypeSourceInfo* TI) const {
1413 this->getLocalData()->UnderlyingTInfo = TI;
1417 // FIXME: location of the 'decltype' and parens.
1418 class DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1422 Expr *getUnderlyingExpr() const { return getTypePtr()->getUnderlyingExpr(); }
1425 struct UnaryTransformTypeLocInfo {
1426 // FIXME: While there's only one unary transform right now, future ones may
1427 // need different representations
1428 SourceLocation KWLoc, LParenLoc, RParenLoc;
1429 TypeSourceInfo *UnderlyingTInfo;
1432 class UnaryTransformTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1433 UnaryTransformTypeLoc,
1435 UnaryTransformTypeLocInfo> {
1437 SourceLocation getKWLoc() const { return getLocalData()->KWLoc; }
1438 void setKWLoc(SourceLocation Loc) { getLocalData()->KWLoc = Loc; }
1440 SourceLocation getLParenLoc() const { return getLocalData()->LParenLoc; }
1441 void setLParenLoc(SourceLocation Loc) { getLocalData()->LParenLoc = Loc; }
1443 SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
1444 void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
1446 TypeSourceInfo* getUnderlyingTInfo() const {
1447 return getLocalData()->UnderlyingTInfo;
1449 void setUnderlyingTInfo(TypeSourceInfo *TInfo) {
1450 getLocalData()->UnderlyingTInfo = TInfo;
1453 SourceRange getLocalSourceRange() const {
1454 return SourceRange(getKWLoc(), getRParenLoc());
1457 SourceRange getParensRange() const {
1458 return SourceRange(getLParenLoc(), getRParenLoc());
1460 void setParensRange(SourceRange Range) {
1461 setLParenLoc(Range.getBegin());
1462 setRParenLoc(Range.getEnd());
1465 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1472 class AutoTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1477 struct ElaboratedLocInfo {
1478 SourceLocation KeywordLoc;
1480 /// \brief Opaque data pointer used to reconstruct a nested-name-specifier
1482 void *QualifierData;
1485 class ElaboratedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1488 ElaboratedLocInfo> {
1490 SourceLocation getKeywordLoc() const {
1491 return this->getLocalData()->KeywordLoc;
1493 void setKeywordLoc(SourceLocation Loc) {
1494 this->getLocalData()->KeywordLoc = Loc;
1497 NestedNameSpecifierLoc getQualifierLoc() const {
1498 return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
1499 getLocalData()->QualifierData);
1502 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1503 assert(QualifierLoc.getNestedNameSpecifier()
1504 == getTypePtr()->getQualifier() &&
1505 "Inconsistent nested-name-specifier pointer");
1506 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1509 SourceRange getLocalSourceRange() const {
1510 if (getKeywordLoc().isValid())
1511 if (getQualifierLoc())
1512 return SourceRange(getKeywordLoc(), getQualifierLoc().getEndLoc());
1514 return SourceRange(getKeywordLoc());
1516 return getQualifierLoc().getSourceRange();
1519 void initializeLocal(ASTContext &Context, SourceLocation Loc);
1521 TypeLoc getNamedTypeLoc() const {
1522 return getInnerTypeLoc();
1525 QualType getInnerType() const {
1526 return getTypePtr()->getNamedType();
1529 void copy(ElaboratedTypeLoc Loc) {
1530 unsigned size = getFullDataSize();
1531 assert(size == Loc.getFullDataSize());
1532 memcpy(Data, Loc.Data, size);
1536 // This is exactly the structure of an ElaboratedTypeLoc whose inner
1537 // type is some sort of TypeDeclTypeLoc.
1538 struct DependentNameLocInfo : ElaboratedLocInfo {
1539 SourceLocation NameLoc;
1541 /// \brief Data associated with the nested-name-specifier location.
1542 void *QualifierData;
1545 class DependentNameTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1546 DependentNameTypeLoc,
1548 DependentNameLocInfo> {
1550 SourceLocation getKeywordLoc() const {
1551 return this->getLocalData()->KeywordLoc;
1553 void setKeywordLoc(SourceLocation Loc) {
1554 this->getLocalData()->KeywordLoc = Loc;
1557 NestedNameSpecifierLoc getQualifierLoc() const {
1558 return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
1559 getLocalData()->QualifierData);
1562 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1563 assert(QualifierLoc.getNestedNameSpecifier()
1564 == getTypePtr()->getQualifier() &&
1565 "Inconsistent nested-name-specifier pointer");
1566 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1569 SourceLocation getNameLoc() const {
1570 return this->getLocalData()->NameLoc;
1572 void setNameLoc(SourceLocation Loc) {
1573 this->getLocalData()->NameLoc = Loc;
1576 SourceRange getLocalSourceRange() const {
1577 if (getKeywordLoc().isValid())
1578 return SourceRange(getKeywordLoc(), getNameLoc());
1580 return SourceRange(getQualifierLoc().getBeginLoc(), getNameLoc());
1583 void copy(DependentNameTypeLoc Loc) {
1584 unsigned size = getFullDataSize();
1585 assert(size == Loc.getFullDataSize());
1586 memcpy(Data, Loc.Data, size);
1589 void initializeLocal(ASTContext &Context, SourceLocation Loc);
1592 struct DependentTemplateSpecializationLocInfo : DependentNameLocInfo {
1593 SourceLocation KeywordLoc;
1594 SourceLocation LAngleLoc;
1595 SourceLocation RAngleLoc;
1596 // followed by a TemplateArgumentLocInfo[]
1599 class DependentTemplateSpecializationTypeLoc :
1600 public ConcreteTypeLoc<UnqualTypeLoc,
1601 DependentTemplateSpecializationTypeLoc,
1602 DependentTemplateSpecializationType,
1603 DependentTemplateSpecializationLocInfo> {
1605 SourceLocation getKeywordLoc() const {
1606 return this->getLocalData()->KeywordLoc;
1608 void setKeywordLoc(SourceLocation Loc) {
1609 this->getLocalData()->KeywordLoc = Loc;
1612 NestedNameSpecifierLoc getQualifierLoc() const {
1613 if (!getLocalData()->QualifierData)
1614 return NestedNameSpecifierLoc();
1616 return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
1617 getLocalData()->QualifierData);
1620 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1621 if (!QualifierLoc) {
1622 // Even if we have a nested-name-specifier in the dependent
1623 // template specialization type, we won't record the nested-name-specifier
1624 // location information when this type-source location information is
1625 // part of a nested-name-specifier.
1626 getLocalData()->QualifierData = 0;
1630 assert(QualifierLoc.getNestedNameSpecifier()
1631 == getTypePtr()->getQualifier() &&
1632 "Inconsistent nested-name-specifier pointer");
1633 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1636 SourceLocation getNameLoc() const {
1637 return this->getLocalData()->NameLoc;
1639 void setNameLoc(SourceLocation Loc) {
1640 this->getLocalData()->NameLoc = Loc;
1643 SourceLocation getLAngleLoc() const {
1644 return this->getLocalData()->LAngleLoc;
1646 void setLAngleLoc(SourceLocation Loc) {
1647 this->getLocalData()->LAngleLoc = Loc;
1650 SourceLocation getRAngleLoc() const {
1651 return this->getLocalData()->RAngleLoc;
1653 void setRAngleLoc(SourceLocation Loc) {
1654 this->getLocalData()->RAngleLoc = Loc;
1657 unsigned getNumArgs() const {
1658 return getTypePtr()->getNumArgs();
1661 void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
1662 getArgInfos()[i] = AI;
1664 TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
1665 return getArgInfos()[i];
1668 TemplateArgumentLoc getArgLoc(unsigned i) const {
1669 return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
1672 SourceRange getLocalSourceRange() const {
1673 if (getKeywordLoc().isValid())
1674 return SourceRange(getKeywordLoc(), getRAngleLoc());
1675 else if (getQualifierLoc())
1676 return SourceRange(getQualifierLoc().getBeginLoc(), getRAngleLoc());
1678 return SourceRange(getNameLoc(), getRAngleLoc());
1681 void copy(DependentTemplateSpecializationTypeLoc Loc) {
1682 unsigned size = getFullDataSize();
1683 assert(size == Loc.getFullDataSize());
1684 memcpy(Data, Loc.Data, size);
1687 void initializeLocal(ASTContext &Context, SourceLocation Loc);
1689 unsigned getExtraLocalDataSize() const {
1690 return getNumArgs() * sizeof(TemplateArgumentLocInfo);
1694 TemplateArgumentLocInfo *getArgInfos() const {
1695 return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
1700 struct PackExpansionTypeLocInfo {
1701 SourceLocation EllipsisLoc;
1704 class PackExpansionTypeLoc
1705 : public ConcreteTypeLoc<UnqualTypeLoc, PackExpansionTypeLoc,
1706 PackExpansionType, PackExpansionTypeLocInfo> {
1708 SourceLocation getEllipsisLoc() const {
1709 return this->getLocalData()->EllipsisLoc;
1712 void setEllipsisLoc(SourceLocation Loc) {
1713 this->getLocalData()->EllipsisLoc = Loc;
1716 SourceRange getLocalSourceRange() const {
1717 return SourceRange(getEllipsisLoc(), getEllipsisLoc());
1720 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1721 setEllipsisLoc(Loc);
1724 TypeLoc getPatternLoc() const {
1725 return getInnerTypeLoc();
1728 QualType getInnerType() const {
1729 return this->getTypePtr()->getPattern();
1733 struct AtomicTypeLocInfo {
1734 SourceLocation KWLoc, LParenLoc, RParenLoc;
1737 class AtomicTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, AtomicTypeLoc,
1738 AtomicType, AtomicTypeLocInfo> {
1740 TypeLoc getValueLoc() const {
1741 return this->getInnerTypeLoc();
1744 SourceRange getLocalSourceRange() const {
1745 return SourceRange(getKWLoc(), getRParenLoc());
1748 SourceLocation getKWLoc() const {
1749 return this->getLocalData()->KWLoc;
1751 void setKWLoc(SourceLocation Loc) {
1752 this->getLocalData()->KWLoc = Loc;
1755 SourceLocation getLParenLoc() const {
1756 return this->getLocalData()->LParenLoc;
1758 void setLParenLoc(SourceLocation Loc) {
1759 this->getLocalData()->LParenLoc = Loc;
1762 SourceLocation getRParenLoc() const {
1763 return this->getLocalData()->RParenLoc;
1765 void setRParenLoc(SourceLocation Loc) {
1766 this->getLocalData()->RParenLoc = Loc;
1769 SourceRange getParensRange() const {
1770 return SourceRange(getLParenLoc(), getRParenLoc());
1772 void setParensRange(SourceRange Range) {
1773 setLParenLoc(Range.getBegin());
1774 setRParenLoc(Range.getEnd());
1777 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1783 QualType getInnerType() const {
1784 return this->getTypePtr()->getValueType();