TypeLoc.h revision 34a0447b8072e0da14c0980597da9d03a1495662
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 TypeSpecLoc; 22b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis class DeclaratorInfo; 2334a0447b8072e0da14c0980597da9d03a1495662John McCall class UnqualTypeLoc; 24b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 25b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Base wrapper for a particular "section" of type source info. 26b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// 27b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// A client should use the TypeLoc subclasses through cast/dyn_cast in order to 28b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// get at the actual information. 29b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisclass TypeLoc { 30b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisprotected: 3134a0447b8072e0da14c0980597da9d03a1495662John McCall // The correctness of this relies on the property that, for Type *Ty, 3234a0447b8072e0da14c0980597da9d03a1495662John McCall // QualType(Ty, 0).getAsOpaquePtr() == (void*) Ty 3334a0447b8072e0da14c0980597da9d03a1495662John McCall void *Ty; 34b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void *Data; 351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 3734a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc() : Ty(0), Data(0) { } 3834a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc(QualType ty, void *opaqueData) 3934a0447b8072e0da14c0980597da9d03a1495662John McCall : Ty(ty.getAsOpaquePtr()), Data(opaqueData) { } 4034a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc(Type *ty, void *opaqueData) 4134a0447b8072e0da14c0980597da9d03a1495662John McCall : Ty(ty), Data(opaqueData) { } 42b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 4334a0447b8072e0da14c0980597da9d03a1495662John McCall bool isNull() const { return !Ty; } 4434a0447b8072e0da14c0980597da9d03a1495662John McCall operator bool() const { return Ty; } 45b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 46b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of type source info data block for the given type. 47b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis static unsigned getFullDataSizeForType(QualType Ty); 48b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 49b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Get the type for which this source info wrapper provides 50b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// information. 5134a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getSourceType() const { return QualType::getFromOpaquePtr(Ty); } 5234a0447b8072e0da14c0980597da9d03a1495662John McCall 5334a0447b8072e0da14c0980597da9d03a1495662John McCall Type *getSourceTypePtr() const { 5434a0447b8072e0da14c0980597da9d03a1495662John McCall return QualType::getFromOpaquePtr(Ty).getTypePtr(); 5534a0447b8072e0da14c0980597da9d03a1495662John McCall } 56b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 57b735471f3848065120d7210e557b5f0d37ed4c43Argyrios Kyrtzidis /// \brief Get the pointer where source information is stored. 58b735471f3848065120d7210e557b5f0d37ed4c43Argyrios Kyrtzidis void *getOpaqueData() const { return Data; } 59b735471f3848065120d7210e557b5f0d37ed4c43Argyrios Kyrtzidis 6068006af18fb880cd8547ce797152111b810aa0baArgyrios Kyrtzidis SourceRange getSourceRange() const; 6168006af18fb880cd8547ce797152111b810aa0baArgyrios Kyrtzidis 62b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this TypeLoc. 63b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeSpecLoc getTypeSpecLoc() const; 64b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 65b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this TypeLoc and return its 66b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// SourceRange. 67b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getTypeSpecRange() const; 68b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 69b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of the type source info data block. 7034a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getFullDataSize() const { 7134a0447b8072e0da14c0980597da9d03a1495662John McCall return getFullDataSizeForType(getSourceType()); 7234a0447b8072e0da14c0980597da9d03a1495662John McCall } 73b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 74b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the 75b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// TypeLoc is a PointerLoc and next TypeLoc is for "int". 76b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getNextTypeLoc() const; 77b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 7834a0447b8072e0da14c0980597da9d03a1495662John McCall /// \brief Skips past any qualifiers, if this is qualified. 7934a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc getUnqualifiedLoc() const; 8034a0447b8072e0da14c0980597da9d03a1495662John McCall 81b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) { 82b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data; 83b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 84b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 85b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis friend bool operator!=(const TypeLoc &LHS, const TypeLoc &RHS) { 86b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return !(LHS == RHS); 87b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 88b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 89b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis static bool classof(const TypeLoc *TL) { return true; } 90b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 91b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 9234a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with 9334a0447b8072e0da14c0980597da9d03a1495662John McCall/// no direct quqlaifiers. 9434a0447b8072e0da14c0980597da9d03a1495662John McCallclass UnqualTypeLoc : public TypeLoc { 9534a0447b8072e0da14c0980597da9d03a1495662John McCallpublic: 9634a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc() {} 9734a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc(Type *Ty, void *Data) : TypeLoc(Ty, Data) {} 9834a0447b8072e0da14c0980597da9d03a1495662John McCall 9934a0447b8072e0da14c0980597da9d03a1495662John McCall Type *getSourceTypePtr() const { 10034a0447b8072e0da14c0980597da9d03a1495662John McCall return reinterpret_cast<Type*>(Ty); 10134a0447b8072e0da14c0980597da9d03a1495662John McCall } 10234a0447b8072e0da14c0980597da9d03a1495662John McCall 10334a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const TypeLoc *TL) { 10434a0447b8072e0da14c0980597da9d03a1495662John McCall return !TL->getSourceType().hasQualifiers(); 10534a0447b8072e0da14c0980597da9d03a1495662John McCall } 10634a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const UnqualTypeLoc *TL) { return true; } 10734a0447b8072e0da14c0980597da9d03a1495662John McCall}; 10834a0447b8072e0da14c0980597da9d03a1495662John McCall 10934a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with 11034a0447b8072e0da14c0980597da9d03a1495662John McCall/// non-trivial direct qualifiers. 11134a0447b8072e0da14c0980597da9d03a1495662John McCall/// 11234a0447b8072e0da14c0980597da9d03a1495662John McCall/// Currently, we intentionally do not provide source location for 11334a0447b8072e0da14c0980597da9d03a1495662John McCall/// type qualifiers. 11434a0447b8072e0da14c0980597da9d03a1495662John McCallclass QualifiedLoc : public TypeLoc { 11534a0447b8072e0da14c0980597da9d03a1495662John McCallpublic: 11634a0447b8072e0da14c0980597da9d03a1495662John McCall SourceRange getSourceRange() const { 11734a0447b8072e0da14c0980597da9d03a1495662John McCall return SourceRange(); 11834a0447b8072e0da14c0980597da9d03a1495662John McCall } 11934a0447b8072e0da14c0980597da9d03a1495662John McCall 12034a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc getUnqualifiedLoc() const { 12134a0447b8072e0da14c0980597da9d03a1495662John McCall return UnqualTypeLoc(getSourceTypePtr(), Data); 12234a0447b8072e0da14c0980597da9d03a1495662John McCall } 12334a0447b8072e0da14c0980597da9d03a1495662John McCall 12434a0447b8072e0da14c0980597da9d03a1495662John McCall /// \brief Returns the size of the type source info data block that is 12534a0447b8072e0da14c0980597da9d03a1495662John McCall /// specific to this type. 12634a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getLocalDataSize() const { 12734a0447b8072e0da14c0980597da9d03a1495662John McCall // In fact, we don't currently preserve any location information 12834a0447b8072e0da14c0980597da9d03a1495662John McCall // for qualifiers. 12934a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 13034a0447b8072e0da14c0980597da9d03a1495662John McCall } 13134a0447b8072e0da14c0980597da9d03a1495662John McCall 13234a0447b8072e0da14c0980597da9d03a1495662John McCall /// \brief Returns the size of the type source info data block. 13334a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getFullDataSize() const { 13434a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalDataSize() + 13534a0447b8072e0da14c0980597da9d03a1495662John McCall getFullDataSizeForType(getSourceType().getUnqualifiedType()); 13634a0447b8072e0da14c0980597da9d03a1495662John McCall } 13734a0447b8072e0da14c0980597da9d03a1495662John McCall 13834a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const TypeLoc *TL) { 13934a0447b8072e0da14c0980597da9d03a1495662John McCall return TL->getSourceType().hasQualifiers(); 14034a0447b8072e0da14c0980597da9d03a1495662John McCall } 14134a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const QualifiedLoc *TL) { return true; } 14234a0447b8072e0da14c0980597da9d03a1495662John McCall}; 14334a0447b8072e0da14c0980597da9d03a1495662John McCall 14434a0447b8072e0da14c0980597da9d03a1495662John McCallinline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const { 14534a0447b8072e0da14c0980597da9d03a1495662John McCall if (isa<QualifiedLoc>(this)) 14634a0447b8072e0da14c0980597da9d03a1495662John McCall return cast<QualifiedLoc>(this)->getUnqualifiedLoc(); 14734a0447b8072e0da14c0980597da9d03a1495662John McCall return cast<UnqualTypeLoc>(*this); 14834a0447b8072e0da14c0980597da9d03a1495662John McCall} 14934a0447b8072e0da14c0980597da9d03a1495662John McCall 150b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Base wrapper of type source info data for type-spec types. 15134a0447b8072e0da14c0980597da9d03a1495662John McCallclass TypeSpecLoc : public UnqualTypeLoc { 152b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 15334a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const TypeLoc *TL) { 15434a0447b8072e0da14c0980597da9d03a1495662John McCall return (UnqualTypeLoc::classof(TL) && 15534a0447b8072e0da14c0980597da9d03a1495662John McCall classof(static_cast<const UnqualTypeLoc*>(TL))); 15634a0447b8072e0da14c0980597da9d03a1495662John McCall } 15734a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const UnqualTypeLoc *TL); 158b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis static bool classof(const TypeSpecLoc *TL) { return true; } 159b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 160b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 16134a0447b8072e0da14c0980597da9d03a1495662John McCallinline SourceRange TypeLoc::getTypeSpecRange() const { 16234a0447b8072e0da14c0980597da9d03a1495662John McCall return getTypeSpecLoc().getSourceRange(); 16334a0447b8072e0da14c0980597da9d03a1495662John McCall} 16434a0447b8072e0da14c0980597da9d03a1495662John McCall 165b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Base wrapper of type source info data for types part of a declarator, 166b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// excluding type-spec types. 16734a0447b8072e0da14c0980597da9d03a1495662John McCallclass DeclaratorLoc : public UnqualTypeLoc { 168b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 169b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this DeclaratorLoc. 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeSpecLoc getTypeSpecLoc() const; 171b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 17234a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const TypeLoc *TL) { 17334a0447b8072e0da14c0980597da9d03a1495662John McCall return (UnqualTypeLoc::classof(TL) && 17434a0447b8072e0da14c0980597da9d03a1495662John McCall classof(static_cast<const UnqualTypeLoc*>(TL))); 17534a0447b8072e0da14c0980597da9d03a1495662John McCall } 17634a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const UnqualTypeLoc *TL); 177b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis static bool classof(const DeclaratorLoc *TL) { return true; } 178b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 179b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 18034a0447b8072e0da14c0980597da9d03a1495662John McCall 18134a0447b8072e0da14c0980597da9d03a1495662John McCall/// A metaprogramming base class for TypeLoc classes which correspond 18234a0447b8072e0da14c0980597da9d03a1495662John McCall/// to a particular Type subclass. 18334a0447b8072e0da14c0980597da9d03a1495662John McCall/// 18434a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param Base a class from which to derive 18534a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param Derived the class deriving from this one 18634a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param TypeClass the concrete Type subclass which this 18734a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param LocalData the structure type of local location data for 18834a0447b8072e0da14c0980597da9d03a1495662John McCall/// this type 18934a0447b8072e0da14c0980597da9d03a1495662John McCall/// 19034a0447b8072e0da14c0980597da9d03a1495662John McCall/// sizeof(LocalData) needs to be a multiple of sizeof(void*) or 19134a0447b8072e0da14c0980597da9d03a1495662John McCall/// else the world will end. 19234a0447b8072e0da14c0980597da9d03a1495662John McCall/// 19334a0447b8072e0da14c0980597da9d03a1495662John McCall/// TypeLocs with non-constant amounts of local data should override 19434a0447b8072e0da14c0980597da9d03a1495662John McCall/// getExtraLocalDataSize(); getExtraLocalData() will then point to 19534a0447b8072e0da14c0980597da9d03a1495662John McCall/// this extra memory. 19634a0447b8072e0da14c0980597da9d03a1495662John McCall/// 19734a0447b8072e0da14c0980597da9d03a1495662John McCall/// TypeLocs with an inner type should override ha 19834a0447b8072e0da14c0980597da9d03a1495662John McCalltemplate <class Base, class Derived, class TypeClass, class LocalData> 19934a0447b8072e0da14c0980597da9d03a1495662John McCallclass ConcreteTypeLoc : public Base { 20034a0447b8072e0da14c0980597da9d03a1495662John McCall 20134a0447b8072e0da14c0980597da9d03a1495662John McCall const Derived *asDerived() const { 20234a0447b8072e0da14c0980597da9d03a1495662John McCall return static_cast<const Derived*>(this); 20334a0447b8072e0da14c0980597da9d03a1495662John McCall } 20434a0447b8072e0da14c0980597da9d03a1495662John McCall 20534a0447b8072e0da14c0980597da9d03a1495662John McCallpublic: 20634a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getLocalDataSize() const { 20734a0447b8072e0da14c0980597da9d03a1495662John McCall return sizeof(LocalData) + asDerived()->getExtraLocalDataSize(); 20834a0447b8072e0da14c0980597da9d03a1495662John McCall } 20934a0447b8072e0da14c0980597da9d03a1495662John McCall // Give a default implementation that's useful for leaf types. 21034a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getFullDataSize() const { 21134a0447b8072e0da14c0980597da9d03a1495662John McCall return asDerived()->getLocalDataSize() + getInnerTypeSize(); 21234a0447b8072e0da14c0980597da9d03a1495662John McCall } 21334a0447b8072e0da14c0980597da9d03a1495662John McCall 21434a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const TypeLoc *TL) { 21534a0447b8072e0da14c0980597da9d03a1495662John McCall return Derived::classofType(TL->getSourceTypePtr()); 21634a0447b8072e0da14c0980597da9d03a1495662John McCall } 21734a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const UnqualTypeLoc *TL) { 21834a0447b8072e0da14c0980597da9d03a1495662John McCall return Derived::classofType(TL->getSourceTypePtr()); 21934a0447b8072e0da14c0980597da9d03a1495662John McCall } 22034a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classof(const Derived *TL) { 22134a0447b8072e0da14c0980597da9d03a1495662John McCall return true; 22234a0447b8072e0da14c0980597da9d03a1495662John McCall } 22334a0447b8072e0da14c0980597da9d03a1495662John McCall 22434a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classofType(const Type *Ty) { 22534a0447b8072e0da14c0980597da9d03a1495662John McCall return TypeClass::classof(Ty); 22634a0447b8072e0da14c0980597da9d03a1495662John McCall } 22734a0447b8072e0da14c0980597da9d03a1495662John McCall 22834a0447b8072e0da14c0980597da9d03a1495662John McCallprotected: 22934a0447b8072e0da14c0980597da9d03a1495662John McCall TypeClass *getTypePtr() const { 23034a0447b8072e0da14c0980597da9d03a1495662John McCall return cast<TypeClass>(Base::getSourceTypePtr()); 23134a0447b8072e0da14c0980597da9d03a1495662John McCall } 23234a0447b8072e0da14c0980597da9d03a1495662John McCall 23334a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 23434a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 23534a0447b8072e0da14c0980597da9d03a1495662John McCall } 23634a0447b8072e0da14c0980597da9d03a1495662John McCall 23734a0447b8072e0da14c0980597da9d03a1495662John McCall LocalData *getLocalData() const { 23834a0447b8072e0da14c0980597da9d03a1495662John McCall return static_cast<LocalData*>(Base::Data); 23934a0447b8072e0da14c0980597da9d03a1495662John McCall } 24034a0447b8072e0da14c0980597da9d03a1495662John McCall 24134a0447b8072e0da14c0980597da9d03a1495662John McCall /// Gets a pointer past the Info structure; useful for classes with 24234a0447b8072e0da14c0980597da9d03a1495662John McCall /// local data that can't be captured in the Info (e.g. because it's 24334a0447b8072e0da14c0980597da9d03a1495662John McCall /// of variable size). 24434a0447b8072e0da14c0980597da9d03a1495662John McCall void *getExtraLocalData() const { 24534a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData() + 1; 24634a0447b8072e0da14c0980597da9d03a1495662John McCall } 24734a0447b8072e0da14c0980597da9d03a1495662John McCall 24834a0447b8072e0da14c0980597da9d03a1495662John McCall void *getNonLocalData() const { 24934a0447b8072e0da14c0980597da9d03a1495662John McCall return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize(); 25034a0447b8072e0da14c0980597da9d03a1495662John McCall } 25134a0447b8072e0da14c0980597da9d03a1495662John McCall 25234a0447b8072e0da14c0980597da9d03a1495662John McCall bool hasInnerType() const { 25334a0447b8072e0da14c0980597da9d03a1495662John McCall return false; 25434a0447b8072e0da14c0980597da9d03a1495662John McCall } 25534a0447b8072e0da14c0980597da9d03a1495662John McCall 25634a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc getInnerTypeLoc() const { 25734a0447b8072e0da14c0980597da9d03a1495662John McCall assert(asDerived()->hasInnerType()); 25834a0447b8072e0da14c0980597da9d03a1495662John McCall return TypeLoc(asDerived()->getInnerType(), getNonLocalData()); 25934a0447b8072e0da14c0980597da9d03a1495662John McCall } 26034a0447b8072e0da14c0980597da9d03a1495662John McCall 26134a0447b8072e0da14c0980597da9d03a1495662John McCallprivate: 26234a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getInnerTypeSize() const { 26334a0447b8072e0da14c0980597da9d03a1495662John McCall if (asDerived()->hasInnerType()) 26434a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc().getFullDataSize(); 26534a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 26634a0447b8072e0da14c0980597da9d03a1495662John McCall } 26734a0447b8072e0da14c0980597da9d03a1495662John McCall 26834a0447b8072e0da14c0980597da9d03a1495662John McCall // Required here because my metaprogramming is too weak to avoid it. 26934a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { 27034a0447b8072e0da14c0980597da9d03a1495662John McCall assert(0 && "getInnerType() not overridden"); 27134a0447b8072e0da14c0980597da9d03a1495662John McCall return QualType(); 27234a0447b8072e0da14c0980597da9d03a1495662John McCall } 27334a0447b8072e0da14c0980597da9d03a1495662John McCall}; 27434a0447b8072e0da14c0980597da9d03a1495662John McCall 27534a0447b8072e0da14c0980597da9d03a1495662John McCall 27634a0447b8072e0da14c0980597da9d03a1495662John McCallstruct DefaultTypeSpecLocInfo { 27734a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation StartLoc; 27834a0447b8072e0da14c0980597da9d03a1495662John McCall}; 27934a0447b8072e0da14c0980597da9d03a1495662John McCall 280b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief The default wrapper for type-spec types that are not handled by 281b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// another specific wrapper. 28234a0447b8072e0da14c0980597da9d03a1495662John McCallclass DefaultTypeSpecLoc : public ConcreteTypeLoc<TypeSpecLoc, 28334a0447b8072e0da14c0980597da9d03a1495662John McCall DefaultTypeSpecLoc, 28434a0447b8072e0da14c0980597da9d03a1495662John McCall Type, 28534a0447b8072e0da14c0980597da9d03a1495662John McCall DefaultTypeSpecLocInfo> { 286b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 287b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getStartLoc() const { 28834a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->StartLoc; 289b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 290b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setStartLoc(SourceLocation Loc) { 29134a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->StartLoc = Loc; 292b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 293b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 294b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getStartLoc(), getStartLoc()); 295b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 296b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 29734a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classofType(const Type *T); 29834a0447b8072e0da14c0980597da9d03a1495662John McCall}; 299b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 300b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 30134a0447b8072e0da14c0980597da9d03a1495662John McCallstruct TypedefLocInfo { 30234a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation NameLoc; 303b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 304b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 305b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for typedefs. 30634a0447b8072e0da14c0980597da9d03a1495662John McCallclass TypedefLoc : public ConcreteTypeLoc<TypeSpecLoc,TypedefLoc, 30734a0447b8072e0da14c0980597da9d03a1495662John McCall TypedefType,TypedefLocInfo> { 308b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 309b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getNameLoc() const { 31034a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->NameLoc; 311b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 312b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setNameLoc(SourceLocation Loc) { 31334a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->NameLoc = Loc; 314b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 315b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 316b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getNameLoc(), getNameLoc()); 317b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3199036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis TypedefDecl *getTypedefDecl() const { 32034a0447b8072e0da14c0980597da9d03a1495662John McCall return getTypePtr()->getDecl(); 3219036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis } 32234a0447b8072e0da14c0980597da9d03a1495662John McCall}; 3239036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis 324b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 32534a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ObjCInterfaceLocInfo { 32634a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation NameLoc; 327b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 328b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 329eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis/// \brief Wrapper for source info for ObjC interfaces. 33034a0447b8072e0da14c0980597da9d03a1495662John McCallclass ObjCInterfaceLoc : public ConcreteTypeLoc<TypeSpecLoc, 33134a0447b8072e0da14c0980597da9d03a1495662John McCall ObjCInterfaceLoc, 33234a0447b8072e0da14c0980597da9d03a1495662John McCall ObjCInterfaceType, 33334a0447b8072e0da14c0980597da9d03a1495662John McCall ObjCInterfaceLocInfo> { 334eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidispublic: 335eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis SourceLocation getNameLoc() const { 33634a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->NameLoc; 337eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis } 338eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis void setNameLoc(SourceLocation Loc) { 33934a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->NameLoc = Loc; 340eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis } 341eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis SourceRange getSourceRange() const { 342eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis return SourceRange(getNameLoc(), getNameLoc()); 343eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis } 344eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 345eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis ObjCInterfaceDecl *getIFaceDecl() const { 34634a0447b8072e0da14c0980597da9d03a1495662John McCall return getTypePtr()->getDecl(); 347eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis } 34834a0447b8072e0da14c0980597da9d03a1495662John McCall}; 349eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 350eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 35134a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ObjCProtocolListLocInfo { 35234a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation LAngleLoc, RAngleLoc; 353eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis}; 354eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 355f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis/// \brief Wrapper for source info for ObjC protocol lists. 35634a0447b8072e0da14c0980597da9d03a1495662John McCallclass ObjCProtocolListLoc : public ConcreteTypeLoc<TypeSpecLoc, 35734a0447b8072e0da14c0980597da9d03a1495662John McCall ObjCProtocolListLoc, 35834a0447b8072e0da14c0980597da9d03a1495662John McCall ObjCProtocolListType, 35934a0447b8072e0da14c0980597da9d03a1495662John McCall ObjCProtocolListLocInfo> { 360f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis // SourceLocations are stored after Info, one for each Protocol. 361f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation *getProtocolLocArray() const { 36234a0447b8072e0da14c0980597da9d03a1495662John McCall return (SourceLocation*) getExtraLocalData(); 363f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 364f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 365f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidispublic: 366f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getLAngleLoc() const { 36734a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->LAngleLoc; 368f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 369f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setLAngleLoc(SourceLocation Loc) { 37034a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->LAngleLoc = Loc; 371f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 372f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 373f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getRAngleLoc() const { 37434a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->RAngleLoc; 375f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 376f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setRAngleLoc(SourceLocation Loc) { 37734a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->RAngleLoc = Loc; 378f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 379f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 380f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis unsigned getNumProtocols() const { 38134a0447b8072e0da14c0980597da9d03a1495662John McCall return getTypePtr()->getNumProtocols(); 382f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 383f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 384f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getProtocolLoc(unsigned i) const { 385f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 386f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis return getProtocolLocArray()[i]; 387f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 388f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setProtocolLoc(unsigned i, SourceLocation Loc) { 389f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 390f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis getProtocolLocArray()[i] = Loc; 391f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 392f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 393f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis ObjCProtocolDecl *getProtocol(unsigned i) const { 394f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 39534a0447b8072e0da14c0980597da9d03a1495662John McCall return *(getTypePtr()->qual_begin() + i); 396f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 397f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 398f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis TypeLoc getBaseTypeLoc() const { 39934a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 400f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 401f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 402f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceRange getSourceRange() const { 403f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis return SourceRange(getLAngleLoc(), getRAngleLoc()); 404f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 405f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 406f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis /// \brief Returns the size of the type source info data block that is 407f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis /// specific to this type. 40834a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 40934a0447b8072e0da14c0980597da9d03a1495662John McCall return getNumProtocols() * sizeof(SourceLocation); 410f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 411f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 41234a0447b8072e0da14c0980597da9d03a1495662John McCall bool hasInnerType() const { return true; } 41334a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getBaseType(); } 41434a0447b8072e0da14c0980597da9d03a1495662John McCall}; 415f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 41634a0447b8072e0da14c0980597da9d03a1495662John McCall 41734a0447b8072e0da14c0980597da9d03a1495662John McCallstruct PointerLocInfo { 41834a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation StarLoc; 419f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis}; 420f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 421b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for pointers. 42234a0447b8072e0da14c0980597da9d03a1495662John McCallclass PointerLoc : public ConcreteTypeLoc<DeclaratorLoc, 42334a0447b8072e0da14c0980597da9d03a1495662John McCall PointerLoc, 42434a0447b8072e0da14c0980597da9d03a1495662John McCall PointerType, 42534a0447b8072e0da14c0980597da9d03a1495662John McCall PointerLocInfo> { 426b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 427b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getStarLoc() const { 42834a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->StarLoc; 429b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 430b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setStarLoc(SourceLocation Loc) { 43134a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->StarLoc = Loc; 432b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 433b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 434b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getPointeeLoc() const { 43534a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 436b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 437b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 438b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this PointerLoc. 439b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeSpecLoc getTypeSpecLoc() const { 440b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return getPointeeLoc().getTypeSpecLoc(); 441b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 442b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 443b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 444b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getStarLoc(), getStarLoc()); 445b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 446b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 44734a0447b8072e0da14c0980597da9d03a1495662John McCall bool hasInnerType() const { return true; } 44834a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getPointeeType(); } 44934a0447b8072e0da14c0980597da9d03a1495662John McCall}; 450b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 451b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 45234a0447b8072e0da14c0980597da9d03a1495662John McCallstruct BlockPointerLocInfo { 45334a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation CaretLoc; 454b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 455b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 456b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for block pointers. 45734a0447b8072e0da14c0980597da9d03a1495662John McCallclass BlockPointerLoc : public ConcreteTypeLoc<DeclaratorLoc, 45834a0447b8072e0da14c0980597da9d03a1495662John McCall BlockPointerLoc, 45934a0447b8072e0da14c0980597da9d03a1495662John McCall BlockPointerType, 46034a0447b8072e0da14c0980597da9d03a1495662John McCall BlockPointerLocInfo> { 461b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 462b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getCaretLoc() const { 46334a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->CaretLoc; 464b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 465b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setCaretLoc(SourceLocation Loc) { 46634a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->CaretLoc = Loc; 467b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 468b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 469b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getPointeeLoc() const { 47034a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 471b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 472b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 473b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this BlockPointerLoc. 474b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeSpecLoc getTypeSpecLoc() const { 475b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return getPointeeLoc().getTypeSpecLoc(); 476b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 477b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 478b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 479b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getCaretLoc(), getCaretLoc()); 480b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 481b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 48234a0447b8072e0da14c0980597da9d03a1495662John McCall bool hasInnerType() const { return true; } 48334a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getPointeeType(); } 48434a0447b8072e0da14c0980597da9d03a1495662John McCall}; 485b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 486b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 48734a0447b8072e0da14c0980597da9d03a1495662John McCallstruct MemberPointerLocInfo { 48834a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation StarLoc; 489b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 490b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 491b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for member pointers. 49234a0447b8072e0da14c0980597da9d03a1495662John McCallclass MemberPointerLoc : public ConcreteTypeLoc<DeclaratorLoc, 49334a0447b8072e0da14c0980597da9d03a1495662John McCall MemberPointerLoc, 49434a0447b8072e0da14c0980597da9d03a1495662John McCall MemberPointerType, 49534a0447b8072e0da14c0980597da9d03a1495662John McCall MemberPointerLocInfo> { 496b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 497b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getStarLoc() const { 49834a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->StarLoc; 499b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 500b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setStarLoc(SourceLocation Loc) { 50134a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->StarLoc = Loc; 502b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 503b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 504b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getPointeeLoc() const { 50534a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 506b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 507b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 508b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this MemberPointerLoc. 509b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeSpecLoc getTypeSpecLoc() const { 510b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return getPointeeLoc().getTypeSpecLoc(); 511b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 512b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 513b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 514b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getStarLoc(), getStarLoc()); 515b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 516b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 51734a0447b8072e0da14c0980597da9d03a1495662John McCall bool hasInnerType() const { return true; } 51834a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getPointeeType(); } 51934a0447b8072e0da14c0980597da9d03a1495662John McCall}; 520b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 521b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 52234a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ReferenceLocInfo { 52334a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation AmpLoc; 524b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 525b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 526b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for references. 52734a0447b8072e0da14c0980597da9d03a1495662John McCallclass ReferenceLoc : public ConcreteTypeLoc<DeclaratorLoc, 52834a0447b8072e0da14c0980597da9d03a1495662John McCall ReferenceLoc, 52934a0447b8072e0da14c0980597da9d03a1495662John McCall ReferenceType, 53034a0447b8072e0da14c0980597da9d03a1495662John McCall ReferenceLocInfo> { 531b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 532b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getAmpLoc() const { 53334a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->AmpLoc; 534b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 535b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setAmpLoc(SourceLocation Loc) { 53634a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->AmpLoc = Loc; 537b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 538b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 539b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getPointeeLoc() const { 54034a0447b8072e0da14c0980597da9d03a1495662John McCall return TypeLoc(getTypePtr()->getPointeeType(), getNonLocalData()); 541b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 542b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 543b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this ReferenceLoc. 544b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeSpecLoc getTypeSpecLoc() const { 545b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return getPointeeLoc().getTypeSpecLoc(); 546b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 547b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 548b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 549b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getAmpLoc(), getAmpLoc()); 550b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 551b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 55234a0447b8072e0da14c0980597da9d03a1495662John McCall bool hasInnerType() const { return true; } 55334a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getPointeeType(); } 55434a0447b8072e0da14c0980597da9d03a1495662John McCall}; 555b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 556b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 55734a0447b8072e0da14c0980597da9d03a1495662John McCallstruct FunctionLocInfo { 55834a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation LParenLoc, RParenLoc; 559b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 560b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 561b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for functions. 56234a0447b8072e0da14c0980597da9d03a1495662John McCallclass FunctionLoc : public ConcreteTypeLoc<DeclaratorLoc, 56334a0447b8072e0da14c0980597da9d03a1495662John McCall FunctionLoc, 56434a0447b8072e0da14c0980597da9d03a1495662John McCall FunctionType, 56534a0447b8072e0da14c0980597da9d03a1495662John McCall FunctionLocInfo> { 566b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis // ParmVarDecls* are stored after Info, one for each argument. 567b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis ParmVarDecl **getParmArray() const { 56834a0447b8072e0da14c0980597da9d03a1495662John McCall return (ParmVarDecl**) getExtraLocalData(); 569b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 570b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 571b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 572b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getLParenLoc() const { 57334a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->LParenLoc; 574b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 575b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setLParenLoc(SourceLocation Loc) { 57634a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->LParenLoc = Loc; 577b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 578b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 579b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getRParenLoc() const { 58034a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->RParenLoc; 581b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 582b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setRParenLoc(SourceLocation Loc) { 58334a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->RParenLoc = Loc; 584b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 585b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 586b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis unsigned getNumArgs() const { 58734a0447b8072e0da14c0980597da9d03a1495662John McCall if (isa<FunctionNoProtoType>(getTypePtr())) 588b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return 0; 58934a0447b8072e0da14c0980597da9d03a1495662John McCall return cast<FunctionProtoType>(getTypePtr())->getNumArgs(); 590b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 591b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; } 592b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; } 593b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 594b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getArgLoc(unsigned i) const; 595b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 596b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getResultLoc() const { 59734a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 598b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 599b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 600b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this FunctionLoc. 601b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeSpecLoc getTypeSpecLoc() const { 602b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return getResultLoc().getTypeSpecLoc(); 603b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 604b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 605b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getLParenLoc(), getRParenLoc()); 606b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 607b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 608b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of the type source info data block that is 609b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// specific to this type. 61034a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 61134a0447b8072e0da14c0980597da9d03a1495662John McCall return getNumArgs() * sizeof(ParmVarDecl*); 612b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 613b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 61434a0447b8072e0da14c0980597da9d03a1495662John McCall bool hasInnerType() const { return true; } 61534a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getResultType(); } 61634a0447b8072e0da14c0980597da9d03a1495662John McCall}; 61734a0447b8072e0da14c0980597da9d03a1495662John McCall 618b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 61934a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ArrayLocInfo { 62034a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation LBracketLoc, RBracketLoc; 62134a0447b8072e0da14c0980597da9d03a1495662John McCall Expr *Size; 622b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 623b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 624b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for arrays. 62534a0447b8072e0da14c0980597da9d03a1495662John McCallclass ArrayLoc : public ConcreteTypeLoc<DeclaratorLoc, 62634a0447b8072e0da14c0980597da9d03a1495662John McCall ArrayLoc, 62734a0447b8072e0da14c0980597da9d03a1495662John McCall ArrayType, 62834a0447b8072e0da14c0980597da9d03a1495662John McCall ArrayLocInfo> { 629b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 630b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getLBracketLoc() const { 63134a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->LBracketLoc; 632b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 633b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setLBracketLoc(SourceLocation Loc) { 63434a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->LBracketLoc = Loc; 635b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 636b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 637b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getRBracketLoc() const { 63834a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->RBracketLoc; 639b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 640b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setRBracketLoc(SourceLocation Loc) { 64134a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->RBracketLoc = Loc; 642b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 643b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 644b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis Expr *getSizeExpr() const { 64534a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->Size; 646b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 647b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setSizeExpr(Expr *Size) { 64834a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->Size = Size; 649b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 650b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 651b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getElementLoc() const { 65234a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 653b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 654b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 655b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Find the TypeSpecLoc that is part of this ArrayLoc. 656b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeSpecLoc getTypeSpecLoc() const { 657b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return getElementLoc().getTypeSpecLoc(); 658b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 659b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceRange getSourceRange() const { 660b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getLBracketLoc(), getRBracketLoc()); 661b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 662b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 66334a0447b8072e0da14c0980597da9d03a1495662John McCall bool hasInnerType() const { return true; } 66434a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getElementType(); } 665b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 666b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 667b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 668b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 669b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#endif 670