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//===----------------------------------------------------------------------===// 95013fcf1236980bd164ad070df298a0364e1e45fJames Dennett/// 105013fcf1236980bd164ad070df298a0364e1e45fJames Dennett/// \file 115013fcf1236980bd164ad070df298a0364e1e45fJames Dennett/// \brief Defines the clang::TypeLoc interface and its subclasses. 125013fcf1236980bd164ad070df298a0364e1e45fJames Dennett/// 13b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 14b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 15b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#ifndef LLVM_CLANG_AST_TYPELOC_H 16b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#define LLVM_CLANG_AST_TYPELOC_H 17b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 183c385c28cf1f27b193a620d2e51f814873362cebJohn McCall#include "clang/AST/Decl.h" 19833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall#include "clang/AST/TemplateBase.h" 2030a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/Type.h" 21ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor#include "clang/Basic/Specifiers.h" 22aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 23b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 24b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisnamespace clang { 25c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor class ASTContext; 26b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis class ParmVarDecl; 27a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall class TypeSourceInfo; 2834a0447b8072e0da14c0980597da9d03a1495662John McCall class UnqualTypeLoc; 29b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 3051bd803fbdade51d674598ed45da3d54190a656cJohn McCall// Predeclare all the type nodes. 3151bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPELOC(Class, Base) 3251bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define TYPELOC(Class, Base) \ 3351bd803fbdade51d674598ed45da3d54190a656cJohn McCall class Class##TypeLoc; 3451bd803fbdade51d674598ed45da3d54190a656cJohn McCall#include "clang/AST/TypeLocNodes.def" 3551bd803fbdade51d674598ed45da3d54190a656cJohn McCall 36b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Base wrapper for a particular "section" of type source info. 37b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// 385013fcf1236980bd164ad070df298a0364e1e45fJames Dennett/// A client should use the TypeLoc subclasses through castAs()/getAs() 395013fcf1236980bd164ad070df298a0364e1e45fJames Dennett/// in order to get at the actual information. 40b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisclass TypeLoc { 41b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisprotected: 4234a0447b8072e0da14c0980597da9d03a1495662John McCall // The correctness of this relies on the property that, for Type *Ty, 4334a0447b8072e0da14c0980597da9d03a1495662John McCall // QualType(Ty, 0).getAsOpaquePtr() == (void*) Ty 44f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const void *Ty; 45b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void *Data; 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 48464011827c5f9047caaba7e245556d66a65a15b6David Blaikie /// \brief Convert to the specified TypeLoc type, asserting that this TypeLoc 49464011827c5f9047caaba7e245556d66a65a15b6David Blaikie /// is of the desired type. 505013fcf1236980bd164ad070df298a0364e1e45fJames Dennett /// 515013fcf1236980bd164ad070df298a0364e1e45fJames Dennett /// \pre T::isKind(*this) 5239e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie template<typename T> 5339e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie T castAs() const { 5465124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie assert(T::isKind(*this)); 5539e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie T t; 5639e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie TypeLoc& tl = t; 5739e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie tl = *this; 5839e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie return t; 5939e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie } 60464011827c5f9047caaba7e245556d66a65a15b6David Blaikie 61464011827c5f9047caaba7e245556d66a65a15b6David Blaikie /// \brief Convert to the specified TypeLoc type, returning a null TypeLoc if 62464011827c5f9047caaba7e245556d66a65a15b6David Blaikie /// this TypeLoc is not of the desired type. 6339e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie template<typename T> 6439e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie T getAs() const { 6565124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie if (!T::isKind(*this)) 6639e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie return T(); 6739e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie T t; 6839e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie TypeLoc& tl = t; 6939e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie tl = *this; 7039e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie return t; 7139e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie } 7239e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie 7351bd803fbdade51d674598ed45da3d54190a656cJohn McCall /// The kinds of TypeLocs. Equivalent to the Type::TypeClass enum, 7451bd803fbdade51d674598ed45da3d54190a656cJohn McCall /// except it also defines a Qualified enum that corresponds to the 7551bd803fbdade51d674598ed45da3d54190a656cJohn McCall /// QualifiedLoc class. 7651bd803fbdade51d674598ed45da3d54190a656cJohn McCall enum TypeLocClass { 7751bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPE(Class, Base) 7851bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define TYPE(Class, Base) \ 7951bd803fbdade51d674598ed45da3d54190a656cJohn McCall Class = Type::Class, 8051bd803fbdade51d674598ed45da3d54190a656cJohn McCall#include "clang/AST/TypeNodes.def" 8151bd803fbdade51d674598ed45da3d54190a656cJohn McCall Qualified 8251bd803fbdade51d674598ed45da3d54190a656cJohn McCall }; 8351bd803fbdade51d674598ed45da3d54190a656cJohn McCall 846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines TypeLoc() : Ty(nullptr), Data(nullptr) { } 8534a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc(QualType ty, void *opaqueData) 8634a0447b8072e0da14c0980597da9d03a1495662John McCall : Ty(ty.getAsOpaquePtr()), Data(opaqueData) { } 87f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall TypeLoc(const Type *ty, void *opaqueData) 8834a0447b8072e0da14c0980597da9d03a1495662John McCall : Ty(ty), Data(opaqueData) { } 89b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 9051bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeLocClass getTypeLocClass() const { 91a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (getType().hasLocalQualifiers()) return Qualified; 9251bd803fbdade51d674598ed45da3d54190a656cJohn McCall return (TypeLocClass) getType()->getTypeClass(); 9351bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 9451bd803fbdade51d674598ed45da3d54190a656cJohn McCall 9534a0447b8072e0da14c0980597da9d03a1495662John McCall bool isNull() const { return !Ty; } 967247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie LLVM_EXPLICIT operator bool() const { return Ty; } 97b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 98b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of type source info data block for the given type. 99b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis static unsigned getFullDataSizeForType(QualType Ty); 100b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 10144ee0a710c59d8e6793189f903bae21c16814324Eli Friedman /// \brief Returns the alignment of type source info data block for 10244ee0a710c59d8e6793189f903bae21c16814324Eli Friedman /// the given type. 10344ee0a710c59d8e6793189f903bae21c16814324Eli Friedman static unsigned getLocalAlignmentForType(QualType Ty); 10444ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 105b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Get the type for which this source info wrapper provides 106b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// information. 10751bd803fbdade51d674598ed45da3d54190a656cJohn McCall QualType getType() const { 10851bd803fbdade51d674598ed45da3d54190a656cJohn McCall return QualType::getFromOpaquePtr(Ty); 10951bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 11034a0447b8072e0da14c0980597da9d03a1495662John McCall 111f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *getTypePtr() const { 11234a0447b8072e0da14c0980597da9d03a1495662John McCall return QualType::getFromOpaquePtr(Ty).getTypePtr(); 11334a0447b8072e0da14c0980597da9d03a1495662John McCall } 114b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 115b735471f3848065120d7210e557b5f0d37ed4c43Argyrios Kyrtzidis /// \brief Get the pointer where source information is stored. 11651bd803fbdade51d674598ed45da3d54190a656cJohn McCall void *getOpaqueData() const { 11751bd803fbdade51d674598ed45da3d54190a656cJohn McCall return Data; 11851bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 119b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 120e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara /// \brief Get the begin source location. 121e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara SourceLocation getBeginLoc() const; 122e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara 123e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara /// \brief Get the end source location. 124e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara SourceLocation getEndLoc() const; 125e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara 126833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Get the full source range. 127aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 128e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara return SourceRange(getBeginLoc(), getEndLoc()); 129833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 130aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc(); } 131aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 132833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 133833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Get the local source range. 134bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 135bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara return getLocalSourceRangeImpl(*this); 13651bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 137b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 138b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of the type source info data block. 13934a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getFullDataSize() const { 14051bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getFullDataSizeForType(getType()); 14134a0447b8072e0da14c0980597da9d03a1495662John McCall } 142b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 143b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the 144b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// TypeLoc is a PointerLoc and next TypeLoc is for "int". 14551bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeLoc getNextTypeLoc() const { 14651bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getNextTypeLocImpl(*this); 14751bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 148b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 14934a0447b8072e0da14c0980597da9d03a1495662John McCall /// \brief Skips past any qualifiers, if this is qualified. 15051bd803fbdade51d674598ed45da3d54190a656cJohn McCall UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header 15134a0447b8072e0da14c0980597da9d03a1495662John McCall 15239e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie TypeLoc IgnoreParens() const; 153140a2bd77539b4537010d8cd6a0a3805ce724b3eAbramo Bagnara 1544ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// \brief Initializes this to state that every location in this 1554ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// type is the given location. 1564ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// 1574ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// This method exists to provide a simple transition for code that 1584ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// relies on location-less types. 159c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initialize(ASTContext &Context, SourceLocation Loc) const { 160c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor initializeImpl(Context, *this, Loc); 1614ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 1624ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 16345ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein /// \brief Initializes this by copying its information from another 16445ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein /// TypeLoc of the same type. 16545ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein void initializeFullCopy(TypeLoc Other) const { 166711c52bb20d0c69063b52a99826fb7d2835501f1John McCall assert(getType() == Other.getType()); 167711c52bb20d0c69063b52a99826fb7d2835501f1John McCall size_t Size = getFullDataSize(); 168711c52bb20d0c69063b52a99826fb7d2835501f1John McCall memcpy(getOpaqueData(), Other.getOpaqueData(), Size); 169711c52bb20d0c69063b52a99826fb7d2835501f1John McCall } 170711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 171711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// \brief Initializes this by copying its information from another 172711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// TypeLoc of the same type. The given size must be the full data 173711c52bb20d0c69063b52a99826fb7d2835501f1John McCall /// size. 174711c52bb20d0c69063b52a99826fb7d2835501f1John McCall void initializeFullCopy(TypeLoc Other, unsigned Size) const { 175711c52bb20d0c69063b52a99826fb7d2835501f1John McCall assert(getType() == Other.getType()); 176711c52bb20d0c69063b52a99826fb7d2835501f1John McCall assert(getFullDataSize() == Size); 177711c52bb20d0c69063b52a99826fb7d2835501f1John McCall memcpy(getOpaqueData(), Other.getOpaqueData(), Size); 17845ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein } 17945ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein 180b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) { 181b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data; 182b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 183b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 184b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis friend bool operator!=(const TypeLoc &LHS, const TypeLoc &RHS) { 185b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return !(LHS == RHS); 186b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 187b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1884ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCallprivate: 18965124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie static bool isKind(const TypeLoc&) { 19065124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie return true; 19165124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie } 19265124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie 193ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static void initializeImpl(ASTContext &Context, TypeLoc TL, 194ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation Loc); 19551bd803fbdade51d674598ed45da3d54190a656cJohn McCall static TypeLoc getNextTypeLocImpl(TypeLoc TL); 196723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara static TypeLoc IgnoreParensImpl(TypeLoc TL); 197bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara static SourceRange getLocalSourceRangeImpl(TypeLoc TL); 198b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 199b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 2003c385c28cf1f27b193a620d2e51f814873362cebJohn McCall/// \brief Return the TypeLoc for a type source info. 2013c385c28cf1f27b193a620d2e51f814873362cebJohn McCallinline TypeLoc TypeSourceInfo::getTypeLoc() const { 2024ab92891a53adda8c52c1947351371da58e33f64Gabor Greif return TypeLoc(Ty, const_cast<void*>(static_cast<const void*>(this + 1))); 2033c385c28cf1f27b193a620d2e51f814873362cebJohn McCall} 2043c385c28cf1f27b193a620d2e51f814873362cebJohn McCall 20534a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with 206489f7131d0f7746525de3b26204c8eb523d84505Gabor Greif/// no direct qualifiers. 20734a0447b8072e0da14c0980597da9d03a1495662John McCallclass UnqualTypeLoc : public TypeLoc { 20834a0447b8072e0da14c0980597da9d03a1495662John McCallpublic: 20934a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc() {} 210f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall UnqualTypeLoc(const Type *Ty, void *Data) : TypeLoc(Ty, Data) {} 21134a0447b8072e0da14c0980597da9d03a1495662John McCall 212f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *getTypePtr() const { 213f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return reinterpret_cast<const Type*>(Ty); 21434a0447b8072e0da14c0980597da9d03a1495662John McCall } 21534a0447b8072e0da14c0980597da9d03a1495662John McCall 21651bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeLocClass getTypeLocClass() const { 21751bd803fbdade51d674598ed45da3d54190a656cJohn McCall return (TypeLocClass) getTypePtr()->getTypeClass(); 21851bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 21951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 22039e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikieprivate: 22139e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie friend class TypeLoc; 22265124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie static bool isKind(const TypeLoc &TL) { 22365124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie return !TL.getType().hasLocalQualifiers(); 22434a0447b8072e0da14c0980597da9d03a1495662John McCall } 22534a0447b8072e0da14c0980597da9d03a1495662John McCall}; 22634a0447b8072e0da14c0980597da9d03a1495662John McCall 22734a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with 22834a0447b8072e0da14c0980597da9d03a1495662John McCall/// non-trivial direct qualifiers. 22934a0447b8072e0da14c0980597da9d03a1495662John McCall/// 23034a0447b8072e0da14c0980597da9d03a1495662John McCall/// Currently, we intentionally do not provide source location for 23134a0447b8072e0da14c0980597da9d03a1495662John McCall/// type qualifiers. 23251bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass QualifiedTypeLoc : public TypeLoc { 23334a0447b8072e0da14c0980597da9d03a1495662John McCallpublic: 234bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 23534a0447b8072e0da14c0980597da9d03a1495662John McCall return SourceRange(); 23634a0447b8072e0da14c0980597da9d03a1495662John McCall } 23734a0447b8072e0da14c0980597da9d03a1495662John McCall 23834a0447b8072e0da14c0980597da9d03a1495662John McCall UnqualTypeLoc getUnqualifiedLoc() const { 23944ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned align = 24044ee0a710c59d8e6793189f903bae21c16814324Eli Friedman TypeLoc::getLocalAlignmentForType(QualType(getTypePtr(), 0)); 24144ee0a710c59d8e6793189f903bae21c16814324Eli Friedman uintptr_t dataInt = reinterpret_cast<uintptr_t>(Data); 24244ee0a710c59d8e6793189f903bae21c16814324Eli Friedman dataInt = llvm::RoundUpToAlignment(dataInt, align); 24344ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return UnqualTypeLoc(getTypePtr(), reinterpret_cast<void*>(dataInt)); 24434a0447b8072e0da14c0980597da9d03a1495662John McCall } 24534a0447b8072e0da14c0980597da9d03a1495662John McCall 2464ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// Initializes the local data of this type source info block to 2474ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall /// provide no information. 248c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 2494ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall // do nothing 2504ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 2514ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 2524ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall TypeLoc getNextTypeLoc() const { 2534ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall return getUnqualifiedLoc(); 2544ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 2554ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 25634a0447b8072e0da14c0980597da9d03a1495662John McCall /// \brief Returns the size of the type source info data block that is 25734a0447b8072e0da14c0980597da9d03a1495662John McCall /// specific to this type. 25834a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getLocalDataSize() const { 25934a0447b8072e0da14c0980597da9d03a1495662John McCall // In fact, we don't currently preserve any location information 26034a0447b8072e0da14c0980597da9d03a1495662John McCall // for qualifiers. 26134a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 26234a0447b8072e0da14c0980597da9d03a1495662John McCall } 26334a0447b8072e0da14c0980597da9d03a1495662John McCall 26444ee0a710c59d8e6793189f903bae21c16814324Eli Friedman /// \brief Returns the alignment of the type source info data block that is 26544ee0a710c59d8e6793189f903bae21c16814324Eli Friedman /// specific to this type. 26644ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getLocalDataAlignment() const { 26744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman // We don't preserve any location information. 26844ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return 1; 26934a0447b8072e0da14c0980597da9d03a1495662John McCall } 27034a0447b8072e0da14c0980597da9d03a1495662John McCall 27139e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikieprivate: 27239e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie friend class TypeLoc; 27365124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie static bool isKind(const TypeLoc &TL) { 27465124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie return TL.getType().hasLocalQualifiers(); 27534a0447b8072e0da14c0980597da9d03a1495662John McCall } 27634a0447b8072e0da14c0980597da9d03a1495662John McCall}; 27734a0447b8072e0da14c0980597da9d03a1495662John McCall 27834a0447b8072e0da14c0980597da9d03a1495662John McCallinline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const { 27939e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie if (QualifiedTypeLoc Loc = getAs<QualifiedTypeLoc>()) 28039e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie return Loc.getUnqualifiedLoc(); 28139e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie return castAs<UnqualTypeLoc>(); 28234a0447b8072e0da14c0980597da9d03a1495662John McCall} 28334a0447b8072e0da14c0980597da9d03a1495662John McCall 28434a0447b8072e0da14c0980597da9d03a1495662John McCall/// A metaprogramming base class for TypeLoc classes which correspond 285f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// to a particular Type subclass. It is accepted for a single 286f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// TypeLoc class to correspond to multiple Type classes. 28734a0447b8072e0da14c0980597da9d03a1495662John McCall/// 28870517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko/// \tparam Base a class from which to derive 28970517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko/// \tparam Derived the class deriving from this one 29070517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko/// \tparam TypeClass the concrete Type subclass associated with this 291f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// location type 29270517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko/// \tparam LocalData the structure type of local location data for 29334a0447b8072e0da14c0980597da9d03a1495662John McCall/// this type 29434a0447b8072e0da14c0980597da9d03a1495662John McCall/// 29534a0447b8072e0da14c0980597da9d03a1495662John McCall/// TypeLocs with non-constant amounts of local data should override 29634a0447b8072e0da14c0980597da9d03a1495662John McCall/// getExtraLocalDataSize(); getExtraLocalData() will then point to 29734a0447b8072e0da14c0980597da9d03a1495662John McCall/// this extra memory. 29834a0447b8072e0da14c0980597da9d03a1495662John McCall/// 299a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// TypeLocs with an inner type should define 300a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// QualType getInnerType() const 301a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// and getInnerTypeLoc() will then point to this inner type's 302a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// location data. 30351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// 30451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A word about hierarchies: this template is not designed to be 30551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// derived from multiple times in a hierarchy. It is also not 30651bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// designed to be used for classes where subtypes might provide 30751bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// different amounts of source information. It should be subclassed 30851bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// only at the deepest portion of the hierarchy where all children 30951bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// have identical source information; if that's an abstract type, 31051bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// then further descendents should inherit from 31151bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// InheritingConcreteTypeLoc instead. 31234a0447b8072e0da14c0980597da9d03a1495662John McCalltemplate <class Base, class Derived, class TypeClass, class LocalData> 31334a0447b8072e0da14c0980597da9d03a1495662John McCallclass ConcreteTypeLoc : public Base { 31434a0447b8072e0da14c0980597da9d03a1495662John McCall 31534a0447b8072e0da14c0980597da9d03a1495662John McCall const Derived *asDerived() const { 31634a0447b8072e0da14c0980597da9d03a1495662John McCall return static_cast<const Derived*>(this); 31734a0447b8072e0da14c0980597da9d03a1495662John McCall } 31834a0447b8072e0da14c0980597da9d03a1495662John McCall 31939e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie friend class TypeLoc; 32065124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie static bool isKind(const TypeLoc &TL) { 32144ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return !TL.getType().hasLocalQualifiers() && 32244ee0a710c59d8e6793189f903bae21c16814324Eli Friedman Derived::classofType(TL.getTypePtr()); 32334a0447b8072e0da14c0980597da9d03a1495662John McCall } 32434a0447b8072e0da14c0980597da9d03a1495662John McCall 32534a0447b8072e0da14c0980597da9d03a1495662John McCall static bool classofType(const Type *Ty) { 32634a0447b8072e0da14c0980597da9d03a1495662John McCall return TypeClass::classof(Ty); 32734a0447b8072e0da14c0980597da9d03a1495662John McCall } 32834a0447b8072e0da14c0980597da9d03a1495662John McCall 32939e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikiepublic: 33044ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getLocalDataAlignment() const { 33144ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return std::max(llvm::alignOf<LocalData>(), 33244ee0a710c59d8e6793189f903bae21c16814324Eli Friedman asDerived()->getExtraLocalDataAlignment()); 33320387efff0870da2c8b30bb62ae661239a903021Manuel Klimek } 33444ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getLocalDataSize() const { 33544ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned size = sizeof(LocalData); 33644ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned extraAlign = asDerived()->getExtraLocalDataAlignment(); 33744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman size = llvm::RoundUpToAlignment(size, extraAlign); 33844ee0a710c59d8e6793189f903bae21c16814324Eli Friedman size += asDerived()->getExtraLocalDataSize(); 33944ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return size; 340e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 341e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 3424ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall TypeLoc getNextTypeLoc() const { 3434ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall return getNextTypeLoc(asDerived()->getInnerType()); 3444ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 3454ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 346f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypeClass *getTypePtr() const { 34751bd803fbdade51d674598ed45da3d54190a656cJohn McCall return cast<TypeClass>(Base::getTypePtr()); 34834a0447b8072e0da14c0980597da9d03a1495662John McCall } 34934a0447b8072e0da14c0980597da9d03a1495662John McCall 35051bd803fbdade51d674598ed45da3d54190a656cJohn McCallprotected: 35134a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 35234a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 35334a0447b8072e0da14c0980597da9d03a1495662John McCall } 35434a0447b8072e0da14c0980597da9d03a1495662John McCall 35544ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getExtraLocalDataAlignment() const { 35644ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return 1; 35744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 35844ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 35934a0447b8072e0da14c0980597da9d03a1495662John McCall LocalData *getLocalData() const { 36034a0447b8072e0da14c0980597da9d03a1495662John McCall return static_cast<LocalData*>(Base::Data); 36134a0447b8072e0da14c0980597da9d03a1495662John McCall } 36234a0447b8072e0da14c0980597da9d03a1495662John McCall 36334a0447b8072e0da14c0980597da9d03a1495662John McCall /// Gets a pointer past the Info structure; useful for classes with 36434a0447b8072e0da14c0980597da9d03a1495662John McCall /// local data that can't be captured in the Info (e.g. because it's 36534a0447b8072e0da14c0980597da9d03a1495662John McCall /// of variable size). 36634a0447b8072e0da14c0980597da9d03a1495662John McCall void *getExtraLocalData() const { 36744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned size = sizeof(LocalData); 36844ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned extraAlign = asDerived()->getExtraLocalDataAlignment(); 36944ee0a710c59d8e6793189f903bae21c16814324Eli Friedman size = llvm::RoundUpToAlignment(size, extraAlign); 37044ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return reinterpret_cast<char*>(Base::Data) + size; 37134a0447b8072e0da14c0980597da9d03a1495662John McCall } 372ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 37334a0447b8072e0da14c0980597da9d03a1495662John McCall void *getNonLocalData() const { 37444ee0a710c59d8e6793189f903bae21c16814324Eli Friedman uintptr_t data = reinterpret_cast<uintptr_t>(Base::Data); 37544ee0a710c59d8e6793189f903bae21c16814324Eli Friedman data += asDerived()->getLocalDataSize(); 37644ee0a710c59d8e6793189f903bae21c16814324Eli Friedman data = llvm::RoundUpToAlignment(data, getNextTypeAlign()); 37744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return reinterpret_cast<void*>(data); 37834a0447b8072e0da14c0980597da9d03a1495662John McCall } 37934a0447b8072e0da14c0980597da9d03a1495662John McCall 380a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall struct HasNoInnerType {}; 381a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall HasNoInnerType getInnerType() const { return HasNoInnerType(); } 38234a0447b8072e0da14c0980597da9d03a1495662John McCall 38334a0447b8072e0da14c0980597da9d03a1495662John McCall TypeLoc getInnerTypeLoc() const { 38434a0447b8072e0da14c0980597da9d03a1495662John McCall return TypeLoc(asDerived()->getInnerType(), getNonLocalData()); 38534a0447b8072e0da14c0980597da9d03a1495662John McCall } 38634a0447b8072e0da14c0980597da9d03a1495662John McCall 38734a0447b8072e0da14c0980597da9d03a1495662John McCallprivate: 38834a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getInnerTypeSize() const { 389a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall return getInnerTypeSize(asDerived()->getInnerType()); 390a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall } 391a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall 392a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall unsigned getInnerTypeSize(HasNoInnerType _) const { 39334a0447b8072e0da14c0980597da9d03a1495662John McCall return 0; 39434a0447b8072e0da14c0980597da9d03a1495662John McCall } 39534a0447b8072e0da14c0980597da9d03a1495662John McCall 396a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall unsigned getInnerTypeSize(QualType _) const { 397a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall return getInnerTypeLoc().getFullDataSize(); 39834a0447b8072e0da14c0980597da9d03a1495662John McCall } 3994ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 40044ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getNextTypeAlign() const { 40144ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return getNextTypeAlign(asDerived()->getInnerType()); 40244ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 40344ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 40444ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getNextTypeAlign(HasNoInnerType _) const { 40544ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return 1; 40644ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 40744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 40844ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getNextTypeAlign(QualType T) const { 40944ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return TypeLoc::getLocalAlignmentForType(T); 41044ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 41144ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 4124ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall TypeLoc getNextTypeLoc(HasNoInnerType _) const { 4134ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall return TypeLoc(); 4144ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 4154ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 4164ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall TypeLoc getNextTypeLoc(QualType T) const { 4174ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall return TypeLoc(T, getNonLocalData()); 4184ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 41934a0447b8072e0da14c0980597da9d03a1495662John McCall}; 42034a0447b8072e0da14c0980597da9d03a1495662John McCall 42151bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A metaprogramming class designed for concrete subtypes of abstract 42251bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// types where all subtypes share equivalently-structured source 42351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// information. See the note on ConcreteTypeLoc. 42451bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Base, class Derived, class TypeClass> 42551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass InheritingConcreteTypeLoc : public Base { 42639e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie friend class TypeLoc; 427713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor static bool classofType(const Type *Ty) { 428713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor return TypeClass::classof(Ty); 429713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor } 430713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor 43165124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie static bool isKind(const TypeLoc &TL) { 43244ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return !TL.getType().hasLocalQualifiers() && 43344ee0a710c59d8e6793189f903bae21c16814324Eli Friedman Derived::classofType(TL.getTypePtr()); 434b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 43565124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie static bool isKind(const UnqualTypeLoc &TL) { 43665124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie return Derived::classofType(TL.getTypePtr()); 437b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 438b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 43939e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikiepublic: 440f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypeClass *getTypePtr() const { 44151bd803fbdade51d674598ed45da3d54190a656cJohn McCall return cast<TypeClass>(Base::getTypePtr()); 4424ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 44334a0447b8072e0da14c0980597da9d03a1495662John McCall}; 444b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 445ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 44651bd803fbdade51d674598ed45da3d54190a656cJohn McCallstruct TypeSpecLocInfo { 44734a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation NameLoc; 448b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 449b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 45051bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief A reasonable base class for TypeLocs that correspond to 45151bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// types that are written as a type-specifier. 452ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikieclass TypeSpecTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 453ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc, 454ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Type, 455ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecLocInfo> { 456b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 45744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman enum { LocalDataSize = sizeof(TypeSpecLocInfo), 45844ee0a710c59d8e6793189f903bae21c16814324Eli Friedman LocalDataAlignment = llvm::AlignOf<TypeSpecLocInfo>::Alignment }; 459ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 460b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getNameLoc() const { 46151bd803fbdade51d674598ed45da3d54190a656cJohn McCall return this->getLocalData()->NameLoc; 462b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 463b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setNameLoc(SourceLocation Loc) { 46451bd803fbdade51d674598ed45da3d54190a656cJohn McCall this->getLocalData()->NameLoc = Loc; 465b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 466bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 467b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getNameLoc(), getNameLoc()); 468b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 469c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 4704ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setNameLoc(Loc); 4714ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 472ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 47339e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikieprivate: 47439e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie friend class TypeLoc; 47565124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie static bool isKind(const TypeLoc &TL); 47651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 4774ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 478ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 479ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorstruct BuiltinLocInfo { 480ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor SourceLocation BuiltinLoc; 481ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor}; 482ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 483ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor/// \brief Wrapper for source info for builtin types. 484ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorclass BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 485ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc, 486ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinType, 487ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinLocInfo> { 488ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorpublic: 489ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor SourceLocation getBuiltinLoc() const { 490ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return getLocalData()->BuiltinLoc; 491ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 492ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor void setBuiltinLoc(SourceLocation Loc) { 493ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor getLocalData()->BuiltinLoc = Loc; 494ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 495ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 496ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor SourceLocation getNameLoc() const { return getBuiltinLoc(); } 497ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 498ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor WrittenBuiltinSpecs& getWrittenBuiltinSpecs() { 499ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData())); 500ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 501ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const { 502ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData())); 503ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 504ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 505ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor bool needsExtraLocalData() const { 506ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinType::Kind bk = getTypePtr()->getKind(); 507ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128) 508d038f361d2b4368af7ab85bd04d5aafcc3ea649dDouglas Gregor || (bk >= BuiltinType::Short && bk <= BuiltinType::LongDouble) 509ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor || bk == BuiltinType::UChar 510ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor || bk == BuiltinType::SChar; 511ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 512ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 513ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor unsigned getExtraLocalDataSize() const { 514d31351288e25e8a7a2a919c99ffe281c2a41b53cDaniel Dunbar return needsExtraLocalData() ? sizeof(WrittenBuiltinSpecs) : 0; 515ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 516ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 51744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getExtraLocalDataAlignment() const { 51844ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return needsExtraLocalData() ? llvm::alignOf<WrittenBuiltinSpecs>() : 1; 51944ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 52044ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 521bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 522ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return SourceRange(getBuiltinLoc(), getBuiltinLoc()); 523ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 524ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 525ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor TypeSpecifierSign getWrittenSignSpec() const { 526ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (needsExtraLocalData()) 527ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return static_cast<TypeSpecifierSign>(getWrittenBuiltinSpecs().Sign); 528ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor else 529ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return TSS_unspecified; 530ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 531ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor bool hasWrittenSignSpec() const { 532ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return getWrittenSignSpec() != TSS_unspecified; 533ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 534ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor void setWrittenSignSpec(TypeSpecifierSign written) { 535ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (needsExtraLocalData()) 536ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor getWrittenBuiltinSpecs().Sign = written; 537ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 538ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 539ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor TypeSpecifierWidth getWrittenWidthSpec() const { 540ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (needsExtraLocalData()) 541ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return static_cast<TypeSpecifierWidth>(getWrittenBuiltinSpecs().Width); 542ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor else 543ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return TSW_unspecified; 544ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 545ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor bool hasWrittenWidthSpec() const { 546ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return getWrittenWidthSpec() != TSW_unspecified; 547ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 548ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor void setWrittenWidthSpec(TypeSpecifierWidth written) { 549ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (needsExtraLocalData()) 550ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor getWrittenBuiltinSpecs().Width = written; 551ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 552ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 553ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor TypeSpecifierType getWrittenTypeSpec() const; 554ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor bool hasWrittenTypeSpec() const { 555ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return getWrittenTypeSpec() != TST_unspecified; 556ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 557ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor void setWrittenTypeSpec(TypeSpecifierType written) { 558ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (needsExtraLocalData()) 559ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor getWrittenBuiltinSpecs().Type = written; 560ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 561ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 562ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor bool hasModeAttr() const { 563ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (needsExtraLocalData()) 564ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return getWrittenBuiltinSpecs().ModeAttr; 565ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor else 566ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return false; 567ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 568ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor void setModeAttr(bool written) { 569ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (needsExtraLocalData()) 570ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor getWrittenBuiltinSpecs().ModeAttr = written; 571ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 572ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 573c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 574ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor setBuiltinLoc(Loc); 575ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (needsExtraLocalData()) { 576ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs(); 577ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor wbs.Sign = TSS_unspecified; 578ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor wbs.Width = TSW_unspecified; 579ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor wbs.Type = TST_unspecified; 580ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor wbs.ModeAttr = false; 581ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 582ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor } 583ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor}; 584ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 585ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor 58651bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for typedefs. 587ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TypedefTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 588ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypedefTypeLoc, 589ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypedefType> { 59051bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic: 591162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *getTypedefNameDecl() const { 59234a0447b8072e0da14c0980597da9d03a1495662John McCall return getTypePtr()->getDecl(); 5939036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis } 59434a0447b8072e0da14c0980597da9d03a1495662John McCall}; 5959036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis 5963cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// \brief Wrapper for source info for injected class names of class 5973cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// templates. 5983cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameTypeLoc : 5993cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 6003cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall InjectedClassNameTypeLoc, 6013cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall InjectedClassNameType> { 602427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidispublic: 603427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidis CXXRecordDecl *getDecl() const { 604427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidis return getTypePtr()->getDecl(); 605427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidis } 6063cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}; 6073cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 608ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for unresolved typename using decls. 609ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingTypeLoc : 610ed97649e9574b9d854fa4d6109c9333ae0993554John McCall public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 611ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypeLoc, 612ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingType> { 613ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 614ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingTypenameDecl *getDecl() const { 615ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return getTypePtr()->getDecl(); 616ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 617ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 618ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 619ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for tag types. Note that this only 620ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// records source info for the name itself; a type written 'struct foo' 621ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// should be represented as an ElaboratedTypeLoc. We currently 622ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// only do that when C++ is enabled because of the expense of 623ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// creating an ElaboratedType node for so many type references in C. 624ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TagTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 625ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TagTypeLoc, 626ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TagType> { 627ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 628ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TagDecl *getDecl() const { return getTypePtr()->getDecl(); } 6296f155de99c59af890817146ec8526bafb6560f1fArgyrios Kyrtzidis 630ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief True if the tag was defined in this type specifier. 6316f155de99c59af890817146ec8526bafb6560f1fArgyrios Kyrtzidis bool isDefinition() const { 632a346efaaad5cd779cdfd5be73c2b258748ad1f06Argyrios Kyrtzidis TagDecl *D = getDecl(); 633a346efaaad5cd779cdfd5be73c2b258748ad1f06Argyrios Kyrtzidis return D->isCompleteDefinition() && 6346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines (D->getIdentifier() == nullptr || D->getLocation() == getNameLoc()); 6356f155de99c59af890817146ec8526bafb6560f1fArgyrios Kyrtzidis } 636ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 637ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 638ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for record types. 639ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc, 640ed97649e9574b9d854fa4d6109c9333ae0993554John McCall RecordTypeLoc, 641ed97649e9574b9d854fa4d6109c9333ae0993554John McCall RecordType> { 642ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 643ed97649e9574b9d854fa4d6109c9333ae0993554John McCall RecordDecl *getDecl() const { return getTypePtr()->getDecl(); } 644ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 645ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 646ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for enum types. 647ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc, 648ed97649e9574b9d854fa4d6109c9333ae0993554John McCall EnumTypeLoc, 649ed97649e9574b9d854fa4d6109c9333ae0993554John McCall EnumType> { 650ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic: 651ed97649e9574b9d854fa4d6109c9333ae0993554John McCall EnumDecl *getDecl() const { return getTypePtr()->getDecl(); } 652ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}; 653b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 65449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Wrapper for template type parameters. 655ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TemplateTypeParmTypeLoc : 656ed97649e9574b9d854fa4d6109c9333ae0993554John McCall public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 657ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TemplateTypeParmTypeLoc, 658ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TemplateTypeParmType> { 659960d13dde337a59dacc9dc3936c26d4aa8478986Chandler Carruthpublic: 660960d13dde337a59dacc9dc3936c26d4aa8478986Chandler Carruth TemplateTypeParmDecl *getDecl() const { return getTypePtr()->getDecl(); } 66149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 66249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 66349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Wrapper for substituted template type parameters. 66449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmTypeLoc : 665ed97649e9574b9d854fa4d6109c9333ae0993554John McCall public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 666ed97649e9574b9d854fa4d6109c9333ae0993554John McCall SubstTemplateTypeParmTypeLoc, 667ed97649e9574b9d854fa4d6109c9333ae0993554John McCall SubstTemplateTypeParmType> { 66849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}; 66951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 670c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor /// \brief Wrapper for substituted template type parameters. 671c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackTypeLoc : 672c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 673c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc, 674c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType> { 675c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}; 676c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 6779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallstruct AttributedLocInfo { 6789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall union { 6799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Expr *ExprOperand; 6809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 6819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// A raw SourceLocation. 6829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall unsigned EnumOperandLoc; 6839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall }; 6849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 6859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceRange OperandParens; 6869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 6879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceLocation AttrLoc; 6889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}; 6899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 6909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// \brief Type source information for an attributed type. 6919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 6929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc, 6939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType, 6949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedLocInfo> { 6959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic: 6969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType::Kind getAttrKind() const { 6979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getTypePtr()->getAttrKind(); 6989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 6999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall bool hasAttrExprOperand() const { 7019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return (getAttrKind() >= AttributedType::FirstExprOperandKind && 7029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall getAttrKind() <= AttributedType::LastExprOperandKind); 7039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall bool hasAttrEnumOperand() const { 7069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return (getAttrKind() >= AttributedType::FirstEnumOperandKind && 7079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall getAttrKind() <= AttributedType::LastEnumOperandKind); 7089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall bool hasAttrOperand() const { 7119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return hasAttrExprOperand() || hasAttrEnumOperand(); 7129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// The modified type, which is generally canonically different from 7159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// the attribute type. 7169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// int main(int, char**) __attribute__((noreturn)) 7179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// ~~~ ~~~~~~~~~~~~~ 7189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall TypeLoc getModifiedLoc() const { 7199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getInnerTypeLoc(); 7209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// The location of the attribute name, i.e. 7239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// __attribute__((regparm(1000))) 7249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// ^~~~~~~ 7259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceLocation getAttrNameLoc() const { 7269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getLocalData()->AttrLoc; 7279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void setAttrNameLoc(SourceLocation loc) { 7299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall getLocalData()->AttrLoc = loc; 7309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// The attribute's expression operand, if it has one. 7339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// void *cur_thread __attribute__((address_space(21))) 7349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// ^~ 7359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Expr *getAttrExprOperand() const { 7369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall assert(hasAttrExprOperand()); 7379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getLocalData()->ExprOperand; 7389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void setAttrExprOperand(Expr *e) { 7409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall assert(hasAttrExprOperand()); 7419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall getLocalData()->ExprOperand = e; 7429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// The location of the attribute's enumerated operand, if it has one. 7459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// void * __attribute__((objc_gc(weak))) 7469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// ^~~~ 7479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceLocation getAttrEnumOperandLoc() const { 7489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall assert(hasAttrEnumOperand()); 7499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return SourceLocation::getFromRawEncoding(getLocalData()->EnumOperandLoc); 7509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void setAttrEnumOperandLoc(SourceLocation loc) { 7529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall assert(hasAttrEnumOperand()); 7539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall getLocalData()->EnumOperandLoc = loc.getRawEncoding(); 7549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// The location of the parentheses around the operand, if there is 7579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// an operand. 7589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// void * __attribute__((objc_gc(weak))) 7599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall /// ^ ^ 7609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceRange getAttrOperandParensRange() const { 7619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall assert(hasAttrOperand()); 7629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getLocalData()->OperandParens; 7639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void setAttrOperandParensRange(SourceRange range) { 7659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall assert(hasAttrOperand()); 7669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall getLocalData()->OperandParens = range; 7679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceRange getLocalSourceRange() const { 7709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // Note that this does *not* include the range of the attribute 7719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // enclosure, e.g.: 7729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // __attribute__((foo(bar))) 7739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // ^~~~~~~~~~~~~~~ ~~ 7749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // or 7759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // [[foo(bar)]] 7769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // ^~ ~~ 7779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // That enclosure doesn't necessarily belong to a single attribute 7789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // anyway. 7799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall SourceRange range(getAttrNameLoc()); 7809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (hasAttrOperand()) 7819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall range.setEnd(getAttrOperandParensRange().getEnd()); 7829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return range; 7839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 785c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation loc) { 7869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall setAttrNameLoc(loc); 7879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (hasAttrExprOperand()) { 7889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall setAttrOperandParensRange(SourceRange(loc)); 7896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines setAttrExprOperand(nullptr); 7909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } else if (hasAttrEnumOperand()) { 7919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall setAttrOperandParensRange(SourceRange(loc)); 7929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall setAttrEnumOperandLoc(loc); 7939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 7969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType getInnerType() const { 7979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getTypePtr()->getModifiedType(); 7989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 7999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}; 8009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 801eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 80234a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ObjCProtocolListLocInfo { 80354e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation LAngleLoc; 80454e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation RAngleLoc; 805ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall bool HasBaseTypeAsWritten; 806eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis}; 807eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis 80854e14c4db764c0636160d26c5bbf491637c83a76John McCall// A helper class for defining ObjC TypeLocs that can qualified with 80954e14c4db764c0636160d26c5bbf491637c83a76John McCall// protocols. 81054e14c4db764c0636160d26c5bbf491637c83a76John McCall// 81154e14c4db764c0636160d26c5bbf491637c83a76John McCall// TypeClass basically has to be either ObjCInterfaceType or 81254e14c4db764c0636160d26c5bbf491637c83a76John McCall// ObjCObjectPointerType. 813c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 814c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeLoc, 815c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectType, 816c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolListLocInfo> { 817f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis // SourceLocations are stored after Info, one for each Protocol. 818f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation *getProtocolLocArray() const { 81954e14c4db764c0636160d26c5bbf491637c83a76John McCall return (SourceLocation*) this->getExtraLocalData(); 82054e14c4db764c0636160d26c5bbf491637c83a76John McCall } 82154e14c4db764c0636160d26c5bbf491637c83a76John McCall 822f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidispublic: 823f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getLAngleLoc() const { 82454e14c4db764c0636160d26c5bbf491637c83a76John McCall return this->getLocalData()->LAngleLoc; 825f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 826f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setLAngleLoc(SourceLocation Loc) { 82754e14c4db764c0636160d26c5bbf491637c83a76John McCall this->getLocalData()->LAngleLoc = Loc; 828f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 829f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 830f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getRAngleLoc() const { 83154e14c4db764c0636160d26c5bbf491637c83a76John McCall return this->getLocalData()->RAngleLoc; 832f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 833f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setRAngleLoc(SourceLocation Loc) { 83454e14c4db764c0636160d26c5bbf491637c83a76John McCall this->getLocalData()->RAngleLoc = Loc; 835f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 836f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 837f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis unsigned getNumProtocols() const { 83854e14c4db764c0636160d26c5bbf491637c83a76John McCall return this->getTypePtr()->getNumProtocols(); 839f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 840f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 841f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis SourceLocation getProtocolLoc(unsigned i) const { 842f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 843f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis return getProtocolLocArray()[i]; 844f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 845f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis void setProtocolLoc(unsigned i, SourceLocation Loc) { 846f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 847f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis getProtocolLocArray()[i] = Loc; 848f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 849f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 850f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis ObjCProtocolDecl *getProtocol(unsigned i) const { 851f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis assert(i < getNumProtocols() && "Index is out of bounds!"); 85254e14c4db764c0636160d26c5bbf491637c83a76John McCall return *(this->getTypePtr()->qual_begin() + i); 853f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 854ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 855c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool hasBaseTypeAsWritten() const { 856ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall return getLocalData()->HasBaseTypeAsWritten; 857c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 858c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 859c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void setHasBaseTypeAsWritten(bool HasBaseType) { 860ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall getLocalData()->HasBaseTypeAsWritten = HasBaseType; 861c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 862c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 863c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TypeLoc getBaseLoc() const { 864c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getInnerTypeLoc(); 865c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 866c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 867bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 868f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis return SourceRange(getLAngleLoc(), getRAngleLoc()); 869f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 870f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 871c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 872ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall setHasBaseTypeAsWritten(true); 873c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall setLAngleLoc(Loc); 874c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall setRAngleLoc(Loc); 875c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (unsigned i = 0, e = getNumProtocols(); i != e; ++i) 876c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall setProtocolLoc(i, Loc); 8774ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 8784ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 87934a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 88054e14c4db764c0636160d26c5bbf491637c83a76John McCall return this->getNumProtocols() * sizeof(SourceLocation); 88154e14c4db764c0636160d26c5bbf491637c83a76John McCall } 882c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 88344ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getExtraLocalDataAlignment() const { 88444ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return llvm::alignOf<SourceLocation>(); 88544ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 88644ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 887c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType getInnerType() const { 888c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getTypePtr()->getBaseType(); 889c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 89054e14c4db764c0636160d26c5bbf491637c83a76John McCall}; 89154e14c4db764c0636160d26c5bbf491637c83a76John McCall 89254e14c4db764c0636160d26c5bbf491637c83a76John McCall 893c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallstruct ObjCInterfaceLocInfo { 89454e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation NameLoc; 8951de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian SourceLocation NameEndLoc; 89654e14c4db764c0636160d26c5bbf491637c83a76John McCall}; 89754e14c4db764c0636160d26c5bbf491637c83a76John McCall 89854e14c4db764c0636160d26c5bbf491637c83a76John McCall/// \brief Wrapper for source info for ObjC interfaces. 899a8bef693d8761e31845a26e136f8d3a0983d2f46Nick Lewyckyclass ObjCInterfaceTypeLoc : public ConcreteTypeLoc<ObjCObjectTypeLoc, 900c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceTypeLoc, 901c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceType, 902c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCInterfaceLocInfo> { 90354e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic: 90454e14c4db764c0636160d26c5bbf491637c83a76John McCall ObjCInterfaceDecl *getIFaceDecl() const { 90554e14c4db764c0636160d26c5bbf491637c83a76John McCall return getTypePtr()->getDecl(); 90654e14c4db764c0636160d26c5bbf491637c83a76John McCall } 90754e14c4db764c0636160d26c5bbf491637c83a76John McCall 90854e14c4db764c0636160d26c5bbf491637c83a76John McCall SourceLocation getNameLoc() const { 90954e14c4db764c0636160d26c5bbf491637c83a76John McCall return getLocalData()->NameLoc; 91054e14c4db764c0636160d26c5bbf491637c83a76John McCall } 91154e14c4db764c0636160d26c5bbf491637c83a76John McCall 91254e14c4db764c0636160d26c5bbf491637c83a76John McCall void setNameLoc(SourceLocation Loc) { 91354e14c4db764c0636160d26c5bbf491637c83a76John McCall getLocalData()->NameLoc = Loc; 91454e14c4db764c0636160d26c5bbf491637c83a76John McCall } 9151de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian 916bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 9171de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian return SourceRange(getNameLoc(), getNameEndLoc()); 9181de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian } 9191de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian 9201de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian SourceLocation getNameEndLoc() const { 9211de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian return getLocalData()->NameEndLoc; 9221de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian } 9231de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian 9241de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian void setNameEndLoc(SourceLocation Loc) { 9251de6a6cb485fb58b4fb100282bb3cf298eedacd9Fariborz Jahanian getLocalData()->NameEndLoc = Loc; 92654e14c4db764c0636160d26c5bbf491637c83a76John McCall } 92754e14c4db764c0636160d26c5bbf491637c83a76John McCall 928c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 92954e14c4db764c0636160d26c5bbf491637c83a76John McCall setNameLoc(Loc); 9306c2fd0d71406c5f311ff00208448a63fa9071453Benjamin Kramer setNameEndLoc(Loc); 931f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis } 93254e14c4db764c0636160d26c5bbf491637c83a76John McCall}; 93354e14c4db764c0636160d26c5bbf491637c83a76John McCall 934075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarastruct ParenLocInfo { 935075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara SourceLocation LParenLoc; 936075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara SourceLocation RParenLoc; 937075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}; 938075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 939075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenTypeLoc 940075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara : public ConcreteTypeLoc<UnqualTypeLoc, ParenTypeLoc, ParenType, 941075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenLocInfo> { 942075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic: 943075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara SourceLocation getLParenLoc() const { 944075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return this->getLocalData()->LParenLoc; 945075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 946075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara SourceLocation getRParenLoc() const { 947075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return this->getLocalData()->RParenLoc; 948075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 949075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void setLParenLoc(SourceLocation Loc) { 950075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara this->getLocalData()->LParenLoc = Loc; 951075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 952075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void setRParenLoc(SourceLocation Loc) { 953075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara this->getLocalData()->RParenLoc = Loc; 954075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 955075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 956075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara SourceRange getLocalSourceRange() const { 957075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return SourceRange(getLParenLoc(), getRParenLoc()); 958075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 959075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 960c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 961075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara setLParenLoc(Loc); 962075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara setRParenLoc(Loc); 963075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 964075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 965075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara TypeLoc getInnerLoc() const { 966075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return getInnerTypeLoc(); 967075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 968075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 969075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType getInnerType() const { 970075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return this->getTypePtr()->getInnerType(); 971075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 972075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}; 973075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 97439e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikieinline TypeLoc TypeLoc::IgnoreParens() const { 97565124fe81f61eed98b845c87e3a78a780f3deb11David Blaikie if (ParenTypeLoc::isKind(*this)) 97639e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie return IgnoreParensImpl(*this); 97739e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie return *this; 97839e6ab4be93d9c5e729a578ddd9d415cd2d49872David Blaikie} 979f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 98012df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner 981651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct AdjustedLocInfo { }; // Nothing. 98212df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner 983651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesclass AdjustedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, AdjustedTypeLoc, 984651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines AdjustedType, AdjustedLocInfo> { 98512df246d6dea2ee1f92c186f922f1afcf499647aReid Klecknerpublic: 98612df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner TypeLoc getOriginalLoc() const { 98712df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner return getInnerTypeLoc(); 98812df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner } 98912df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner 99012df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner void initializeLocal(ASTContext &Context, SourceLocation Loc) { 99112df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner // do nothing 99212df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner } 99312df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner 99412df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner QualType getInnerType() const { 99512df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner // The inner type is the undecayed type, since that's what we have source 99612df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner // location information for. 99712df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner return getTypePtr()->getOriginalType(); 99812df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner } 99912df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner 100012df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner SourceRange getLocalSourceRange() const { 100112df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner return SourceRange(); 100212df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner } 100312df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner 100412df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner unsigned getLocalDataSize() const { 1005651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // sizeof(AdjustedLocInfo) is 1, but we don't need its address to be unique 100612df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner // anyway. TypeLocBuilder can't handle data sizes of 1. 100712df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner return 0; // No data. 100812df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner } 100912df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner}; 101012df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner 1011651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// \brief Wrapper for source info for pointers decayed from arrays and 1012651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// functions. 1013651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesclass DecayedTypeLoc : public InheritingConcreteTypeLoc< 1014651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines AdjustedTypeLoc, DecayedTypeLoc, DecayedType> { 1015651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}; 101612df246d6dea2ee1f92c186f922f1afcf499647aReid Kleckner 101751bd803fbdade51d674598ed45da3d54190a656cJohn McCallstruct PointerLikeLocInfo { 101834a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation StarLoc; 1019f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis}; 1020f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis 1021ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// A base class for 102251bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo> 102351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived, 102451bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeClass, LocalData> { 1025ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 102651bd803fbdade51d674598ed45da3d54190a656cJohn McCall SourceLocation getSigilLoc() const { 102751bd803fbdade51d674598ed45da3d54190a656cJohn McCall return this->getLocalData()->StarLoc; 1028b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 102951bd803fbdade51d674598ed45da3d54190a656cJohn McCall void setSigilLoc(SourceLocation Loc) { 103051bd803fbdade51d674598ed45da3d54190a656cJohn McCall this->getLocalData()->StarLoc = Loc; 1031b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1032b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1033b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getPointeeLoc() const { 103451bd803fbdade51d674598ed45da3d54190a656cJohn McCall return this->getInnerTypeLoc(); 1035b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1036b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1037bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 103851bd803fbdade51d674598ed45da3d54190a656cJohn McCall return SourceRange(getSigilLoc(), getSigilLoc()); 1039b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1040b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1041c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 104251bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 10434ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 10444ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 104551bd803fbdade51d674598ed45da3d54190a656cJohn McCall QualType getInnerType() const { 104651bd803fbdade51d674598ed45da3d54190a656cJohn McCall return this->getTypePtr()->getPointeeType(); 104751bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 104834a0447b8072e0da14c0980597da9d03a1495662John McCall}; 1049b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1050b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 105151bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for pointers. 105251bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc, 105351bd803fbdade51d674598ed45da3d54190a656cJohn McCall PointerType> { 105451bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic: 105551bd803fbdade51d674598ed45da3d54190a656cJohn McCall SourceLocation getStarLoc() const { 105651bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 105751bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 105851bd803fbdade51d674598ed45da3d54190a656cJohn McCall void setStarLoc(SourceLocation Loc) { 105951bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 106051bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 1061b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 1062b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 106351bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1064b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for block pointers. 106551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc, 106651bd803fbdade51d674598ed45da3d54190a656cJohn McCall BlockPointerType> { 1067b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 1068b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getCaretLoc() const { 106951bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 1070b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1071b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setCaretLoc(SourceLocation Loc) { 107251bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 1073b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 107434a0447b8072e0da14c0980597da9d03a1495662John McCall}; 1075b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1076b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnarastruct MemberPointerLocInfo : public PointerLikeLocInfo { 1077b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo *ClassTInfo; 1078b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara}; 1079b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1080b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for member pointers. 108151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc, 1082b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara MemberPointerType, 1083b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara MemberPointerLocInfo> { 1084b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 1085b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getStarLoc() const { 108651bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 1087b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1088b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setStarLoc(SourceLocation Loc) { 108951bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 10904ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 1091b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 1092b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const Type *getClass() const { 1093b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return getTypePtr()->getClass(); 1094b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 1095b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo *getClassTInfo() const { 1096b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return getLocalData()->ClassTInfo; 1097b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 1098b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara void setClassTInfo(TypeSourceInfo* TI) { 1099b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara getLocalData()->ClassTInfo = TI; 1100b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 1101b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 1102b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara void initializeLocal(ASTContext &Context, SourceLocation Loc) { 1103b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara setSigilLoc(Loc); 11046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines setClassTInfo(nullptr); 1105b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 1106b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 1107b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara SourceRange getLocalSourceRange() const { 1108b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (TypeSourceInfo *TI = getClassTInfo()) 1109b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return SourceRange(TI->getTypeLoc().getBeginLoc(), getStarLoc()); 1110b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara else 1111b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return SourceRange(getStarLoc()); 1112b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 111334a0447b8072e0da14c0980597da9d03a1495662John McCall}; 1114b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1115c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Wraps an ObjCPointerType with source location information. 1116c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectPointerTypeLoc : 1117c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall public PointerLikeTypeLoc<ObjCObjectPointerTypeLoc, 1118c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType> { 1119c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic: 1120c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall SourceLocation getStarLoc() const { 1121c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getSigilLoc(); 1122c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 1123c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 1124c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void setStarLoc(SourceLocation Loc) { 1125c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall setSigilLoc(Loc); 1126c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall } 1127c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}; 1128c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 1129b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 113051bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc, 113151bd803fbdade51d674598ed45da3d54190a656cJohn McCall ReferenceType> { 113254e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic: 113354e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType getInnerType() const { 113454e14c4db764c0636160d26c5bbf491637c83a76John McCall return getTypePtr()->getPointeeTypeAsWritten(); 113554e14c4db764c0636160d26c5bbf491637c83a76John McCall } 1136b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 1137b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1138bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallclass LValueReferenceTypeLoc : 1139bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall public InheritingConcreteTypeLoc<ReferenceTypeLoc, 1140bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall LValueReferenceTypeLoc, 1141bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall LValueReferenceType> { 1142b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 1143b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getAmpLoc() const { 114451bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 1145b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1146b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setAmpLoc(SourceLocation Loc) { 114751bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 1148b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 114951bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 1150b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1151bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallclass RValueReferenceTypeLoc : 1152bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall public InheritingConcreteTypeLoc<ReferenceTypeLoc, 1153bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall RValueReferenceTypeLoc, 1154bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall RValueReferenceType> { 115551bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic: 115651bd803fbdade51d674598ed45da3d54190a656cJohn McCall SourceLocation getAmpAmpLoc() const { 115751bd803fbdade51d674598ed45da3d54190a656cJohn McCall return getSigilLoc(); 1158b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 115951bd803fbdade51d674598ed45da3d54190a656cJohn McCall void setAmpAmpLoc(SourceLocation Loc) { 116051bd803fbdade51d674598ed45da3d54190a656cJohn McCall setSigilLoc(Loc); 1161b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 116251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 1163b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1164b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 116534a0447b8072e0da14c0980597da9d03a1495662John McCallstruct FunctionLocInfo { 1166796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara SourceLocation LocalRangeBegin; 116759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation LParenLoc; 116859c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation RParenLoc; 1169796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara SourceLocation LocalRangeEnd; 1170b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 1171b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1172b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for functions. 117351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 117451bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionTypeLoc, 117551bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionType, 117651bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionLocInfo> { 1177b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 1178796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara SourceLocation getLocalRangeBegin() const { 1179796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara return getLocalData()->LocalRangeBegin; 1180b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1181796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara void setLocalRangeBegin(SourceLocation L) { 1182796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara getLocalData()->LocalRangeBegin = L; 1183b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1184b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1185796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara SourceLocation getLocalRangeEnd() const { 1186796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara return getLocalData()->LocalRangeEnd; 1187b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1188796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara void setLocalRangeEnd(SourceLocation L) { 1189796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara getLocalData()->LocalRangeEnd = L; 1190b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1191b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 119259c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation getLParenLoc() const { 119359c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara return this->getLocalData()->LParenLoc; 119459c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara } 119559c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara void setLParenLoc(SourceLocation Loc) { 119659c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara this->getLocalData()->LParenLoc = Loc; 119759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara } 119859c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 119959c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceLocation getRParenLoc() const { 120059c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara return this->getLocalData()->RParenLoc; 120159c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara } 120259c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara void setRParenLoc(SourceLocation Loc) { 120359c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara this->getLocalData()->RParenLoc = Loc; 120459c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara } 120559c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 120659c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara SourceRange getParensRange() const { 120759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara return SourceRange(getLParenLoc(), getRParenLoc()); 120859c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara } 120959c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara 1210ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman ArrayRef<ParmVarDecl *> getParams() const { 1211651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return ArrayRef<ParmVarDecl *>(getParmArray(), getNumParams()); 1212ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman } 1213ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman 1214651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // ParmVarDecls* are stored after Info, one for each parameter. 1215a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **getParmArray() const { 1216a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor return (ParmVarDecl**) getExtraLocalData(); 1217a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor } 1218a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor 1219651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned getNumParams() const { 122034a0447b8072e0da14c0980597da9d03a1495662John McCall if (isa<FunctionNoProtoType>(getTypePtr())) 1221b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return 0; 1222651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return cast<FunctionProtoType>(getTypePtr())->getNumParams(); 1223b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1224651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ParmVarDecl *getParam(unsigned i) const { return getParmArray()[i]; } 1225651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void setParam(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; } 1226b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1227651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines TypeLoc getReturnLoc() const { 122834a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 1229b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1230b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1231bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 1232796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara return SourceRange(getLocalRangeBegin(), getLocalRangeEnd()); 1233b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1234b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1235c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 1236796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara setLocalRangeBegin(Loc); 123759c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara setLParenLoc(Loc); 123859c0a818a79be850f7ae8fdafd57a1710e5b809aAbramo Bagnara setRParenLoc(Loc); 1239796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara setLocalRangeEnd(Loc); 1240651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (unsigned i = 0, e = getNumParams(); i != e; ++i) 12416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines setParam(i, nullptr); 12424ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 12434ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 1244b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// \brief Returns the size of the type source info data block that is 1245b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis /// specific to this type. 124634a0447b8072e0da14c0980597da9d03a1495662John McCall unsigned getExtraLocalDataSize() const { 1247651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return getNumParams() * sizeof(ParmVarDecl *); 1248b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1249b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 125044ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getExtraLocalDataAlignment() const { 125144ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return llvm::alignOf<ParmVarDecl*>(); 125244ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 125344ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 1254651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines QualType getInnerType() const { return getTypePtr()->getReturnType(); } 125534a0447b8072e0da14c0980597da9d03a1495662John McCall}; 125634a0447b8072e0da14c0980597da9d03a1495662John McCall 125751bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionProtoTypeLoc : 125851bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<FunctionTypeLoc, 125951bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionProtoTypeLoc, 126051bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionProtoType> { 126151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 126251bd803fbdade51d674598ed45da3d54190a656cJohn McCall 126351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionNoProtoTypeLoc : 126451bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<FunctionTypeLoc, 126551bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionNoProtoTypeLoc, 126651bd803fbdade51d674598ed45da3d54190a656cJohn McCall FunctionNoProtoType> { 126751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 126851bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1269b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 127034a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ArrayLocInfo { 127134a0447b8072e0da14c0980597da9d03a1495662John McCall SourceLocation LBracketLoc, RBracketLoc; 127234a0447b8072e0da14c0980597da9d03a1495662John McCall Expr *Size; 1273b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 1274b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1275b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for arrays. 127651bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 127751bd803fbdade51d674598ed45da3d54190a656cJohn McCall ArrayTypeLoc, 127851bd803fbdade51d674598ed45da3d54190a656cJohn McCall ArrayType, 127951bd803fbdade51d674598ed45da3d54190a656cJohn McCall ArrayLocInfo> { 1280b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic: 1281b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getLBracketLoc() const { 128234a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->LBracketLoc; 1283b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1284b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setLBracketLoc(SourceLocation Loc) { 128534a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->LBracketLoc = Loc; 1286b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1287b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1288b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis SourceLocation getRBracketLoc() const { 128934a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->RBracketLoc; 1290b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1291b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setRBracketLoc(SourceLocation Loc) { 129234a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->RBracketLoc = Loc; 1293b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1294b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 129585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange getBracketsRange() const { 129685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return SourceRange(getLBracketLoc(), getRBracketLoc()); 129785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 129885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 1299b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis Expr *getSizeExpr() const { 130034a0447b8072e0da14c0980597da9d03a1495662John McCall return getLocalData()->Size; 1301b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1302b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis void setSizeExpr(Expr *Size) { 130334a0447b8072e0da14c0980597da9d03a1495662John McCall getLocalData()->Size = Size; 1304b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1305b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1306b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis TypeLoc getElementLoc() const { 130734a0447b8072e0da14c0980597da9d03a1495662John McCall return getInnerTypeLoc(); 1308b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1309b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1310bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 1311b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return SourceRange(getLBracketLoc(), getRBracketLoc()); 1312b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis } 1313b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1314c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 13154ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setLBracketLoc(Loc); 13164ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall setRBracketLoc(Loc); 13176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines setSizeExpr(nullptr); 13184ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall } 13194ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall 132034a0447b8072e0da14c0980597da9d03a1495662John McCall QualType getInnerType() const { return getTypePtr()->getElementType(); } 1321b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}; 1322b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 132351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ConstantArrayTypeLoc : 132451bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<ArrayTypeLoc, 132551bd803fbdade51d674598ed45da3d54190a656cJohn McCall ConstantArrayTypeLoc, 132651bd803fbdade51d674598ed45da3d54190a656cJohn McCall ConstantArrayType> { 132751bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 132851bd803fbdade51d674598ed45da3d54190a656cJohn McCall 132951bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass IncompleteArrayTypeLoc : 133051bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<ArrayTypeLoc, 133151bd803fbdade51d674598ed45da3d54190a656cJohn McCall IncompleteArrayTypeLoc, 133251bd803fbdade51d674598ed45da3d54190a656cJohn McCall IncompleteArrayType> { 133351bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 133451bd803fbdade51d674598ed45da3d54190a656cJohn McCall 133551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DependentSizedArrayTypeLoc : 133651bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<ArrayTypeLoc, 133751bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedArrayTypeLoc, 133851bd803fbdade51d674598ed45da3d54190a656cJohn McCall DependentSizedArrayType> { 133951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 134051bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 134151bd803fbdade51d674598ed45da3d54190a656cJohn McCall 134251bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass VariableArrayTypeLoc : 134351bd803fbdade51d674598ed45da3d54190a656cJohn McCall public InheritingConcreteTypeLoc<ArrayTypeLoc, 134451bd803fbdade51d674598ed45da3d54190a656cJohn McCall VariableArrayTypeLoc, 134551bd803fbdade51d674598ed45da3d54190a656cJohn McCall VariableArrayType> { 134651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 134751bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1348833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1349833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall// Location information for a TemplateName. Rudimentary for now. 1350833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstruct TemplateNameLocInfo { 1351833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation NameLoc; 1352833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}; 1353833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1354833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstruct TemplateSpecializationLocInfo : TemplateNameLocInfo { 135555d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SourceLocation TemplateKWLoc; 1356833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation LAngleLoc; 1357833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation RAngleLoc; 1358833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}; 1359833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1360833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallclass TemplateSpecializationTypeLoc : 1361833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall public ConcreteTypeLoc<UnqualTypeLoc, 1362833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc, 1363833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationType, 1364833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationLocInfo> { 1365833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallpublic: 136655d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SourceLocation getTemplateKeywordLoc() const { 136755d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara return getLocalData()->TemplateKWLoc; 136855d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara } 136955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara void setTemplateKeywordLoc(SourceLocation Loc) { 137055d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara getLocalData()->TemplateKWLoc = Loc; 137155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara } 137255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara 1373833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation getLAngleLoc() const { 1374833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return getLocalData()->LAngleLoc; 1375833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1376833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void setLAngleLoc(SourceLocation Loc) { 1377833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getLocalData()->LAngleLoc = Loc; 1378833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1379833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1380833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation getRAngleLoc() const { 1381833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return getLocalData()->RAngleLoc; 1382833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1383833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void setRAngleLoc(SourceLocation Loc) { 1384833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getLocalData()->RAngleLoc = Loc; 1385833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1386833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1387833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned getNumArgs() const { 1388833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return getTypePtr()->getNumArgs(); 1389833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1390833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) { 1391833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getArgInfos()[i] = AI; 1392833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1393833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLocInfo getArgLocInfo(unsigned i) const { 1394833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return getArgInfos()[i]; 1395833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1396833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1397833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc getArgLoc(unsigned i) const { 1398833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i)); 1399833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1400833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1401833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation getTemplateNameLoc() const { 1402833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return getLocalData()->NameLoc; 1403833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1404833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void setTemplateNameLoc(SourceLocation Loc) { 1405833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getLocalData()->NameLoc = Loc; 1406833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1407833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1408833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief - Copy the location information from the given info. 1409833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void copy(TemplateSpecializationTypeLoc Loc) { 1410833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned size = getFullDataSize(); 1411833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall assert(size == Loc.getFullDataSize()); 1412833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1413833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // We're potentially copying Expr references here. We don't 1414a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall // bother retaining them because TypeSourceInfos live forever, so 1415833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // as long as the Expr was retained when originally written into 1416833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // the TypeLoc, we're okay. 1417833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall memcpy(Data, Loc.Data, size); 1418833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1419833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1420bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 142155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara if (getTemplateKeywordLoc().isValid()) 142255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara return SourceRange(getTemplateKeywordLoc(), getRAngleLoc()); 142355d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara else 142455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara return SourceRange(getTemplateNameLoc(), getRAngleLoc()); 1425833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1426833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1427c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 142855d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara setTemplateKeywordLoc(Loc); 142955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara setTemplateNameLoc(Loc); 1430833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall setLAngleLoc(Loc); 1431833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall setRAngleLoc(Loc); 1432c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor initializeArgLocs(Context, getNumArgs(), getTypePtr()->getArgs(), 143333500955d731c73717af52088b7fc0e7a85681e7John McCall getArgInfos(), Loc); 143433500955d731c73717af52088b7fc0e7a85681e7John McCall } 1435833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1436c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor static void initializeArgLocs(ASTContext &Context, unsigned NumArgs, 143733500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args, 143833500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgumentLocInfo *ArgInfos, 1439c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor SourceLocation Loc); 1440833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1441833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall unsigned getExtraLocalDataSize() const { 1442833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return getNumArgs() * sizeof(TemplateArgumentLocInfo); 1443833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1444833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 144544ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getExtraLocalDataAlignment() const { 144644ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return llvm::alignOf<TemplateArgumentLocInfo>(); 144744ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 144844ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 1449833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallprivate: 1450833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLocInfo *getArgInfos() const { 1451833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData()); 1452833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 1453833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}; 1454833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1455ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//===----------------------------------------------------------------------===// 1456ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// 1457ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// All of these need proper implementations. 1458ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// 1459ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//===----------------------------------------------------------------------===// 146051bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1461ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: size expression and attribute locations (or keyword if we 1462ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// ever fully support altivec syntax). 1463ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass VectorTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 1464ed97649e9574b9d854fa4d6109c9333ae0993554John McCall VectorTypeLoc, 1465ed97649e9574b9d854fa4d6109c9333ae0993554John McCall VectorType> { 146651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 146751bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1468ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: size expression and attribute locations. 146951bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc, 147051bd803fbdade51d674598ed45da3d54190a656cJohn McCall ExtVectorTypeLoc, 147151bd803fbdade51d674598ed45da3d54190a656cJohn McCall ExtVectorType> { 147251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 147351bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1474ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: attribute locations. 147551bd803fbdade51d674598ed45da3d54190a656cJohn McCall// For some reason, this isn't a subtype of VectorType. 147651bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DependentSizedExtVectorTypeLoc : 1477ed97649e9574b9d854fa4d6109c9333ae0993554John McCall public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 1478ed97649e9574b9d854fa4d6109c9333ae0993554John McCall DependentSizedExtVectorTypeLoc, 1479ed97649e9574b9d854fa4d6109c9333ae0993554John McCall DependentSizedExtVectorType> { 148051bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 148151bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1482ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: location of the '_Complex' keyword. 1483ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass ComplexTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 1484ed97649e9574b9d854fa4d6109c9333ae0993554John McCall ComplexTypeLoc, 1485ed97649e9574b9d854fa4d6109c9333ae0993554John McCall ComplexType> { 148651bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 148751bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1488cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeofLocInfo { 1489cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceLocation TypeofLoc; 1490cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceLocation LParenLoc; 1491cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceLocation RParenLoc; 149251bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 149351bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1494cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeOfExprTypeLocInfo : public TypeofLocInfo { 1495cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall}; 1496cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1497cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeOfTypeLocInfo : public TypeofLocInfo { 1498cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* UnderlyingTInfo; 1499cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall}; 1500cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1501cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCalltemplate <class Derived, class TypeClass, class LocalData = TypeofLocInfo> 1502cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeofLikeTypeLoc 1503cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> { 1504cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic: 1505cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceLocation getTypeofLoc() const { 1506cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall return this->getLocalData()->TypeofLoc; 1507cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1508cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void setTypeofLoc(SourceLocation Loc) { 1509cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall this->getLocalData()->TypeofLoc = Loc; 1510cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1511cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1512cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceLocation getLParenLoc() const { 1513cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall return this->getLocalData()->LParenLoc; 1514cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1515cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void setLParenLoc(SourceLocation Loc) { 1516cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall this->getLocalData()->LParenLoc = Loc; 1517cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1518cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1519cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceLocation getRParenLoc() const { 1520cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall return this->getLocalData()->RParenLoc; 1521cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1522cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void setRParenLoc(SourceLocation Loc) { 1523cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall this->getLocalData()->RParenLoc = Loc; 1524cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1525cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1526cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall SourceRange getParensRange() const { 1527cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall return SourceRange(getLParenLoc(), getRParenLoc()); 1528cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1529cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void setParensRange(SourceRange range) { 1530cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall setLParenLoc(range.getBegin()); 1531cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall setRParenLoc(range.getEnd()); 1532cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1533cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1534bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 1535cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall return SourceRange(getTypeofLoc(), getRParenLoc()); 1536cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1537cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1538c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 1539cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall setTypeofLoc(Loc); 1540cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall setLParenLoc(Loc); 1541cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall setRParenLoc(Loc); 1542cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1543cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall}; 1544cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1545cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeOfExprTypeLoc : public TypeofLikeTypeLoc<TypeOfExprTypeLoc, 1546cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeOfExprType, 1547cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeOfExprTypeLocInfo> { 1548cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic: 1549cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Expr* getUnderlyingExpr() const { 1550cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall return getTypePtr()->getUnderlyingExpr(); 1551cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1552cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall // Reimplemented to account for GNU/C++ extension 1553cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall // typeof unary-expression 1554cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall // where there are no parentheses. 1555bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const; 1556cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall}; 1557cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall 1558cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeOfTypeLoc 1559cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall : public TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo> { 1560cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic: 1561cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall QualType getUnderlyingType() const { 1562cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall return this->getTypePtr()->getUnderlyingType(); 1563cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1564cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* getUnderlyingTInfo() const { 1565cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall return this->getLocalData()->UnderlyingTInfo; 1566cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 1567cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall void setUnderlyingTInfo(TypeSourceInfo* TI) const { 1568cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall this->getLocalData()->UnderlyingTInfo = TI; 1569cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall } 157051bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 157151bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1572ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: location of the 'decltype' and parens. 1573ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 1574ed97649e9574b9d854fa4d6109c9333ae0993554John McCall DecltypeTypeLoc, 1575ed97649e9574b9d854fa4d6109c9333ae0993554John McCall DecltypeType> { 1576427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidispublic: 1577427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidis Expr *getUnderlyingExpr() const { return getTypePtr()->getUnderlyingExpr(); } 157851bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 157951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 1580ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntstruct UnaryTransformTypeLocInfo { 1581ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt // FIXME: While there's only one unary transform right now, future ones may 1582ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt // need different representations 1583ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation KWLoc, LParenLoc, RParenLoc; 1584ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeSourceInfo *UnderlyingTInfo; 1585ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}; 1586ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1587ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntclass UnaryTransformTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 1588ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc, 1589ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType, 1590ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLocInfo> { 1591ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic: 1592ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation getKWLoc() const { return getLocalData()->KWLoc; } 1593ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt void setKWLoc(SourceLocation Loc) { getLocalData()->KWLoc = Loc; } 1594ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1595ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation getLParenLoc() const { return getLocalData()->LParenLoc; } 1596ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt void setLParenLoc(SourceLocation Loc) { getLocalData()->LParenLoc = Loc; } 1597ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1598ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; } 1599ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; } 1600ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1601ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeSourceInfo* getUnderlyingTInfo() const { 1602ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return getLocalData()->UnderlyingTInfo; 1603ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 1604ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt void setUnderlyingTInfo(TypeSourceInfo *TInfo) { 1605ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt getLocalData()->UnderlyingTInfo = TInfo; 1606ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 1607ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1608ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceRange getLocalSourceRange() const { 1609ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return SourceRange(getKWLoc(), getRParenLoc()); 1610ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 1611ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1612ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceRange getParensRange() const { 1613ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return SourceRange(getLParenLoc(), getRParenLoc()); 1614ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 1615ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt void setParensRange(SourceRange Range) { 1616ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt setLParenLoc(Range.getBegin()); 1617ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt setRParenLoc(Range.getEnd()); 1618ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 1619ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1620ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt void initializeLocal(ASTContext &Context, SourceLocation Loc) { 1621ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt setKWLoc(Loc); 1622ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt setRParenLoc(Loc); 1623ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt setLParenLoc(Loc); 1624ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 1625ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}; 1626ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 162734b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, 162834b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc, 162934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType> { 163034b41d939a1328f484511c6002ba2456db879a29Richard Smith}; 163134b41d939a1328f484511c6002ba2456db879a29Richard Smith 1632e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarastruct ElaboratedLocInfo { 163338a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara SourceLocation ElaboratedKWLoc; 163438a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara /// \brief Data associated with the nested-name-specifier location. 16359e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor void *QualifierData; 1636e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara}; 1637e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 1638e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnaraclass ElaboratedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 1639e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc, 1640e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedType, 1641e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedLocInfo> { 1642e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarapublic: 164338a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara SourceLocation getElaboratedKeywordLoc() const { 164438a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara return this->getLocalData()->ElaboratedKWLoc; 1645e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 164638a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara void setElaboratedKeywordLoc(SourceLocation Loc) { 164738a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara this->getLocalData()->ElaboratedKWLoc = Loc; 1648e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1649e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 16509e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 1651ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return NestedNameSpecifierLoc(getTypePtr()->getQualifier(), 16529e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor getLocalData()->QualifierData); 1653e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1654ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16559e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) { 1656ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(QualifierLoc.getNestedNameSpecifier() 16579e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor == getTypePtr()->getQualifier() && 16589e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor "Inconsistent nested-name-specifier pointer"); 16599e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor getLocalData()->QualifierData = QualifierLoc.getOpaqueData(); 1660e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1661e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 1662bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 166338a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara if (getElaboratedKeywordLoc().isValid()) 16649e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (getQualifierLoc()) 166538a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara return SourceRange(getElaboratedKeywordLoc(), 166638a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara getQualifierLoc().getEndLoc()); 1667e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara else 166838a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara return SourceRange(getElaboratedKeywordLoc()); 1669e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara else 16709e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor return getQualifierLoc().getSourceRange(); 1671e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1672e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 16739e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc); 1674e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 1675e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara TypeLoc getNamedTypeLoc() const { 1676e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara return getInnerTypeLoc(); 1677e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1678e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 1679e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType getInnerType() const { 1680e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara return getTypePtr()->getNamedType(); 1681e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1682e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 1683e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara void copy(ElaboratedTypeLoc Loc) { 1684e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara unsigned size = getFullDataSize(); 1685e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara assert(size == Loc.getFullDataSize()); 1686e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara memcpy(Data, Loc.Data, size); 1687e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 168851bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 168951bd803fbdade51d674598ed45da3d54190a656cJohn McCall 169033500955d731c73717af52088b7fc0e7a85681e7John McCall// This is exactly the structure of an ElaboratedTypeLoc whose inner 169133500955d731c73717af52088b7fc0e7a85681e7John McCall// type is some sort of TypeDeclTypeLoc. 169233500955d731c73717af52088b7fc0e7a85681e7John McCallstruct DependentNameLocInfo : ElaboratedLocInfo { 1693e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation NameLoc; 1694e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara}; 1695e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 1696e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnaraclass DependentNameTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 1697e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc, 1698e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameType, 1699e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameLocInfo> { 1700e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarapublic: 170138a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara SourceLocation getElaboratedKeywordLoc() const { 170238a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara return this->getLocalData()->ElaboratedKWLoc; 1703e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 170438a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara void setElaboratedKeywordLoc(SourceLocation Loc) { 170538a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara this->getLocalData()->ElaboratedKWLoc = Loc; 1706e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1707e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 17082494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 1709ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return NestedNameSpecifierLoc(getTypePtr()->getQualifier(), 17102494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor getLocalData()->QualifierData); 1711e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1712ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17132494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) { 1714ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(QualifierLoc.getNestedNameSpecifier() 17152494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor == getTypePtr()->getQualifier() && 17162494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor "Inconsistent nested-name-specifier pointer"); 17172494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor getLocalData()->QualifierData = QualifierLoc.getOpaqueData(); 1718e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1719ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1720e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation getNameLoc() const { 1721e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara return this->getLocalData()->NameLoc; 1722e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1723e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara void setNameLoc(SourceLocation Loc) { 1724e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara this->getLocalData()->NameLoc = Loc; 1725e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1726e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 1727bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara SourceRange getLocalSourceRange() const { 172838a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara if (getElaboratedKeywordLoc().isValid()) 172938a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara return SourceRange(getElaboratedKeywordLoc(), getNameLoc()); 1730e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara else 17312494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SourceRange(getQualifierLoc().getBeginLoc(), getNameLoc()); 1732e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1733e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 1734e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara void copy(DependentNameTypeLoc Loc) { 1735e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara unsigned size = getFullDataSize(); 1736e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara assert(size == Loc.getFullDataSize()); 1737e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara memcpy(Data, Loc.Data, size); 1738e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 1739e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 17402494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc); 174151bd803fbdade51d674598ed45da3d54190a656cJohn McCall}; 174251bd803fbdade51d674598ed45da3d54190a656cJohn McCall 174394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregorstruct DependentTemplateSpecializationLocInfo : DependentNameLocInfo { 174466581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara SourceLocation TemplateKWLoc; 174533500955d731c73717af52088b7fc0e7a85681e7John McCall SourceLocation LAngleLoc; 174633500955d731c73717af52088b7fc0e7a85681e7John McCall SourceLocation RAngleLoc; 174733500955d731c73717af52088b7fc0e7a85681e7John McCall // followed by a TemplateArgumentLocInfo[] 174833500955d731c73717af52088b7fc0e7a85681e7John McCall}; 174933500955d731c73717af52088b7fc0e7a85681e7John McCall 175033500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationTypeLoc : 175133500955d731c73717af52088b7fc0e7a85681e7John McCall public ConcreteTypeLoc<UnqualTypeLoc, 175233500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypeLoc, 175333500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationType, 175433500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationLocInfo> { 175533500955d731c73717af52088b7fc0e7a85681e7John McCallpublic: 175655d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SourceLocation getElaboratedKeywordLoc() const { 175755d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara return this->getLocalData()->ElaboratedKWLoc; 175833500955d731c73717af52088b7fc0e7a85681e7John McCall } 175955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara void setElaboratedKeywordLoc(SourceLocation Loc) { 176055d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara this->getLocalData()->ElaboratedKWLoc = Loc; 176133500955d731c73717af52088b7fc0e7a85681e7John McCall } 176233500955d731c73717af52088b7fc0e7a85681e7John McCall 176394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 176494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (!getLocalData()->QualifierData) 176594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return NestedNameSpecifierLoc(); 1766ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1767ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return NestedNameSpecifierLoc(getTypePtr()->getQualifier(), 176894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor getLocalData()->QualifierData); 176933500955d731c73717af52088b7fc0e7a85681e7John McCall } 1770ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 177194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) { 177294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (!QualifierLoc) { 1773ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie // Even if we have a nested-name-specifier in the dependent 177494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // template specialization type, we won't record the nested-name-specifier 177594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // location information when this type-source location information is 177694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // part of a nested-name-specifier. 17776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines getLocalData()->QualifierData = nullptr; 177894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return; 177994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 1780ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1781ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(QualifierLoc.getNestedNameSpecifier() 178294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor == getTypePtr()->getQualifier() && 178394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor "Inconsistent nested-name-specifier pointer"); 178494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor getLocalData()->QualifierData = QualifierLoc.getOpaqueData(); 178533500955d731c73717af52088b7fc0e7a85681e7John McCall } 178633500955d731c73717af52088b7fc0e7a85681e7John McCall 178766581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 178866581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara return getLocalData()->TemplateKWLoc; 178966581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara } 179066581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara void setTemplateKeywordLoc(SourceLocation Loc) { 179166581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara getLocalData()->TemplateKWLoc = Loc; 179266581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara } 179366581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara 179455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SourceLocation getTemplateNameLoc() const { 179533500955d731c73717af52088b7fc0e7a85681e7John McCall return this->getLocalData()->NameLoc; 179633500955d731c73717af52088b7fc0e7a85681e7John McCall } 179755d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara void setTemplateNameLoc(SourceLocation Loc) { 179833500955d731c73717af52088b7fc0e7a85681e7John McCall this->getLocalData()->NameLoc = Loc; 179933500955d731c73717af52088b7fc0e7a85681e7John McCall } 180033500955d731c73717af52088b7fc0e7a85681e7John McCall 180133500955d731c73717af52088b7fc0e7a85681e7John McCall SourceLocation getLAngleLoc() const { 180233500955d731c73717af52088b7fc0e7a85681e7John McCall return this->getLocalData()->LAngleLoc; 180333500955d731c73717af52088b7fc0e7a85681e7John McCall } 180433500955d731c73717af52088b7fc0e7a85681e7John McCall void setLAngleLoc(SourceLocation Loc) { 180533500955d731c73717af52088b7fc0e7a85681e7John McCall this->getLocalData()->LAngleLoc = Loc; 180633500955d731c73717af52088b7fc0e7a85681e7John McCall } 180733500955d731c73717af52088b7fc0e7a85681e7John McCall 180833500955d731c73717af52088b7fc0e7a85681e7John McCall SourceLocation getRAngleLoc() const { 180933500955d731c73717af52088b7fc0e7a85681e7John McCall return this->getLocalData()->RAngleLoc; 181033500955d731c73717af52088b7fc0e7a85681e7John McCall } 181133500955d731c73717af52088b7fc0e7a85681e7John McCall void setRAngleLoc(SourceLocation Loc) { 181233500955d731c73717af52088b7fc0e7a85681e7John McCall this->getLocalData()->RAngleLoc = Loc; 181333500955d731c73717af52088b7fc0e7a85681e7John McCall } 181433500955d731c73717af52088b7fc0e7a85681e7John McCall 181533500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned getNumArgs() const { 181633500955d731c73717af52088b7fc0e7a85681e7John McCall return getTypePtr()->getNumArgs(); 181733500955d731c73717af52088b7fc0e7a85681e7John McCall } 181833500955d731c73717af52088b7fc0e7a85681e7John McCall 181933500955d731c73717af52088b7fc0e7a85681e7John McCall void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) { 182033500955d731c73717af52088b7fc0e7a85681e7John McCall getArgInfos()[i] = AI; 182133500955d731c73717af52088b7fc0e7a85681e7John McCall } 182233500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgumentLocInfo getArgLocInfo(unsigned i) const { 182333500955d731c73717af52088b7fc0e7a85681e7John McCall return getArgInfos()[i]; 182433500955d731c73717af52088b7fc0e7a85681e7John McCall } 182533500955d731c73717af52088b7fc0e7a85681e7John McCall 182633500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgumentLoc getArgLoc(unsigned i) const { 182733500955d731c73717af52088b7fc0e7a85681e7John McCall return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i)); 182833500955d731c73717af52088b7fc0e7a85681e7John McCall } 182933500955d731c73717af52088b7fc0e7a85681e7John McCall 183033500955d731c73717af52088b7fc0e7a85681e7John McCall SourceRange getLocalSourceRange() const { 183155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara if (getElaboratedKeywordLoc().isValid()) 183255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara return SourceRange(getElaboratedKeywordLoc(), getRAngleLoc()); 183394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor else if (getQualifierLoc()) 183494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SourceRange(getQualifierLoc().getBeginLoc(), getRAngleLoc()); 183566581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara else if (getTemplateKeywordLoc().isValid()) 183666581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara return SourceRange(getTemplateKeywordLoc(), getRAngleLoc()); 18379e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor else 183855d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara return SourceRange(getTemplateNameLoc(), getRAngleLoc()); 183933500955d731c73717af52088b7fc0e7a85681e7John McCall } 184033500955d731c73717af52088b7fc0e7a85681e7John McCall 184133500955d731c73717af52088b7fc0e7a85681e7John McCall void copy(DependentTemplateSpecializationTypeLoc Loc) { 184233500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned size = getFullDataSize(); 184333500955d731c73717af52088b7fc0e7a85681e7John McCall assert(size == Loc.getFullDataSize()); 184433500955d731c73717af52088b7fc0e7a85681e7John McCall memcpy(Data, Loc.Data, size); 184533500955d731c73717af52088b7fc0e7a85681e7John McCall } 184633500955d731c73717af52088b7fc0e7a85681e7John McCall 184794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc); 184833500955d731c73717af52088b7fc0e7a85681e7John McCall 184933500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned getExtraLocalDataSize() const { 185033500955d731c73717af52088b7fc0e7a85681e7John McCall return getNumArgs() * sizeof(TemplateArgumentLocInfo); 185133500955d731c73717af52088b7fc0e7a85681e7John McCall } 185233500955d731c73717af52088b7fc0e7a85681e7John McCall 185344ee0a710c59d8e6793189f903bae21c16814324Eli Friedman unsigned getExtraLocalDataAlignment() const { 185444ee0a710c59d8e6793189f903bae21c16814324Eli Friedman return llvm::alignOf<TemplateArgumentLocInfo>(); 185544ee0a710c59d8e6793189f903bae21c16814324Eli Friedman } 185644ee0a710c59d8e6793189f903bae21c16814324Eli Friedman 185733500955d731c73717af52088b7fc0e7a85681e7John McCallprivate: 185833500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgumentLocInfo *getArgInfos() const { 185933500955d731c73717af52088b7fc0e7a85681e7John McCall return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData()); 186033500955d731c73717af52088b7fc0e7a85681e7John McCall } 186133500955d731c73717af52088b7fc0e7a85681e7John McCall}; 186233500955d731c73717af52088b7fc0e7a85681e7John McCall 18637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 18647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorstruct PackExpansionTypeLocInfo { 18657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor SourceLocation EllipsisLoc; 18667536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}; 18677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 18687536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionTypeLoc 1869ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : public ConcreteTypeLoc<UnqualTypeLoc, PackExpansionTypeLoc, 18707536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionType, PackExpansionTypeLocInfo> { 18717536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic: 18727536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor SourceLocation getEllipsisLoc() const { 18737536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return this->getLocalData()->EllipsisLoc; 18747536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 18757536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 18767536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor void setEllipsisLoc(SourceLocation Loc) { 18777536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor this->getLocalData()->EllipsisLoc = Loc; 18787536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 18797536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 18807536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor SourceRange getLocalSourceRange() const { 18817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return SourceRange(getEllipsisLoc(), getEllipsisLoc()); 18827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 18837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 1884c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor void initializeLocal(ASTContext &Context, SourceLocation Loc) { 18857536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor setEllipsisLoc(Loc); 18867536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 18877536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 18887536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor TypeLoc getPatternLoc() const { 18897536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return getInnerTypeLoc(); 18907536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 18917536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 18927536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType getInnerType() const { 18937536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return this->getTypePtr()->getPattern(); 18947536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 18957536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}; 18967536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 1897b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanstruct AtomicTypeLocInfo { 1898b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation KWLoc, LParenLoc, RParenLoc; 1899b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}; 1900b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1901b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanclass AtomicTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, AtomicTypeLoc, 1902b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType, AtomicTypeLocInfo> { 1903ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 1904b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman TypeLoc getValueLoc() const { 1905b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return this->getInnerTypeLoc(); 1906b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1907b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1908b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceRange getLocalSourceRange() const { 1909b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return SourceRange(getKWLoc(), getRParenLoc()); 1910b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1911b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1912b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation getKWLoc() const { 1913b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return this->getLocalData()->KWLoc; 1914b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1915b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void setKWLoc(SourceLocation Loc) { 1916b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman this->getLocalData()->KWLoc = Loc; 1917b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1918b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1919b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation getLParenLoc() const { 1920b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return this->getLocalData()->LParenLoc; 1921b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1922b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void setLParenLoc(SourceLocation Loc) { 1923b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman this->getLocalData()->LParenLoc = Loc; 1924b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1925b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1926b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation getRParenLoc() const { 1927b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return this->getLocalData()->RParenLoc; 1928b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1929b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void setRParenLoc(SourceLocation Loc) { 1930b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman this->getLocalData()->RParenLoc = Loc; 1931b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1932b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1933b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceRange getParensRange() const { 1934b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return SourceRange(getLParenLoc(), getRParenLoc()); 1935b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1936b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void setParensRange(SourceRange Range) { 1937b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman setLParenLoc(Range.getBegin()); 1938b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman setRParenLoc(Range.getEnd()); 1939b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1940b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1941b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void initializeLocal(ASTContext &Context, SourceLocation Loc) { 1942b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman setKWLoc(Loc); 1943b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman setLParenLoc(Loc); 1944b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman setRParenLoc(Loc); 1945b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1946b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1947b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType getInnerType() const { 1948b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return this->getTypePtr()->getValueType(); 1949b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1950b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}; 1951b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1952b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1953b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 1954b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1955b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#endif 1956