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> {
543 /// \brief Wrapper for source info for unresolved typename using decls.
544 class UnresolvedUsingTypeLoc :
545 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
546 UnresolvedUsingTypeLoc,
547 UnresolvedUsingType> {
549 UnresolvedUsingTypenameDecl *getDecl() const {
550 return getTypePtr()->getDecl();
554 /// \brief Wrapper for source info for tag types. Note that this only
555 /// records source info for the name itself; a type written 'struct foo'
556 /// should be represented as an ElaboratedTypeLoc. We currently
557 /// only do that when C++ is enabled because of the expense of
558 /// creating an ElaboratedType node for so many type references in C.
559 class TagTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
563 TagDecl *getDecl() const { return getTypePtr()->getDecl(); }
566 /// \brief Wrapper for source info for record types.
567 class RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
571 RecordDecl *getDecl() const { return getTypePtr()->getDecl(); }
574 /// \brief Wrapper for source info for enum types.
575 class EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
579 EnumDecl *getDecl() const { return getTypePtr()->getDecl(); }
582 /// \brief Wrapper for template type parameters.
583 class TemplateTypeParmTypeLoc :
584 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
585 TemplateTypeParmTypeLoc,
586 TemplateTypeParmType> {
588 TemplateTypeParmDecl *getDecl() const { return getTypePtr()->getDecl(); }
591 /// \brief Wrapper for substituted template type parameters.
592 class SubstTemplateTypeParmTypeLoc :
593 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
594 SubstTemplateTypeParmTypeLoc,
595 SubstTemplateTypeParmType> {
598 /// \brief Wrapper for substituted template type parameters.
599 class SubstTemplateTypeParmPackTypeLoc :
600 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
601 SubstTemplateTypeParmPackTypeLoc,
602 SubstTemplateTypeParmPackType> {
605 struct AttributedLocInfo {
609 /// A raw SourceLocation.
610 unsigned EnumOperandLoc;
613 SourceRange OperandParens;
615 SourceLocation AttrLoc;
618 /// \brief Type source information for an attributed type.
619 class AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
624 AttributedType::Kind getAttrKind() const {
625 return getTypePtr()->getAttrKind();
628 bool hasAttrExprOperand() const {
629 return (getAttrKind() >= AttributedType::FirstExprOperandKind &&
630 getAttrKind() <= AttributedType::LastExprOperandKind);
633 bool hasAttrEnumOperand() const {
634 return (getAttrKind() >= AttributedType::FirstEnumOperandKind &&
635 getAttrKind() <= AttributedType::LastEnumOperandKind);
638 bool hasAttrOperand() const {
639 return hasAttrExprOperand() || hasAttrEnumOperand();
642 /// The modified type, which is generally canonically different from
643 /// the attribute type.
644 /// int main(int, char**) __attribute__((noreturn))
645 /// ~~~ ~~~~~~~~~~~~~
646 TypeLoc getModifiedLoc() const {
647 return getInnerTypeLoc();
650 /// The location of the attribute name, i.e.
651 /// __attribute__((regparm(1000)))
653 SourceLocation getAttrNameLoc() const {
654 return getLocalData()->AttrLoc;
656 void setAttrNameLoc(SourceLocation loc) {
657 getLocalData()->AttrLoc = loc;
660 /// The attribute's expression operand, if it has one.
661 /// void *cur_thread __attribute__((address_space(21)))
663 Expr *getAttrExprOperand() const {
664 assert(hasAttrExprOperand());
665 return getLocalData()->ExprOperand;
667 void setAttrExprOperand(Expr *e) {
668 assert(hasAttrExprOperand());
669 getLocalData()->ExprOperand = e;
672 /// The location of the attribute's enumerated operand, if it has one.
673 /// void * __attribute__((objc_gc(weak)))
675 SourceLocation getAttrEnumOperandLoc() const {
676 assert(hasAttrEnumOperand());
677 return SourceLocation::getFromRawEncoding(getLocalData()->EnumOperandLoc);
679 void setAttrEnumOperandLoc(SourceLocation loc) {
680 assert(hasAttrEnumOperand());
681 getLocalData()->EnumOperandLoc = loc.getRawEncoding();
684 /// The location of the parentheses around the operand, if there is
686 /// void * __attribute__((objc_gc(weak)))
688 SourceRange getAttrOperandParensRange() const {
689 assert(hasAttrOperand());
690 return getLocalData()->OperandParens;
692 void setAttrOperandParensRange(SourceRange range) {
693 assert(hasAttrOperand());
694 getLocalData()->OperandParens = range;
697 SourceRange getLocalSourceRange() const {
698 // Note that this does *not* include the range of the attribute
700 // __attribute__((foo(bar)))
701 // ^~~~~~~~~~~~~~~ ~~
705 // That enclosure doesn't necessarily belong to a single attribute
707 SourceRange range(getAttrNameLoc());
708 if (hasAttrOperand())
709 range.setEnd(getAttrOperandParensRange().getEnd());
713 void initializeLocal(ASTContext &Context, SourceLocation loc) {
715 if (hasAttrExprOperand()) {
716 setAttrOperandParensRange(SourceRange(loc));
717 setAttrExprOperand(0);
718 } else if (hasAttrEnumOperand()) {
719 setAttrOperandParensRange(SourceRange(loc));
720 setAttrEnumOperandLoc(loc);
724 QualType getInnerType() const {
725 return getTypePtr()->getModifiedType();
730 struct ObjCProtocolListLocInfo {
731 SourceLocation LAngleLoc;
732 SourceLocation RAngleLoc;
733 bool HasBaseTypeAsWritten;
736 // A helper class for defining ObjC TypeLocs that can qualified with
739 // TypeClass basically has to be either ObjCInterfaceType or
740 // ObjCObjectPointerType.
741 class ObjCObjectTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
744 ObjCProtocolListLocInfo> {
745 // SourceLocations are stored after Info, one for each Protocol.
746 SourceLocation *getProtocolLocArray() const {
747 return (SourceLocation*) this->getExtraLocalData();
751 SourceLocation getLAngleLoc() const {
752 return this->getLocalData()->LAngleLoc;
754 void setLAngleLoc(SourceLocation Loc) {
755 this->getLocalData()->LAngleLoc = Loc;
758 SourceLocation getRAngleLoc() const {
759 return this->getLocalData()->RAngleLoc;
761 void setRAngleLoc(SourceLocation Loc) {
762 this->getLocalData()->RAngleLoc = Loc;
765 unsigned getNumProtocols() const {
766 return this->getTypePtr()->getNumProtocols();
769 SourceLocation getProtocolLoc(unsigned i) const {
770 assert(i < getNumProtocols() && "Index is out of bounds!");
771 return getProtocolLocArray()[i];
773 void setProtocolLoc(unsigned i, SourceLocation Loc) {
774 assert(i < getNumProtocols() && "Index is out of bounds!");
775 getProtocolLocArray()[i] = Loc;
778 ObjCProtocolDecl *getProtocol(unsigned i) const {
779 assert(i < getNumProtocols() && "Index is out of bounds!");
780 return *(this->getTypePtr()->qual_begin() + i);
783 bool hasBaseTypeAsWritten() const {
784 return getLocalData()->HasBaseTypeAsWritten;
787 void setHasBaseTypeAsWritten(bool HasBaseType) {
788 getLocalData()->HasBaseTypeAsWritten = HasBaseType;
791 TypeLoc getBaseLoc() const {
792 return getInnerTypeLoc();
795 SourceRange getLocalSourceRange() const {
796 return SourceRange(getLAngleLoc(), getRAngleLoc());
799 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
800 setHasBaseTypeAsWritten(true);
803 for (unsigned i = 0, e = getNumProtocols(); i != e; ++i)
804 setProtocolLoc(i, Loc);
807 unsigned getExtraLocalDataSize() const {
808 return this->getNumProtocols() * sizeof(SourceLocation);
811 QualType getInnerType() const {
812 return getTypePtr()->getBaseType();
817 struct ObjCInterfaceLocInfo {
818 SourceLocation NameLoc;
821 /// \brief Wrapper for source info for ObjC interfaces.
822 class ObjCInterfaceTypeLoc : public ConcreteTypeLoc<ObjCObjectTypeLoc,
823 ObjCInterfaceTypeLoc,
825 ObjCInterfaceLocInfo> {
827 ObjCInterfaceDecl *getIFaceDecl() const {
828 return getTypePtr()->getDecl();
831 SourceLocation getNameLoc() const {
832 return getLocalData()->NameLoc;
835 void setNameLoc(SourceLocation Loc) {
836 getLocalData()->NameLoc = Loc;
839 SourceRange getLocalSourceRange() const {
840 return SourceRange(getNameLoc());
843 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
848 struct ParenLocInfo {
849 SourceLocation LParenLoc;
850 SourceLocation RParenLoc;
854 : public ConcreteTypeLoc<UnqualTypeLoc, ParenTypeLoc, ParenType,
857 SourceLocation getLParenLoc() const {
858 return this->getLocalData()->LParenLoc;
860 SourceLocation getRParenLoc() const {
861 return this->getLocalData()->RParenLoc;
863 void setLParenLoc(SourceLocation Loc) {
864 this->getLocalData()->LParenLoc = Loc;
866 void setRParenLoc(SourceLocation Loc) {
867 this->getLocalData()->RParenLoc = Loc;
870 SourceRange getLocalSourceRange() const {
871 return SourceRange(getLParenLoc(), getRParenLoc());
874 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
879 TypeLoc getInnerLoc() const {
880 return getInnerTypeLoc();
883 QualType getInnerType() const {
884 return this->getTypePtr()->getInnerType();
889 struct PointerLikeLocInfo {
890 SourceLocation StarLoc;
894 template <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo>
895 class PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived,
896 TypeClass, LocalData> {
898 SourceLocation getSigilLoc() const {
899 return this->getLocalData()->StarLoc;
901 void setSigilLoc(SourceLocation Loc) {
902 this->getLocalData()->StarLoc = Loc;
905 TypeLoc getPointeeLoc() const {
906 return this->getInnerTypeLoc();
909 SourceRange getLocalSourceRange() const {
910 return SourceRange(getSigilLoc(), getSigilLoc());
913 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
917 QualType getInnerType() const {
918 return this->getTypePtr()->getPointeeType();
923 /// \brief Wrapper for source info for pointers.
924 class PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc,
927 SourceLocation getStarLoc() const {
928 return getSigilLoc();
930 void setStarLoc(SourceLocation Loc) {
936 /// \brief Wrapper for source info for block pointers.
937 class BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc,
940 SourceLocation getCaretLoc() const {
941 return getSigilLoc();
943 void setCaretLoc(SourceLocation Loc) {
948 struct MemberPointerLocInfo : public PointerLikeLocInfo {
949 TypeSourceInfo *ClassTInfo;
952 /// \brief Wrapper for source info for member pointers.
953 class MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc,
955 MemberPointerLocInfo> {
957 SourceLocation getStarLoc() const {
958 return getSigilLoc();
960 void setStarLoc(SourceLocation Loc) {
964 const Type *getClass() const {
965 return getTypePtr()->getClass();
967 TypeSourceInfo *getClassTInfo() const {
968 return getLocalData()->ClassTInfo;
970 void setClassTInfo(TypeSourceInfo* TI) {
971 getLocalData()->ClassTInfo = TI;
974 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
979 SourceRange getLocalSourceRange() const {
980 if (TypeSourceInfo *TI = getClassTInfo())
981 return SourceRange(TI->getTypeLoc().getBeginLoc(), getStarLoc());
983 return SourceRange(getStarLoc());
987 /// Wraps an ObjCPointerType with source location information.
988 class ObjCObjectPointerTypeLoc :
989 public PointerLikeTypeLoc<ObjCObjectPointerTypeLoc,
990 ObjCObjectPointerType> {
992 SourceLocation getStarLoc() const {
993 return getSigilLoc();
996 void setStarLoc(SourceLocation Loc) {
1002 class ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc,
1005 QualType getInnerType() const {
1006 return getTypePtr()->getPointeeTypeAsWritten();
1010 class LValueReferenceTypeLoc :
1011 public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1012 LValueReferenceTypeLoc,
1013 LValueReferenceType> {
1015 SourceLocation getAmpLoc() const {
1016 return getSigilLoc();
1018 void setAmpLoc(SourceLocation Loc) {
1023 class RValueReferenceTypeLoc :
1024 public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1025 RValueReferenceTypeLoc,
1026 RValueReferenceType> {
1028 SourceLocation getAmpAmpLoc() const {
1029 return getSigilLoc();
1031 void setAmpAmpLoc(SourceLocation Loc) {
1037 struct FunctionLocInfo {
1038 SourceLocation LocalRangeBegin;
1039 SourceLocation LocalRangeEnd;
1040 bool TrailingReturn;
1043 /// \brief Wrapper for source info for functions.
1044 class FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1049 SourceLocation getLocalRangeBegin() const {
1050 return getLocalData()->LocalRangeBegin;
1052 void setLocalRangeBegin(SourceLocation L) {
1053 getLocalData()->LocalRangeBegin = L;
1056 SourceLocation getLocalRangeEnd() const {
1057 return getLocalData()->LocalRangeEnd;
1059 void setLocalRangeEnd(SourceLocation L) {
1060 getLocalData()->LocalRangeEnd = L;
1063 bool getTrailingReturn() const {
1064 return getLocalData()->TrailingReturn;
1066 void setTrailingReturn(bool Trailing) {
1067 getLocalData()->TrailingReturn = Trailing;
1070 // ParmVarDecls* are stored after Info, one for each argument.
1071 ParmVarDecl **getParmArray() const {
1072 return (ParmVarDecl**) getExtraLocalData();
1075 unsigned getNumArgs() const {
1076 if (isa<FunctionNoProtoType>(getTypePtr()))
1078 return cast<FunctionProtoType>(getTypePtr())->getNumArgs();
1080 ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; }
1081 void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; }
1083 TypeLoc getResultLoc() const {
1084 return getInnerTypeLoc();
1087 SourceRange getLocalSourceRange() const {
1088 return SourceRange(getLocalRangeBegin(), getLocalRangeEnd());
1091 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1092 setLocalRangeBegin(Loc);
1093 setLocalRangeEnd(Loc);
1094 setTrailingReturn(false);
1095 for (unsigned i = 0, e = getNumArgs(); i != e; ++i)
1099 /// \brief Returns the size of the type source info data block that is
1100 /// specific to this type.
1101 unsigned getExtraLocalDataSize() const {
1102 return getNumArgs() * sizeof(ParmVarDecl*);
1105 QualType getInnerType() const { return getTypePtr()->getResultType(); }
1108 class FunctionProtoTypeLoc :
1109 public InheritingConcreteTypeLoc<FunctionTypeLoc,
1110 FunctionProtoTypeLoc,
1111 FunctionProtoType> {
1114 class FunctionNoProtoTypeLoc :
1115 public InheritingConcreteTypeLoc<FunctionTypeLoc,
1116 FunctionNoProtoTypeLoc,
1117 FunctionNoProtoType> {
1121 struct ArrayLocInfo {
1122 SourceLocation LBracketLoc, RBracketLoc;
1126 /// \brief Wrapper for source info for arrays.
1127 class ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1132 SourceLocation getLBracketLoc() const {
1133 return getLocalData()->LBracketLoc;
1135 void setLBracketLoc(SourceLocation Loc) {
1136 getLocalData()->LBracketLoc = Loc;
1139 SourceLocation getRBracketLoc() const {
1140 return getLocalData()->RBracketLoc;
1142 void setRBracketLoc(SourceLocation Loc) {
1143 getLocalData()->RBracketLoc = Loc;
1146 SourceRange getBracketsRange() const {
1147 return SourceRange(getLBracketLoc(), getRBracketLoc());
1150 Expr *getSizeExpr() const {
1151 return getLocalData()->Size;
1153 void setSizeExpr(Expr *Size) {
1154 getLocalData()->Size = Size;
1157 TypeLoc getElementLoc() const {
1158 return getInnerTypeLoc();
1161 SourceRange getLocalSourceRange() const {
1162 return SourceRange(getLBracketLoc(), getRBracketLoc());
1165 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1166 setLBracketLoc(Loc);
1167 setRBracketLoc(Loc);
1171 QualType getInnerType() const { return getTypePtr()->getElementType(); }
1174 class ConstantArrayTypeLoc :
1175 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1176 ConstantArrayTypeLoc,
1177 ConstantArrayType> {
1180 class IncompleteArrayTypeLoc :
1181 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1182 IncompleteArrayTypeLoc,
1183 IncompleteArrayType> {
1186 class DependentSizedArrayTypeLoc :
1187 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1188 DependentSizedArrayTypeLoc,
1189 DependentSizedArrayType> {
1193 class VariableArrayTypeLoc :
1194 public InheritingConcreteTypeLoc<ArrayTypeLoc,
1195 VariableArrayTypeLoc,
1196 VariableArrayType> {
1200 // Location information for a TemplateName. Rudimentary for now.
1201 struct TemplateNameLocInfo {
1202 SourceLocation NameLoc;
1205 struct TemplateSpecializationLocInfo : TemplateNameLocInfo {
1206 SourceLocation LAngleLoc;
1207 SourceLocation RAngleLoc;
1210 class TemplateSpecializationTypeLoc :
1211 public ConcreteTypeLoc<UnqualTypeLoc,
1212 TemplateSpecializationTypeLoc,
1213 TemplateSpecializationType,
1214 TemplateSpecializationLocInfo> {
1216 SourceLocation getLAngleLoc() const {
1217 return getLocalData()->LAngleLoc;
1219 void setLAngleLoc(SourceLocation Loc) {
1220 getLocalData()->LAngleLoc = Loc;
1223 SourceLocation getRAngleLoc() const {
1224 return getLocalData()->RAngleLoc;
1226 void setRAngleLoc(SourceLocation Loc) {
1227 getLocalData()->RAngleLoc = Loc;
1230 unsigned getNumArgs() const {
1231 return getTypePtr()->getNumArgs();
1233 void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
1234 getArgInfos()[i] = AI;
1236 TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
1237 return getArgInfos()[i];
1240 TemplateArgumentLoc getArgLoc(unsigned i) const {
1241 return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
1244 SourceLocation getTemplateNameLoc() const {
1245 return getLocalData()->NameLoc;
1247 void setTemplateNameLoc(SourceLocation Loc) {
1248 getLocalData()->NameLoc = Loc;
1251 /// \brief - Copy the location information from the given info.
1252 void copy(TemplateSpecializationTypeLoc Loc) {
1253 unsigned size = getFullDataSize();
1254 assert(size == Loc.getFullDataSize());
1256 // We're potentially copying Expr references here. We don't
1257 // bother retaining them because TypeSourceInfos live forever, so
1258 // as long as the Expr was retained when originally written into
1259 // the TypeLoc, we're okay.
1260 memcpy(Data, Loc.Data, size);
1263 SourceRange getLocalSourceRange() const {
1264 return SourceRange(getTemplateNameLoc(), getRAngleLoc());
1267 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1270 setTemplateNameLoc(Loc);
1271 initializeArgLocs(Context, getNumArgs(), getTypePtr()->getArgs(),
1272 getArgInfos(), Loc);
1275 static void initializeArgLocs(ASTContext &Context, unsigned NumArgs,
1276 const TemplateArgument *Args,
1277 TemplateArgumentLocInfo *ArgInfos,
1278 SourceLocation Loc);
1280 unsigned getExtraLocalDataSize() const {
1281 return getNumArgs() * sizeof(TemplateArgumentLocInfo);
1285 TemplateArgumentLocInfo *getArgInfos() const {
1286 return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
1290 //===----------------------------------------------------------------------===//
1292 // All of these need proper implementations.
1294 //===----------------------------------------------------------------------===//
1296 // FIXME: size expression and attribute locations (or keyword if we
1297 // ever fully support altivec syntax).
1298 class VectorTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1303 // FIXME: size expression and attribute locations.
1304 class ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc,
1309 // FIXME: attribute locations.
1310 // For some reason, this isn't a subtype of VectorType.
1311 class DependentSizedExtVectorTypeLoc :
1312 public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1313 DependentSizedExtVectorTypeLoc,
1314 DependentSizedExtVectorType> {
1317 // FIXME: location of the '_Complex' keyword.
1318 class ComplexTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1323 struct TypeofLocInfo {
1324 SourceLocation TypeofLoc;
1325 SourceLocation LParenLoc;
1326 SourceLocation RParenLoc;
1329 struct TypeOfExprTypeLocInfo : public TypeofLocInfo {
1332 struct TypeOfTypeLocInfo : public TypeofLocInfo {
1333 TypeSourceInfo* UnderlyingTInfo;
1336 template <class Derived, class TypeClass, class LocalData = TypeofLocInfo>
1337 class TypeofLikeTypeLoc
1338 : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> {
1340 SourceLocation getTypeofLoc() const {
1341 return this->getLocalData()->TypeofLoc;
1343 void setTypeofLoc(SourceLocation Loc) {
1344 this->getLocalData()->TypeofLoc = Loc;
1347 SourceLocation getLParenLoc() const {
1348 return this->getLocalData()->LParenLoc;
1350 void setLParenLoc(SourceLocation Loc) {
1351 this->getLocalData()->LParenLoc = Loc;
1354 SourceLocation getRParenLoc() const {
1355 return this->getLocalData()->RParenLoc;
1357 void setRParenLoc(SourceLocation Loc) {
1358 this->getLocalData()->RParenLoc = Loc;
1361 SourceRange getParensRange() const {
1362 return SourceRange(getLParenLoc(), getRParenLoc());
1364 void setParensRange(SourceRange range) {
1365 setLParenLoc(range.getBegin());
1366 setRParenLoc(range.getEnd());
1369 SourceRange getLocalSourceRange() const {
1370 return SourceRange(getTypeofLoc(), getRParenLoc());
1373 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1380 class TypeOfExprTypeLoc : public TypeofLikeTypeLoc<TypeOfExprTypeLoc,
1382 TypeOfExprTypeLocInfo> {
1384 Expr* getUnderlyingExpr() const {
1385 return getTypePtr()->getUnderlyingExpr();
1387 // Reimplemented to account for GNU/C++ extension
1388 // typeof unary-expression
1389 // where there are no parentheses.
1390 SourceRange getLocalSourceRange() const;
1394 : public TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo> {
1396 QualType getUnderlyingType() const {
1397 return this->getTypePtr()->getUnderlyingType();
1399 TypeSourceInfo* getUnderlyingTInfo() const {
1400 return this->getLocalData()->UnderlyingTInfo;
1402 void setUnderlyingTInfo(TypeSourceInfo* TI) const {
1403 this->getLocalData()->UnderlyingTInfo = TI;
1407 // FIXME: location of the 'decltype' and parens.
1408 class DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1413 struct UnaryTransformTypeLocInfo {
1414 // FIXME: While there's only one unary transform right now, future ones may
1415 // need different representations
1416 SourceLocation KWLoc, LParenLoc, RParenLoc;
1417 TypeSourceInfo *UnderlyingTInfo;
1420 class UnaryTransformTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1421 UnaryTransformTypeLoc,
1423 UnaryTransformTypeLocInfo> {
1425 SourceLocation getKWLoc() const { return getLocalData()->KWLoc; }
1426 void setKWLoc(SourceLocation Loc) { getLocalData()->KWLoc = Loc; }
1428 SourceLocation getLParenLoc() const { return getLocalData()->LParenLoc; }
1429 void setLParenLoc(SourceLocation Loc) { getLocalData()->LParenLoc = Loc; }
1431 SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
1432 void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
1434 TypeSourceInfo* getUnderlyingTInfo() const {
1435 return getLocalData()->UnderlyingTInfo;
1437 void setUnderlyingTInfo(TypeSourceInfo *TInfo) {
1438 getLocalData()->UnderlyingTInfo = TInfo;
1441 SourceRange getLocalSourceRange() const {
1442 return SourceRange(getKWLoc(), getRParenLoc());
1445 SourceRange getParensRange() const {
1446 return SourceRange(getLParenLoc(), getRParenLoc());
1448 void setParensRange(SourceRange Range) {
1449 setLParenLoc(Range.getBegin());
1450 setRParenLoc(Range.getEnd());
1453 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1460 class AutoTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1465 struct ElaboratedLocInfo {
1466 SourceLocation KeywordLoc;
1468 /// \brief Opaque data pointer used to reconstruct a nested-name-specifier
1470 void *QualifierData;
1473 class ElaboratedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1476 ElaboratedLocInfo> {
1478 SourceLocation getKeywordLoc() const {
1479 return this->getLocalData()->KeywordLoc;
1481 void setKeywordLoc(SourceLocation Loc) {
1482 this->getLocalData()->KeywordLoc = Loc;
1485 NestedNameSpecifierLoc getQualifierLoc() const {
1486 return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
1487 getLocalData()->QualifierData);
1490 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1491 assert(QualifierLoc.getNestedNameSpecifier()
1492 == getTypePtr()->getQualifier() &&
1493 "Inconsistent nested-name-specifier pointer");
1494 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1497 SourceRange getLocalSourceRange() const {
1498 if (getKeywordLoc().isValid())
1499 if (getQualifierLoc())
1500 return SourceRange(getKeywordLoc(), getQualifierLoc().getEndLoc());
1502 return SourceRange(getKeywordLoc());
1504 return getQualifierLoc().getSourceRange();
1507 void initializeLocal(ASTContext &Context, SourceLocation Loc);
1509 TypeLoc getNamedTypeLoc() const {
1510 return getInnerTypeLoc();
1513 QualType getInnerType() const {
1514 return getTypePtr()->getNamedType();
1517 void copy(ElaboratedTypeLoc Loc) {
1518 unsigned size = getFullDataSize();
1519 assert(size == Loc.getFullDataSize());
1520 memcpy(Data, Loc.Data, size);
1524 // This is exactly the structure of an ElaboratedTypeLoc whose inner
1525 // type is some sort of TypeDeclTypeLoc.
1526 struct DependentNameLocInfo : ElaboratedLocInfo {
1527 SourceLocation NameLoc;
1529 /// \brief Data associated with the nested-name-specifier location.
1530 void *QualifierData;
1533 class DependentNameTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1534 DependentNameTypeLoc,
1536 DependentNameLocInfo> {
1538 SourceLocation getKeywordLoc() const {
1539 return this->getLocalData()->KeywordLoc;
1541 void setKeywordLoc(SourceLocation Loc) {
1542 this->getLocalData()->KeywordLoc = Loc;
1545 NestedNameSpecifierLoc getQualifierLoc() const {
1546 return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
1547 getLocalData()->QualifierData);
1550 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1551 assert(QualifierLoc.getNestedNameSpecifier()
1552 == getTypePtr()->getQualifier() &&
1553 "Inconsistent nested-name-specifier pointer");
1554 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1557 SourceLocation getNameLoc() const {
1558 return this->getLocalData()->NameLoc;
1560 void setNameLoc(SourceLocation Loc) {
1561 this->getLocalData()->NameLoc = Loc;
1564 SourceRange getLocalSourceRange() const {
1565 if (getKeywordLoc().isValid())
1566 return SourceRange(getKeywordLoc(), getNameLoc());
1568 return SourceRange(getQualifierLoc().getBeginLoc(), getNameLoc());
1571 void copy(DependentNameTypeLoc Loc) {
1572 unsigned size = getFullDataSize();
1573 assert(size == Loc.getFullDataSize());
1574 memcpy(Data, Loc.Data, size);
1577 void initializeLocal(ASTContext &Context, SourceLocation Loc);
1580 struct DependentTemplateSpecializationLocInfo : DependentNameLocInfo {
1581 SourceLocation KeywordLoc;
1582 SourceLocation LAngleLoc;
1583 SourceLocation RAngleLoc;
1584 // followed by a TemplateArgumentLocInfo[]
1587 class DependentTemplateSpecializationTypeLoc :
1588 public ConcreteTypeLoc<UnqualTypeLoc,
1589 DependentTemplateSpecializationTypeLoc,
1590 DependentTemplateSpecializationType,
1591 DependentTemplateSpecializationLocInfo> {
1593 SourceLocation getKeywordLoc() const {
1594 return this->getLocalData()->KeywordLoc;
1596 void setKeywordLoc(SourceLocation Loc) {
1597 this->getLocalData()->KeywordLoc = Loc;
1600 NestedNameSpecifierLoc getQualifierLoc() const {
1601 if (!getLocalData()->QualifierData)
1602 return NestedNameSpecifierLoc();
1604 return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
1605 getLocalData()->QualifierData);
1608 void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1609 if (!QualifierLoc) {
1610 // Even if we have a nested-name-specifier in the dependent
1611 // template specialization type, we won't record the nested-name-specifier
1612 // location information when this type-source location information is
1613 // part of a nested-name-specifier.
1614 getLocalData()->QualifierData = 0;
1618 assert(QualifierLoc.getNestedNameSpecifier()
1619 == getTypePtr()->getQualifier() &&
1620 "Inconsistent nested-name-specifier pointer");
1621 getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1624 SourceLocation getNameLoc() const {
1625 return this->getLocalData()->NameLoc;
1627 void setNameLoc(SourceLocation Loc) {
1628 this->getLocalData()->NameLoc = Loc;
1631 SourceLocation getLAngleLoc() const {
1632 return this->getLocalData()->LAngleLoc;
1634 void setLAngleLoc(SourceLocation Loc) {
1635 this->getLocalData()->LAngleLoc = Loc;
1638 SourceLocation getRAngleLoc() const {
1639 return this->getLocalData()->RAngleLoc;
1641 void setRAngleLoc(SourceLocation Loc) {
1642 this->getLocalData()->RAngleLoc = Loc;
1645 unsigned getNumArgs() const {
1646 return getTypePtr()->getNumArgs();
1649 void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
1650 getArgInfos()[i] = AI;
1652 TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
1653 return getArgInfos()[i];
1656 TemplateArgumentLoc getArgLoc(unsigned i) const {
1657 return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
1660 SourceRange getLocalSourceRange() const {
1661 if (getKeywordLoc().isValid())
1662 return SourceRange(getKeywordLoc(), getRAngleLoc());
1663 else if (getQualifierLoc())
1664 return SourceRange(getQualifierLoc().getBeginLoc(), getRAngleLoc());
1666 return SourceRange(getNameLoc(), getRAngleLoc());
1669 void copy(DependentTemplateSpecializationTypeLoc Loc) {
1670 unsigned size = getFullDataSize();
1671 assert(size == Loc.getFullDataSize());
1672 memcpy(Data, Loc.Data, size);
1675 void initializeLocal(ASTContext &Context, SourceLocation Loc);
1677 unsigned getExtraLocalDataSize() const {
1678 return getNumArgs() * sizeof(TemplateArgumentLocInfo);
1682 TemplateArgumentLocInfo *getArgInfos() const {
1683 return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
1688 struct PackExpansionTypeLocInfo {
1689 SourceLocation EllipsisLoc;
1692 class PackExpansionTypeLoc
1693 : public ConcreteTypeLoc<UnqualTypeLoc, PackExpansionTypeLoc,
1694 PackExpansionType, PackExpansionTypeLocInfo> {
1696 SourceLocation getEllipsisLoc() const {
1697 return this->getLocalData()->EllipsisLoc;
1700 void setEllipsisLoc(SourceLocation Loc) {
1701 this->getLocalData()->EllipsisLoc = Loc;
1704 SourceRange getLocalSourceRange() const {
1705 return SourceRange(getEllipsisLoc(), getEllipsisLoc());
1708 void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1709 setEllipsisLoc(Loc);
1712 TypeLoc getPatternLoc() const {
1713 return getInnerTypeLoc();
1716 QualType getInnerType() const {
1717 return this->getTypePtr()->getPattern();