TypeLoc.h revision 54e14c4db764c0636160d26c5bbf491637c83a76
1b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//===--- TypeLoc.h - Type Source Info Wrapper -------------------*- C++ -*-===// 2b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// 3b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// The LLVM Compiler Infrastructure 4b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// 5b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// This file is distributed under the University of Illinois Open Source 6b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// License. See LICENSE.TXT for details. 7b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// 8b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 9b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// 10b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// This file defines the TypeLoc interface and subclasses. 11b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// 12b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 13b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 14b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#ifndef LLVM_CLANG_AST_TYPELOC_H 15b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#define LLVM_CLANG_AST_TYPELOC_H 16b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 17b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#include "clang/AST/Type.h" 18b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 19b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisnamespace clang { 20b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis class ParmVarDecl; 21b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis class DeclaratorInfo; 2234a0447b8072e0da14c0980597da9d03a1495662John McCall class UnqualTypeLoc; 23b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 2451bd803fbdade51d674598ed45da3d54190a656cJohn McCall// Predeclare all the type nodes. 2551bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPELOC(Class, Base) 2651bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define TYPELOC(Class, Base) \ 2751bd803fbdade51d674598ed45da3d54190a656cJohn McCall class Class##TypeLoc; 2851bd803fbdade51d674598ed45da3d54190a656cJohn McCall#include "clang/AST/TypeLocNodes.def" 2951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 30b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Base wrapper for a particular "section" of type source info. 31b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// 32b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// A client should use the TypeLoc subclasses through cast/dyn_cast in order to 33b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// get at the actual information. 34b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisclass TypeLoc { 35b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisprotected: 3634a0447b8072e0da14c0980597da9d03a1495662John McCall // The correctness of this relies on the property that, for Type *Ty, 3734a0447b8072e0da14c0980597da9d03a1495662John McCall // QualType(Ty, 0).getAsOpaquePtr() == (void*) Ty 3834a0447b8072e0da14c0980597da9d03a1495662John McCall void *Ty; 39b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void *Data; 401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 4251bd803fbdade51d674598ed45da3d54190a656cJohn McCall /// The kinds of TypeLocs. Equivalent to the Type::TypeClass enum, 4351bd803fbdade51d674598ed45da3d54190a656cJohn McCall /// except it also defines a Qualified enum that corresponds to the 4451bd803fbdade51d674598ed45da3d54190a656cJohn McCall /// QualifiedLoc class. 4551bd803fbdade51d674598ed45da3d54190a656cJohn McCall enum TypeLocClass { 4651bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPE(Class, Base) 4751bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define TYPE(Class, Base) \ 4851bd803fbdade51d674598ed45da3d54190a656cJohn McCall Class = Type::Class, 4951bd803fbdade51d674598ed45da3d54190a656cJohn McCall#include "clang/AST/TypeNodes.def" 5051bd803fbdade51d674598ed45da3d54190a656cJohn McCall Qualified 5151bd803fbdade51d674598ed45da3d54190a656cJohn McCall }; 5251bd803fbdade51d674598ed45da3d54190a656cJohn McCall 5334a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc() : Ty(0), Data(0) { } 5434a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc(QualType ty, void *opaqueData) 5534a0447b8072e0da14c0980597da9d03a1495662John McCall : Ty(ty.getAsOpaquePtr()), Data(opaqueData) { } 5634a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc(Type *ty, void *opaqueData) 5734a0447b8072e0da14c0980597da9d03a1495662John McCall : Ty(ty), Data(opaqueData) { } 58b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 5951bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeLocClass getTypeLocClass() const { 6051bd803fbdade51d674598ed45da3d54190a656cJohn McCall if (getType().hasQualifiers()) return Qualified; 6151bd803fbdade51d674598ed45da3d54190a656cJohn McCall return (TypeLocClass) getType()->getTypeClass(); 6251bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 6351bd803fbdade51d674598ed45da3d54190a656cJohn McCall 6434a0447b8072e0da14c0980597da9d03a1495662John McCall bool isNull() const { return !Ty; } 6534a0447b8072e0da14c0980597da9d03a1495662John McCall operator bool() const { return Ty; } 66b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 67b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of type source info data block for the given type. 68b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis static unsigned getFullDataSizeForType(QualType Ty); 69b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 70b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Get the type for which this source info wrapper provides 71b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// information. 7251bd803fbdade51d674598ed45da3d54190a656cJohn McCall QualType getType() const { 7351bd803fbdade51d674598ed45da3d54190a656cJohn McCall return QualType::getFromOpaquePtr(Ty); 7451bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 7534a0447b8072e0da14c0980597da9d03a1495662John McCall 7651bd803fbdade51d674598ed45da3d54190a656cJohn McCall Type *getTypePtr() const { 7734a0447b8072e0da14c0980597da9d03a1495662John McCall return QualType::getFromOpaquePtr(Ty).getTypePtr(); 7834a0447b8072e0da14c0980597da9d03a1495662John McCall } 79b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 80b735471f3848065120d7210e557b5f0d37ed4c43Argyrios Kyrtzidis /// \brief Get the pointer where source information is stored. 8151bd803fbdade51d674598ed45da3d54190a656cJohn McCall void *getOpaqueData() const { 8251bd803fbdade51d674598ed45da3d54190a656cJohn McCall return Data; 8351bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 84b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 8551bd803fbdade51d674598ed45da3d54190a656cJohn McCall SourceRange getSourceRange() const { 8651bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSourceRangeImpl(*this); 8751bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 88b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 89b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of the type source info data block. 9034a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getFullDataSize() const { 9151bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getFullDataSizeForType(getType()); 9234a0447b8072e0da14c0980597da9d03a1495662John McCall } 93b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 94b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the 95b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// TypeLoc is a PointerLoc and next TypeLoc is for "int". 9651bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeLoc getNextTypeLoc() const { 9751bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getNextTypeLocImpl(*this); 9851bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 99b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 10034a0447b8072e0da14c0980597da9d03a1495662John McCall /// \brief Skips past any qualifiers, if this is qualified. 10151bd803fbdade51d674598ed45da3d54190a656cJohn McCall UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header 10234a0447b8072e0da14c0980597da9d03a1495662John McCall 1034ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// \brief Initializes this to state that every location in this 1044ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// type is the given location. 1054ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// 1064ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// This method exists to provide a simple transition for code that 1074ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// relies on location-less types. 1084ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall void initialize(SourceLocation Loc) const { 1094ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall initializeImpl(*this, Loc); 1104ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 1114ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 112b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) { 113b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data; 114b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 115b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 116b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis friend bool operator!=(const TypeLoc &LHS, const TypeLoc &RHS) { 117b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return !(LHS == RHS); 118b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 119b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 120b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis static bool classof(const TypeLoc *TL) { return true; } 1214ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 1224ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCallprivate: 1234ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall static void initializeImpl(TypeLoc TL, SourceLocation Loc); 12451bd803fbdade51d674598ed45da3d54190a656cJohn McCall static TypeLoc getNextTypeLocImpl(TypeLoc TL); 12551bd803fbdade51d674598ed45da3d54190a656cJohn McCall static SourceRange getSourceRangeImpl(TypeLoc TL); 126b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 127b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 12834a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with 12934a0447b8072e0da14c0980597da9d03a1495662John McCall/// no direct quqlaifiers. 13034a0447b8072e0da14c0980597da9d03a1495662John McCallclass UnqualTypeLoc : public TypeLoc { 13134a0447b8072e0da14c0980597da9d03a1495662John McCallpublic: 13234a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc() {} 13334a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc(Type *Ty, void *Data) : TypeLoc(Ty, Data) {} 13434a0447b8072e0da14c0980597da9d03a1495662John McCall 13551bd803fbdade51d674598ed45da3d54190a656cJohn McCall Type *getTypePtr() const { 13634a0447b8072e0da14c0980597da9d03a1495662John McCall return reinterpret_cast<Type*>(Ty); 13734a0447b8072e0da14c0980597da9d03a1495662John McCall } 13834a0447b8072e0da14c0980597da9d03a1495662John McCall 13951bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeLocClass getTypeLocClass() const { 14051bd803fbdade51d674598ed45da3d54190a656cJohn McCall return (TypeLocClass) getTypePtr()->getTypeClass(); 14151bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 14251bd803fbdade51d674598ed45da3d54190a656cJohn McCall 14334a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const TypeLoc *TL) { 14451bd803fbdade51d674598ed45da3d54190a656cJohn McCall return !TL->getType().hasQualifiers(); 14534a0447b8072e0da14c0980597da9d03a1495662John McCall } 14634a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const UnqualTypeLoc *TL) { return true; } 14734a0447b8072e0da14c0980597da9d03a1495662John McCall}; 14834a0447b8072e0da14c0980597da9d03a1495662John McCall 14934a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with 15034a0447b8072e0da14c0980597da9d03a1495662John McCall/// non-trivial direct qualifiers. 15134a0447b8072e0da14c0980597da9d03a1495662John McCall/// 15234a0447b8072e0da14c0980597da9d03a1495662John McCall/// Currently, we intentionally do not provide source location for 15334a0447b8072e0da14c0980597da9d03a1495662John McCall/// type qualifiers. 15451bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass QualifiedTypeLoc : public TypeLoc { 15534a0447b8072e0da14c0980597da9d03a1495662John McCallpublic: 15634a0447b8072e0da14c0980597da9d03a1495662John McCall SourceRange getSourceRange() const { 15734a0447b8072e0da14c0980597da9d03a1495662John McCall return SourceRange(); 15834a0447b8072e0da14c0980597da9d03a1495662John McCall } 15934a0447b8072e0da14c0980597da9d03a1495662John McCall 16034a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc getUnqualifiedLoc() const { 16151bd803fbdade51d674598ed45da3d54190a656cJohn McCall return UnqualTypeLoc(getTypePtr(), Data); 16234a0447b8072e0da14c0980597da9d03a1495662John McCall } 16334a0447b8072e0da14c0980597da9d03a1495662John McCall 1644ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// Initializes the local data of this type source info block to 1654ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// provide no information. 1664ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall void initializeLocal(SourceLocation Loc) { 1674ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall // do nothing 1684ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 1694ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 1704ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall TypeLoc getNextTypeLoc() const { 1714ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall return getUnqualifiedLoc(); 1724ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 1734ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 17434a0447b8072e0da14c0980597da9d03a1495662John McCall /// \brief Returns the size of the type source info data block that is 17534a0447b8072e0da14c0980597da9d03a1495662John McCall /// specific to this type. 17634a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getLocalDataSize() const { 17734a0447b8072e0da14c0980597da9d03a1495662John McCall // In fact, we don't currently preserve any location information 17834a0447b8072e0da14c0980597da9d03a1495662John McCall // for qualifiers. 17934a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 18034a0447b8072e0da14c0980597da9d03a1495662John McCall } 18134a0447b8072e0da14c0980597da9d03a1495662John McCall 18234a0447b8072e0da14c0980597da9d03a1495662John McCall /// \brief Returns the size of the type source info data block. 18334a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getFullDataSize() const { 18434a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalDataSize() + 18551bd803fbdade51d674598ed45da3d54190a656cJohn McCall getFullDataSizeForType(getType().getUnqualifiedType()); 18634a0447b8072e0da14c0980597da9d03a1495662John McCall } 18734a0447b8072e0da14c0980597da9d03a1495662John McCall 18834a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const TypeLoc *TL) { 18951bd803fbdade51d674598ed45da3d54190a656cJohn McCall return TL->getType().hasQualifiers(); 19034a0447b8072e0da14c0980597da9d03a1495662John McCall } 19151bd803fbdade51d674598ed45da3d54190a656cJohn McCall static bool classof(const QualifiedTypeLoc *TL) { return true; } 19234a0447b8072e0da14c0980597da9d03a1495662John McCall}; 19334a0447b8072e0da14c0980597da9d03a1495662John McCall 19434a0447b8072e0da14c0980597da9d03a1495662John McCallinline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const { 19551bd803fbdade51d674598ed45da3d54190a656cJohn McCall if (isa<QualifiedTypeLoc>(this)) 19651bd803fbdade51d674598ed45da3d54190a656cJohn McCall return cast<QualifiedTypeLoc>(this)->getUnqualifiedLoc(); 19734a0447b8072e0da14c0980597da9d03a1495662John McCall return cast<UnqualTypeLoc>(*this); 19834a0447b8072e0da14c0980597da9d03a1495662John McCall} 19934a0447b8072e0da14c0980597da9d03a1495662John McCall 20034a0447b8072e0da14c0980597da9d03a1495662John McCall/// A metaprogramming base class for TypeLoc classes which correspond 201f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// to a particular Type subclass. It is accepted for a single 202f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// TypeLoc class to correspond to multiple Type classes. 20334a0447b8072e0da14c0980597da9d03a1495662John McCall/// 20434a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param Base a class from which to derive 20534a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param Derived the class deriving from this one 206f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// \param TypeClass the concrete Type subclass associated with this 207f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// location type 20834a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param LocalData the structure type of local location data for 20934a0447b8072e0da14c0980597da9d03a1495662John McCall/// this type 21034a0447b8072e0da14c0980597da9d03a1495662John McCall/// 21134a0447b8072e0da14c0980597da9d03a1495662John McCall/// sizeof(LocalData) needs to be a multiple of sizeof(void*) or 21234a0447b8072e0da14c0980597da9d03a1495662John McCall/// else the world will end. 21334a0447b8072e0da14c0980597da9d03a1495662John McCall/// 21434a0447b8072e0da14c0980597da9d03a1495662John McCall/// TypeLocs with non-constant amounts of local data should override 21534a0447b8072e0da14c0980597da9d03a1495662John McCall/// getExtraLocalDataSize(); getExtraLocalData() will then point to 21634a0447b8072e0da14c0980597da9d03a1495662John McCall/// this extra memory. 21734a0447b8072e0da14c0980597da9d03a1495662John McCall/// 218a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// TypeLocs with an inner type should define 219a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// QualType getInnerType() const 220a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// and getInnerTypeLoc() will then point to this inner type's 221a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// location data. 22251bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// 22351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A word about hierarchies: this template is not designed to be 22451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// derived from multiple times in a hierarchy. It is also not 22551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// designed to be used for classes where subtypes might provide 22651bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// different amounts of source information. It should be subclassed 22751bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// only at the deepest portion of the hierarchy where all children 22851bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// have identical source information; if that's an abstract type, 22951bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// then further descendents should inherit from 23051bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// InheritingConcreteTypeLoc instead. 23134a0447b8072e0da14c0980597da9d03a1495662John McCalltemplate <class Base, class Derived, class TypeClass, class LocalData> 23234a0447b8072e0da14c0980597da9d03a1495662John McCallclass ConcreteTypeLoc : public Base { 23334a0447b8072e0da14c0980597da9d03a1495662John McCall 23434a0447b8072e0da14c0980597da9d03a1495662John McCall const Derived *asDerived() const { 23534a0447b8072e0da14c0980597da9d03a1495662John McCall return static_cast<const Derived*>(this); 23634a0447b8072e0da14c0980597da9d03a1495662John McCall } 23734a0447b8072e0da14c0980597da9d03a1495662John McCall 23834a0447b8072e0da14c0980597da9d03a1495662John McCallpublic: 23934a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getLocalDataSize() const { 24034a0447b8072e0da14c0980597da9d03a1495662John McCall return sizeof(LocalData) + asDerived()->getExtraLocalDataSize(); 24134a0447b8072e0da14c0980597da9d03a1495662John McCall } 24234a0447b8072e0da14c0980597da9d03a1495662John McCall // Give a default implementation that's useful for leaf types. 24334a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getFullDataSize() const { 24434a0447b8072e0da14c0980597da9d03a1495662John McCall return asDerived()->getLocalDataSize() + getInnerTypeSize(); 24534a0447b8072e0da14c0980597da9d03a1495662John McCall } 24634a0447b8072e0da14c0980597da9d03a1495662John McCall 24734a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classofType(const Type *Ty) { 24834a0447b8072e0da14c0980597da9d03a1495662John McCall return TypeClass::classof(Ty); 24934a0447b8072e0da14c0980597da9d03a1495662John McCall } 25034a0447b8072e0da14c0980597da9d03a1495662John McCall 2514ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall TypeLoc getNextTypeLoc() const { 2524ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall return getNextTypeLoc(asDerived()->getInnerType()); 2534ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 2544ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 25534a0447b8072e0da14c0980597da9d03a1495662John McCall TypeClass *getTypePtr() const { 25651bd803fbdade51d674598ed45da3d54190a656cJohn McCall return cast<TypeClass>(Base::getTypePtr()); 25734a0447b8072e0da14c0980597da9d03a1495662John McCall } 25834a0447b8072e0da14c0980597da9d03a1495662John McCall 25951bd803fbdade51d674598ed45da3d54190a656cJohn McCallprotected: 26034a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 26134a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 26234a0447b8072e0da14c0980597da9d03a1495662John McCall } 26334a0447b8072e0da14c0980597da9d03a1495662John McCall 26434a0447b8072e0da14c0980597da9d03a1495662John McCall LocalData *getLocalData() const { 26534a0447b8072e0da14c0980597da9d03a1495662John McCall return static_cast<LocalData*>(Base::Data); 26634a0447b8072e0da14c0980597da9d03a1495662John McCall } 26734a0447b8072e0da14c0980597da9d03a1495662John McCall 26834a0447b8072e0da14c0980597da9d03a1495662John McCall /// Gets a pointer past the Info structure; useful for classes with 26934a0447b8072e0da14c0980597da9d03a1495662John McCall /// local data that can't be captured in the Info (e.g. because it's 27034a0447b8072e0da14c0980597da9d03a1495662John McCall /// of variable size). 27134a0447b8072e0da14c0980597da9d03a1495662John McCall void *getExtraLocalData() const { 27234a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData() + 1; 27334a0447b8072e0da14c0980597da9d03a1495662John McCall } 27434a0447b8072e0da14c0980597da9d03a1495662John McCall 27534a0447b8072e0da14c0980597da9d03a1495662John McCall void *getNonLocalData() const { 27634a0447b8072e0da14c0980597da9d03a1495662John McCall return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize(); 27734a0447b8072e0da14c0980597da9d03a1495662John McCall } 27834a0447b8072e0da14c0980597da9d03a1495662John McCall 279a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall struct HasNoInnerType {}; 280a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall HasNoInnerType getInnerType() const { return HasNoInnerType(); } 28134a0447b8072e0da14c0980597da9d03a1495662John McCall 28234a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc getInnerTypeLoc() const { 28334a0447b8072e0da14c0980597da9d03a1495662John McCall return TypeLoc(asDerived()->getInnerType(), getNonLocalData()); 28434a0447b8072e0da14c0980597da9d03a1495662John McCall } 28534a0447b8072e0da14c0980597da9d03a1495662John McCall 28634a0447b8072e0da14c0980597da9d03a1495662John McCallprivate: 28734a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getInnerTypeSize() const { 288a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall return getInnerTypeSize(asDerived()->getInnerType()); 289a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall } 290a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall 291a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall unsigned getInnerTypeSize(HasNoInnerType _) const { 29234a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 29334a0447b8072e0da14c0980597da9d03a1495662John McCall } 29434a0447b8072e0da14c0980597da9d03a1495662John McCall 295a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall unsigned getInnerTypeSize(QualType _) const { 296a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall return getInnerTypeLoc().getFullDataSize(); 29734a0447b8072e0da14c0980597da9d03a1495662John McCall } 2984ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 2994ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall TypeLoc getNextTypeLoc(HasNoInnerType _) const { 3004ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall return TypeLoc(); 3014ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 3024ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 3034ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall TypeLoc getNextTypeLoc(QualType T) const { 3044ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall return TypeLoc(T, getNonLocalData()); 3054ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 30634a0447b8072e0da14c0980597da9d03a1495662John McCall}; 30734a0447b8072e0da14c0980597da9d03a1495662John McCall 30851bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A metaprogramming class designed for concrete subtypes of abstract 30951bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// types where all subtypes share equivalently-structured source 31051bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// information. See the note on ConcreteTypeLoc. 31151bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Base, class Derived, class TypeClass> 31251bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass InheritingConcreteTypeLoc : public Base { 313b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 31451bd803fbdade51d674598ed45da3d54190a656cJohn McCall static bool classof(const TypeLoc *TL) { 31551bd803fbdade51d674598ed45da3d54190a656cJohn McCall return Derived::classofType(TL->getTypePtr()); 316b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 31751bd803fbdade51d674598ed45da3d54190a656cJohn McCall static bool classof(const UnqualTypeLoc *TL) { 31851bd803fbdade51d674598ed45da3d54190a656cJohn McCall return Derived::classofType(TL->getTypePtr()); 319b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 32051bd803fbdade51d674598ed45da3d54190a656cJohn McCall static bool classof(const Derived *TL) { 32151bd803fbdade51d674598ed45da3d54190a656cJohn McCall return true; 322b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 323b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 32451bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeClass *getTypePtr() const { 32551bd803fbdade51d674598ed45da3d54190a656cJohn McCall return cast<TypeClass>(Base::getTypePtr()); 3264ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 32734a0447b8072e0da14c0980597da9d03a1495662John McCall}; 328b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 32951bd803fbdade51d674598ed45da3d54190a656cJohn McCallstruct TypeSpecLocInfo { 33034a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation NameLoc; 331b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 332b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 33351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief A reasonable base class for TypeLocs that correspond to 33451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// types that are written as a type-specifier. 33551bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Derived, class TypeClass, class LocalData = TypeSpecLocInfo> 33651bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass TypeSpecTypeLoc 33751bd803fbdade51d674598ed45da3d54190a656cJohn McCall : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> { 338b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 339b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getNameLoc() const { 34051bd803fbdade51d674598ed45da3d54190a656cJohn McCall return this->getLocalData()->NameLoc; 341b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 342b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setNameLoc(SourceLocation Loc) { 34351bd803fbdade51d674598ed45da3d54190a656cJohn McCall this->getLocalData()->NameLoc = Loc; 344b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 345b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 346b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getNameLoc(), getNameLoc()); 347b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 3484ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall void initializeLocal(SourceLocation Loc) { 3494ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setNameLoc(Loc); 3504ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 35151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 3524ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 35351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for typedefs. 35451bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass TypedefTypeLoc : public TypeSpecTypeLoc<TypedefTypeLoc,TypedefType> { 35551bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic: 3569036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis TypedefDecl *getTypedefDecl() const { 35734a0447b8072e0da14c0980597da9d03a1495662John McCall return getTypePtr()->getDecl(); 3589036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis } 35934a0447b8072e0da14c0980597da9d03a1495662John McCall}; 3609036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis 361b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 36251bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for builtin types. 36351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass BuiltinTypeLoc : public TypeSpecTypeLoc<BuiltinTypeLoc, 36451bd803fbdade51d674598ed45da3d54190a656cJohn McCall BuiltinType> { 365b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 366b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 36749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Wrapper for template type parameters. 36849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass TemplateTypeParmTypeLoc : public TypeSpecTypeLoc<TemplateTypeParmTypeLoc, 36949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall TemplateTypeParmType> { 37049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 37149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 37249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Wrapper for substituted template type parameters. 37349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmTypeLoc : 37449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall public TypeSpecTypeLoc<SubstTemplateTypeParmTypeLoc, 37549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType> { 37649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 37751bd803fbdade51d674598ed45da3d54190a656cJohn McCall 378eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 37934a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ObjCProtocolListLocInfo { 38054e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation LAngleLoc; 38154e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation RAngleLoc; 382eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis}; 383eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 38454e14c4db764c0636160d26c5bbf491637c83a76John McCall// A helper class for defining ObjC TypeLocs that can qualified with 38554e14c4db764c0636160d26c5bbf491637c83a76John McCall// protocols. 38654e14c4db764c0636160d26c5bbf491637c83a76John McCall// 38754e14c4db764c0636160d26c5bbf491637c83a76John McCall// TypeClass basically has to be either ObjCInterfaceType or 38854e14c4db764c0636160d26c5bbf491637c83a76John McCall// ObjCObjectPointerType. 38954e14c4db764c0636160d26c5bbf491637c83a76John McCalltemplate <class Derived, class TypeClass, class LocalData> 39054e14c4db764c0636160d26c5bbf491637c83a76John McCallclass ObjCProtocolListTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 39154e14c4db764c0636160d26c5bbf491637c83a76John McCall Derived, 39254e14c4db764c0636160d26c5bbf491637c83a76John McCall TypeClass, 39354e14c4db764c0636160d26c5bbf491637c83a76John McCall LocalData> { 394f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis // SourceLocations are stored after Info, one for each Protocol. 395f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation *getProtocolLocArray() const { 39654e14c4db764c0636160d26c5bbf491637c83a76John McCall return (SourceLocation*) this->getExtraLocalData(); 39754e14c4db764c0636160d26c5bbf491637c83a76John McCall } 39854e14c4db764c0636160d26c5bbf491637c83a76John McCall 39954e14c4db764c0636160d26c5bbf491637c83a76John McCallprotected: 40054e14c4db764c0636160d26c5bbf491637c83a76John McCall void initializeLocalBase(SourceLocation Loc) { 40154e14c4db764c0636160d26c5bbf491637c83a76John McCall setLAngleLoc(Loc); 40254e14c4db764c0636160d26c5bbf491637c83a76John McCall setRAngleLoc(Loc); 40354e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 0, e = getNumProtocols(); i != e; ++i) 40454e14c4db764c0636160d26c5bbf491637c83a76John McCall setProtocolLoc(i, Loc); 405f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 406f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 407f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidispublic: 408f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getLAngleLoc() const { 40954e14c4db764c0636160d26c5bbf491637c83a76John McCall return this->getLocalData()->LAngleLoc; 410f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 411f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setLAngleLoc(SourceLocation Loc) { 41254e14c4db764c0636160d26c5bbf491637c83a76John McCall this->getLocalData()->LAngleLoc = Loc; 413f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 414f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 415f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getRAngleLoc() const { 41654e14c4db764c0636160d26c5bbf491637c83a76John McCall return this->getLocalData()->RAngleLoc; 417f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 418f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setRAngleLoc(SourceLocation Loc) { 41954e14c4db764c0636160d26c5bbf491637c83a76John McCall this->getLocalData()->RAngleLoc = Loc; 420f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 421f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 422f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis unsigned getNumProtocols() const { 42354e14c4db764c0636160d26c5bbf491637c83a76John McCall return this->getTypePtr()->getNumProtocols(); 424f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 425f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 426f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getProtocolLoc(unsigned i) const { 427f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 428f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis return getProtocolLocArray()[i]; 429f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 430f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setProtocolLoc(unsigned i, SourceLocation Loc) { 431f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 432f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis getProtocolLocArray()[i] = Loc; 433f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 434f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 435f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis ObjCProtocolDecl *getProtocol(unsigned i) const { 436f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 43754e14c4db764c0636160d26c5bbf491637c83a76John McCall return *(this->getTypePtr()->qual_begin() + i); 438f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 439f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 440f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceRange getSourceRange() const { 441f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis return SourceRange(getLAngleLoc(), getRAngleLoc()); 442f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 443f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 4444ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall void initializeLocal(SourceLocation Loc) { 44554e14c4db764c0636160d26c5bbf491637c83a76John McCall initializeLocalBase(Loc); 4464ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 4474ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 44834a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 44954e14c4db764c0636160d26c5bbf491637c83a76John McCall return this->getNumProtocols() * sizeof(SourceLocation); 45054e14c4db764c0636160d26c5bbf491637c83a76John McCall } 45154e14c4db764c0636160d26c5bbf491637c83a76John McCall}; 45254e14c4db764c0636160d26c5bbf491637c83a76John McCall 45354e14c4db764c0636160d26c5bbf491637c83a76John McCall 45454e14c4db764c0636160d26c5bbf491637c83a76John McCallstruct ObjCInterfaceLocInfo : ObjCProtocolListLocInfo { 45554e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation NameLoc; 45654e14c4db764c0636160d26c5bbf491637c83a76John McCall}; 45754e14c4db764c0636160d26c5bbf491637c83a76John McCall 45854e14c4db764c0636160d26c5bbf491637c83a76John McCall/// \brief Wrapper for source info for ObjC interfaces. 45954e14c4db764c0636160d26c5bbf491637c83a76John McCallclass ObjCInterfaceTypeLoc : 46054e14c4db764c0636160d26c5bbf491637c83a76John McCall public ObjCProtocolListTypeLoc<ObjCInterfaceTypeLoc, 46154e14c4db764c0636160d26c5bbf491637c83a76John McCall ObjCInterfaceType, 46254e14c4db764c0636160d26c5bbf491637c83a76John McCall ObjCInterfaceLocInfo> { 46354e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic: 46454e14c4db764c0636160d26c5bbf491637c83a76John McCall ObjCInterfaceDecl *getIFaceDecl() const { 46554e14c4db764c0636160d26c5bbf491637c83a76John McCall return getTypePtr()->getDecl(); 46654e14c4db764c0636160d26c5bbf491637c83a76John McCall } 46754e14c4db764c0636160d26c5bbf491637c83a76John McCall 46854e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation getNameLoc() const { 46954e14c4db764c0636160d26c5bbf491637c83a76John McCall return getLocalData()->NameLoc; 47054e14c4db764c0636160d26c5bbf491637c83a76John McCall } 47154e14c4db764c0636160d26c5bbf491637c83a76John McCall 47254e14c4db764c0636160d26c5bbf491637c83a76John McCall void setNameLoc(SourceLocation Loc) { 47354e14c4db764c0636160d26c5bbf491637c83a76John McCall getLocalData()->NameLoc = Loc; 47454e14c4db764c0636160d26c5bbf491637c83a76John McCall } 47554e14c4db764c0636160d26c5bbf491637c83a76John McCall 47654e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceRange getSourceRange() const { 47754e14c4db764c0636160d26c5bbf491637c83a76John McCall if (getNumProtocols()) 47854e14c4db764c0636160d26c5bbf491637c83a76John McCall return SourceRange(getNameLoc(), getRAngleLoc()); 47954e14c4db764c0636160d26c5bbf491637c83a76John McCall else 48054e14c4db764c0636160d26c5bbf491637c83a76John McCall return SourceRange(getNameLoc(), getNameLoc()); 48154e14c4db764c0636160d26c5bbf491637c83a76John McCall } 48254e14c4db764c0636160d26c5bbf491637c83a76John McCall 48354e14c4db764c0636160d26c5bbf491637c83a76John McCall void initializeLocal(SourceLocation Loc) { 48454e14c4db764c0636160d26c5bbf491637c83a76John McCall initializeLocalBase(Loc); 48554e14c4db764c0636160d26c5bbf491637c83a76John McCall setNameLoc(Loc); 486f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 48754e14c4db764c0636160d26c5bbf491637c83a76John McCall}; 48854e14c4db764c0636160d26c5bbf491637c83a76John McCall 489f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 49054e14c4db764c0636160d26c5bbf491637c83a76John McCallstruct ObjCObjectPointerLocInfo : ObjCProtocolListLocInfo { 49154e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation StarLoc; 49254e14c4db764c0636160d26c5bbf491637c83a76John McCall bool HasProtocols; 49354e14c4db764c0636160d26c5bbf491637c83a76John McCall bool HasBaseType; 49434a0447b8072e0da14c0980597da9d03a1495662John McCall}; 495f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 49654e14c4db764c0636160d26c5bbf491637c83a76John McCall/// Wraps an ObjCPointerType with source location information. Note 49754e14c4db764c0636160d26c5bbf491637c83a76John McCall/// that not all ObjCPointerTypes actually have a star location; nor 49854e14c4db764c0636160d26c5bbf491637c83a76John McCall/// are protocol locations necessarily written in the source just 49954e14c4db764c0636160d26c5bbf491637c83a76John McCall/// because they're present on the type. 50054e14c4db764c0636160d26c5bbf491637c83a76John McCallclass ObjCObjectPointerTypeLoc : 50154e14c4db764c0636160d26c5bbf491637c83a76John McCall public ObjCProtocolListTypeLoc<ObjCObjectPointerTypeLoc, 50254e14c4db764c0636160d26c5bbf491637c83a76John McCall ObjCObjectPointerType, 50354e14c4db764c0636160d26c5bbf491637c83a76John McCall ObjCObjectPointerLocInfo> { 50454e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic: 50554e14c4db764c0636160d26c5bbf491637c83a76John McCall bool hasProtocolsAsWritten() const { 50654e14c4db764c0636160d26c5bbf491637c83a76John McCall return getLocalData()->HasProtocols; 50754e14c4db764c0636160d26c5bbf491637c83a76John McCall } 50854e14c4db764c0636160d26c5bbf491637c83a76John McCall 50954e14c4db764c0636160d26c5bbf491637c83a76John McCall void setHasProtocolsAsWritten(bool HasProtocols) { 51054e14c4db764c0636160d26c5bbf491637c83a76John McCall getLocalData()->HasProtocols = HasProtocols; 51154e14c4db764c0636160d26c5bbf491637c83a76John McCall } 51254e14c4db764c0636160d26c5bbf491637c83a76John McCall 51354e14c4db764c0636160d26c5bbf491637c83a76John McCall bool hasBaseTypeAsWritten() const { 51454e14c4db764c0636160d26c5bbf491637c83a76John McCall return getLocalData()->HasBaseType; 51554e14c4db764c0636160d26c5bbf491637c83a76John McCall } 51654e14c4db764c0636160d26c5bbf491637c83a76John McCall 51754e14c4db764c0636160d26c5bbf491637c83a76John McCall void setHasBaseTypeAsWritten(bool HasBaseType) { 51854e14c4db764c0636160d26c5bbf491637c83a76John McCall getLocalData()->HasBaseType = HasBaseType; 51954e14c4db764c0636160d26c5bbf491637c83a76John McCall } 52054e14c4db764c0636160d26c5bbf491637c83a76John McCall 52154e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation getStarLoc() const { 52254e14c4db764c0636160d26c5bbf491637c83a76John McCall return getLocalData()->StarLoc; 52354e14c4db764c0636160d26c5bbf491637c83a76John McCall } 52454e14c4db764c0636160d26c5bbf491637c83a76John McCall 52554e14c4db764c0636160d26c5bbf491637c83a76John McCall void setStarLoc(SourceLocation Loc) { 52654e14c4db764c0636160d26c5bbf491637c83a76John McCall getLocalData()->StarLoc = Loc; 52754e14c4db764c0636160d26c5bbf491637c83a76John McCall } 52854e14c4db764c0636160d26c5bbf491637c83a76John McCall 52954e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceRange getSourceRange() const { 53054e14c4db764c0636160d26c5bbf491637c83a76John McCall // Being written with protocols is incompatible with being written 53154e14c4db764c0636160d26c5bbf491637c83a76John McCall // with a star. 53254e14c4db764c0636160d26c5bbf491637c83a76John McCall if (hasProtocolsAsWritten()) 53354e14c4db764c0636160d26c5bbf491637c83a76John McCall return SourceRange(getLAngleLoc(), getRAngleLoc()); 53454e14c4db764c0636160d26c5bbf491637c83a76John McCall else 53554e14c4db764c0636160d26c5bbf491637c83a76John McCall return SourceRange(getStarLoc(), getStarLoc()); 53654e14c4db764c0636160d26c5bbf491637c83a76John McCall } 53754e14c4db764c0636160d26c5bbf491637c83a76John McCall 53854e14c4db764c0636160d26c5bbf491637c83a76John McCall void initializeLocal(SourceLocation Loc) { 53954e14c4db764c0636160d26c5bbf491637c83a76John McCall initializeLocalBase(Loc); 54054e14c4db764c0636160d26c5bbf491637c83a76John McCall setHasProtocolsAsWritten(false); 54154e14c4db764c0636160d26c5bbf491637c83a76John McCall setHasBaseTypeAsWritten(false); 54254e14c4db764c0636160d26c5bbf491637c83a76John McCall setStarLoc(Loc); 54354e14c4db764c0636160d26c5bbf491637c83a76John McCall } 54454e14c4db764c0636160d26c5bbf491637c83a76John McCall 54554e14c4db764c0636160d26c5bbf491637c83a76John McCall TypeLoc getBaseTypeLoc() const { 54654e14c4db764c0636160d26c5bbf491637c83a76John McCall return getInnerTypeLoc(); 54754e14c4db764c0636160d26c5bbf491637c83a76John McCall } 54854e14c4db764c0636160d26c5bbf491637c83a76John McCall 54954e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getInnerType() const { 55054e14c4db764c0636160d26c5bbf491637c83a76John McCall return getTypePtr()->getPointeeType(); 55154e14c4db764c0636160d26c5bbf491637c83a76John McCall } 55254e14c4db764c0636160d26c5bbf491637c83a76John McCall}; 55334a0447b8072e0da14c0980597da9d03a1495662John McCall 55451bd803fbdade51d674598ed45da3d54190a656cJohn McCall 55551bd803fbdade51d674598ed45da3d54190a656cJohn McCallstruct PointerLikeLocInfo { 55634a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation StarLoc; 557f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis}; 558f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 55951bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A base class for 56051bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo> 56151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived, 56251bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeClass, LocalData> { 563bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallpublic: 56451bd803fbdade51d674598ed45da3d54190a656cJohn McCall SourceLocation getSigilLoc() const { 56551bd803fbdade51d674598ed45da3d54190a656cJohn McCall return this->getLocalData()->StarLoc; 566b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 56751bd803fbdade51d674598ed45da3d54190a656cJohn McCall void setSigilLoc(SourceLocation Loc) { 56851bd803fbdade51d674598ed45da3d54190a656cJohn McCall this->getLocalData()->StarLoc = Loc; 569b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 570b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 571b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getPointeeLoc() const { 57251bd803fbdade51d674598ed45da3d54190a656cJohn McCall return this->getInnerTypeLoc(); 573b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 574b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 575b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 57651bd803fbdade51d674598ed45da3d54190a656cJohn McCall return SourceRange(getSigilLoc(), getSigilLoc()); 577b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 578b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 5794ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall void initializeLocal(SourceLocation Loc) { 58051bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 5814ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 5824ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 58351bd803fbdade51d674598ed45da3d54190a656cJohn McCall QualType getInnerType() const { 58451bd803fbdade51d674598ed45da3d54190a656cJohn McCall return this->getTypePtr()->getPointeeType(); 58551bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 58634a0447b8072e0da14c0980597da9d03a1495662John McCall}; 587b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 588b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 58951bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for pointers. 59051bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc, 59151bd803fbdade51d674598ed45da3d54190a656cJohn McCall PointerType> { 59251bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic: 59351bd803fbdade51d674598ed45da3d54190a656cJohn McCall SourceLocation getStarLoc() const { 59451bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 59551bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 59651bd803fbdade51d674598ed45da3d54190a656cJohn McCall void setStarLoc(SourceLocation Loc) { 59751bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 59851bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 599b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 600b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 60151bd803fbdade51d674598ed45da3d54190a656cJohn McCall 602b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for block pointers. 60351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc, 60451bd803fbdade51d674598ed45da3d54190a656cJohn McCall BlockPointerType> { 605b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 606b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getCaretLoc() const { 60751bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 608b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 609b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setCaretLoc(SourceLocation Loc) { 61051bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 611b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 61234a0447b8072e0da14c0980597da9d03a1495662John McCall}; 613b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 614b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 615b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for member pointers. 61651bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc, 61751bd803fbdade51d674598ed45da3d54190a656cJohn McCall MemberPointerType> { 618b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 619b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getStarLoc() const { 62051bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 621b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 622b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setStarLoc(SourceLocation Loc) { 62351bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 6244ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 62534a0447b8072e0da14c0980597da9d03a1495662John McCall}; 626b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 627b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 62851bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc, 62951bd803fbdade51d674598ed45da3d54190a656cJohn McCall ReferenceType> { 63054e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic: 63154e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getInnerType() const { 63254e14c4db764c0636160d26c5bbf491637c83a76John McCall return getTypePtr()->getPointeeTypeAsWritten(); 63354e14c4db764c0636160d26c5bbf491637c83a76John McCall } 634b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 635b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 636bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallclass LValueReferenceTypeLoc : 637bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall public InheritingConcreteTypeLoc<ReferenceTypeLoc, 638bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall LValueReferenceTypeLoc, 639bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall LValueReferenceType> { 640b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 641b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getAmpLoc() const { 64251bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 643b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 644b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setAmpLoc(SourceLocation Loc) { 64551bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 646b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 64751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 648b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 649bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallclass RValueReferenceTypeLoc : 650bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall public InheritingConcreteTypeLoc<ReferenceTypeLoc, 651bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall RValueReferenceTypeLoc, 652bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall RValueReferenceType> { 65351bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic: 65451bd803fbdade51d674598ed45da3d54190a656cJohn McCall SourceLocation getAmpAmpLoc() const { 65551bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 656b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 65751bd803fbdade51d674598ed45da3d54190a656cJohn McCall void setAmpAmpLoc(SourceLocation Loc) { 65851bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 659b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 66051bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 661b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 662b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 66334a0447b8072e0da14c0980597da9d03a1495662John McCallstruct FunctionLocInfo { 66434a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation LParenLoc, RParenLoc; 665b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 666b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 667b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for functions. 66851bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 66951bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionTypeLoc, 67051bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionType, 67151bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionLocInfo> { 672b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis // ParmVarDecls* are stored after Info, one for each argument. 673b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis ParmVarDecl **getParmArray() const { 67434a0447b8072e0da14c0980597da9d03a1495662John McCall return (ParmVarDecl**) getExtraLocalData(); 675b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 676b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 677b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 678b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getLParenLoc() const { 67934a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->LParenLoc; 680b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 681b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setLParenLoc(SourceLocation Loc) { 68234a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->LParenLoc = Loc; 683b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 684b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 685b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getRParenLoc() const { 68634a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->RParenLoc; 687b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 688b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setRParenLoc(SourceLocation Loc) { 68934a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->RParenLoc = Loc; 690b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 691b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 692b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis unsigned getNumArgs() const { 69334a0447b8072e0da14c0980597da9d03a1495662John McCall if (isa<FunctionNoProtoType>(getTypePtr())) 694b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return 0; 69534a0447b8072e0da14c0980597da9d03a1495662John McCall return cast<FunctionProtoType>(getTypePtr())->getNumArgs(); 696b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 697b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; } 698b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; } 699b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 700b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getArgLoc(unsigned i) const; 701b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 702b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getResultLoc() const { 70334a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 704b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 705b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 706b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 707b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getLParenLoc(), getRParenLoc()); 708b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 709b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 7104ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall void initializeLocal(SourceLocation Loc) { 7114ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setLParenLoc(Loc); 7124ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setRParenLoc(Loc); 7134ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall for (unsigned i = 0, e = getNumArgs(); i != e; ++i) 7144ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setArg(i, NULL); 7154ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 7164ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 717b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of the type source info data block that is 718b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// specific to this type. 71934a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 72034a0447b8072e0da14c0980597da9d03a1495662John McCall return getNumArgs() * sizeof(ParmVarDecl*); 721b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 722b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 72334a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getResultType(); } 72434a0447b8072e0da14c0980597da9d03a1495662John McCall}; 72534a0447b8072e0da14c0980597da9d03a1495662John McCall 72651bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionProtoTypeLoc : 72751bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<FunctionTypeLoc, 72851bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionProtoTypeLoc, 72951bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionProtoType> { 73051bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 73151bd803fbdade51d674598ed45da3d54190a656cJohn McCall 73251bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionNoProtoTypeLoc : 73351bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<FunctionTypeLoc, 73451bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionNoProtoTypeLoc, 73551bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionNoProtoType> { 73651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 73751bd803fbdade51d674598ed45da3d54190a656cJohn McCall 738b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 73934a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ArrayLocInfo { 74034a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation LBracketLoc, RBracketLoc; 74134a0447b8072e0da14c0980597da9d03a1495662John McCall Expr *Size; 742b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 743b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 744b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for arrays. 74551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 74651bd803fbdade51d674598ed45da3d54190a656cJohn McCall ArrayTypeLoc, 74751bd803fbdade51d674598ed45da3d54190a656cJohn McCall ArrayType, 74851bd803fbdade51d674598ed45da3d54190a656cJohn McCall ArrayLocInfo> { 749b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 750b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getLBracketLoc() const { 75134a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->LBracketLoc; 752b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 753b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setLBracketLoc(SourceLocation Loc) { 75434a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->LBracketLoc = Loc; 755b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 756b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 757b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getRBracketLoc() const { 75834a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->RBracketLoc; 759b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 760b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setRBracketLoc(SourceLocation Loc) { 76134a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->RBracketLoc = Loc; 762b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 763b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 764b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis Expr *getSizeExpr() const { 76534a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->Size; 766b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 767b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setSizeExpr(Expr *Size) { 76834a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->Size = Size; 769b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 770b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 771b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getElementLoc() const { 77234a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 773b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 774b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 775b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 776b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getLBracketLoc(), getRBracketLoc()); 777b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 778b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 7794ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall void initializeLocal(SourceLocation Loc) { 7804ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setLBracketLoc(Loc); 7814ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setRBracketLoc(Loc); 7824ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setSizeExpr(NULL); 7834ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 7844ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 78534a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getElementType(); } 786b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 787b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 78851bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ConstantArrayTypeLoc : 78951bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<ArrayTypeLoc, 79051bd803fbdade51d674598ed45da3d54190a656cJohn McCall ConstantArrayTypeLoc, 79151bd803fbdade51d674598ed45da3d54190a656cJohn McCall ConstantArrayType> { 79251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 79351bd803fbdade51d674598ed45da3d54190a656cJohn McCall 79451bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass IncompleteArrayTypeLoc : 79551bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<ArrayTypeLoc, 79651bd803fbdade51d674598ed45da3d54190a656cJohn McCall IncompleteArrayTypeLoc, 79751bd803fbdade51d674598ed45da3d54190a656cJohn McCall IncompleteArrayType> { 79851bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 79951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 80051bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DependentSizedArrayTypeLoc : 80151bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<ArrayTypeLoc, 80251bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedArrayTypeLoc, 80351bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedArrayType> { 80451bd803fbdade51d674598ed45da3d54190a656cJohn McCall 80551bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 80651bd803fbdade51d674598ed45da3d54190a656cJohn McCall 80751bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass VariableArrayTypeLoc : 80851bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<ArrayTypeLoc, 80951bd803fbdade51d674598ed45da3d54190a656cJohn McCall VariableArrayTypeLoc, 81051bd803fbdade51d674598ed45da3d54190a656cJohn McCall VariableArrayType> { 81151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 81251bd803fbdade51d674598ed45da3d54190a656cJohn McCall 81351bd803fbdade51d674598ed45da3d54190a656cJohn McCall// None of these types have proper implementations yet. 81451bd803fbdade51d674598ed45da3d54190a656cJohn McCall 81551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass VectorTypeLoc : public TypeSpecTypeLoc<VectorTypeLoc, VectorType> { 81651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 81751bd803fbdade51d674598ed45da3d54190a656cJohn McCall 81851bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc, 81951bd803fbdade51d674598ed45da3d54190a656cJohn McCall ExtVectorTypeLoc, 82051bd803fbdade51d674598ed45da3d54190a656cJohn McCall ExtVectorType> { 82151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 82251bd803fbdade51d674598ed45da3d54190a656cJohn McCall 82351bd803fbdade51d674598ed45da3d54190a656cJohn McCall// For some reason, this isn't a subtype of VectorType. 82451bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DependentSizedExtVectorTypeLoc : 82551bd803fbdade51d674598ed45da3d54190a656cJohn McCall public TypeSpecTypeLoc<DependentSizedExtVectorTypeLoc, 82651bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedExtVectorType> { 82751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 82851bd803fbdade51d674598ed45da3d54190a656cJohn McCall 82951bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FixedWidthIntTypeLoc : public TypeSpecTypeLoc<FixedWidthIntTypeLoc, 83051bd803fbdade51d674598ed45da3d54190a656cJohn McCall FixedWidthIntType> { 83151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 83251bd803fbdade51d674598ed45da3d54190a656cJohn McCall 83351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ComplexTypeLoc : public TypeSpecTypeLoc<ComplexTypeLoc, 83451bd803fbdade51d674598ed45da3d54190a656cJohn McCall ComplexType> { 83551bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 83651bd803fbdade51d674598ed45da3d54190a656cJohn McCall 83751bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass TypeOfExprTypeLoc : public TypeSpecTypeLoc<TypeOfExprTypeLoc, 83851bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeOfExprType> { 83951bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 84051bd803fbdade51d674598ed45da3d54190a656cJohn McCall 84151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass TypeOfTypeLoc : public TypeSpecTypeLoc<TypeOfTypeLoc, TypeOfType> { 84251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 84351bd803fbdade51d674598ed45da3d54190a656cJohn McCall 84451bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DecltypeTypeLoc : public TypeSpecTypeLoc<DecltypeTypeLoc, DecltypeType> { 84551bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 84651bd803fbdade51d674598ed45da3d54190a656cJohn McCall 84751bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass TagTypeLoc : public TypeSpecTypeLoc<TagTypeLoc, TagType> { 84851bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 84951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 85051bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc, 85151bd803fbdade51d674598ed45da3d54190a656cJohn McCall RecordTypeLoc, 85251bd803fbdade51d674598ed45da3d54190a656cJohn McCall RecordType> { 85351bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 85451bd803fbdade51d674598ed45da3d54190a656cJohn McCall 85551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc, 85651bd803fbdade51d674598ed45da3d54190a656cJohn McCall EnumTypeLoc, 85751bd803fbdade51d674598ed45da3d54190a656cJohn McCall EnumType> { 85851bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 85951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 86051bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ElaboratedTypeLoc : public TypeSpecTypeLoc<ElaboratedTypeLoc, 86151bd803fbdade51d674598ed45da3d54190a656cJohn McCall ElaboratedType> { 86251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 86351bd803fbdade51d674598ed45da3d54190a656cJohn McCall 86451bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass TemplateSpecializationTypeLoc 86551bd803fbdade51d674598ed45da3d54190a656cJohn McCall : public TypeSpecTypeLoc<TemplateSpecializationTypeLoc, 86651bd803fbdade51d674598ed45da3d54190a656cJohn McCall TemplateSpecializationType> { 86751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 86851bd803fbdade51d674598ed45da3d54190a656cJohn McCall 86951bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass QualifiedNameTypeLoc : public TypeSpecTypeLoc<QualifiedNameTypeLoc, 87051bd803fbdade51d674598ed45da3d54190a656cJohn McCall QualifiedNameType> { 87151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 87251bd803fbdade51d674598ed45da3d54190a656cJohn McCall 87351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass TypenameTypeLoc : public TypeSpecTypeLoc<TypenameTypeLoc, 87451bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypenameType> { 87551bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 87651bd803fbdade51d674598ed45da3d54190a656cJohn McCall 877b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 878b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 879b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#endif 880