TypeLoc.h revision ec9ea7200718478e8a976529defbe21942a11c9c
1b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//===--- TypeLoc.h - Type Source Info Wrapper -------------------*- C++ -*-===//
2b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//
3b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//                     The LLVM Compiler Infrastructure
4b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//
5b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// This file is distributed under the University of Illinois Open Source
6b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis// License. See LICENSE.TXT for details.
7b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//
8b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//===----------------------------------------------------------------------===//
9b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//
10b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//  This file defines the TypeLoc interface and subclasses.
11b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//
12b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis//===----------------------------------------------------------------------===//
13b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
14b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#ifndef LLVM_CLANG_AST_TYPELOC_H
15b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#define LLVM_CLANG_AST_TYPELOC_H
16b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
17b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#include "clang/AST/Type.h"
183c385c28cf1f27b193a620d2e51f814873362cebJohn McCall#include "clang/AST/Decl.h"
19833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall#include "clang/AST/TemplateBase.h"
20ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor#include "clang/Basic/Specifiers.h"
21b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
22b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisnamespace clang {
23c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  class ASTContext;
24b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  class ParmVarDecl;
25a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  class TypeSourceInfo;
2634a0447b8072e0da14c0980597da9d03a1495662John McCall  class UnqualTypeLoc;
27b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
2851bd803fbdade51d674598ed45da3d54190a656cJohn McCall// Predeclare all the type nodes.
2951bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPELOC(Class, Base)
3051bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define TYPELOC(Class, Base) \
3151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  class Class##TypeLoc;
3251bd803fbdade51d674598ed45da3d54190a656cJohn McCall#include "clang/AST/TypeLocNodes.def"
3351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
34b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Base wrapper for a particular "section" of type source info.
35b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis///
36b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// A client should use the TypeLoc subclasses through cast/dyn_cast in order to
37b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// get at the actual information.
38b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisclass TypeLoc {
39b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidisprotected:
4034a0447b8072e0da14c0980597da9d03a1495662John McCall  // The correctness of this relies on the property that, for Type *Ty,
4134a0447b8072e0da14c0980597da9d03a1495662John McCall  //   QualType(Ty, 0).getAsOpaquePtr() == (void*) Ty
42f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const void *Ty;
43b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void *Data;
441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
4651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  /// The kinds of TypeLocs.  Equivalent to the Type::TypeClass enum,
4751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  /// except it also defines a Qualified enum that corresponds to the
4851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  /// QualifiedLoc class.
4951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  enum TypeLocClass {
5051bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define ABSTRACT_TYPE(Class, Base)
5151bd803fbdade51d674598ed45da3d54190a656cJohn McCall#define TYPE(Class, Base) \
5251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    Class = Type::Class,
5351bd803fbdade51d674598ed45da3d54190a656cJohn McCall#include "clang/AST/TypeNodes.def"
5451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    Qualified
5551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  };
5651bd803fbdade51d674598ed45da3d54190a656cJohn McCall
5734a0447b8072e0da14c0980597da9d03a1495662John McCall  TypeLoc() : Ty(0), Data(0) { }
5834a0447b8072e0da14c0980597da9d03a1495662John McCall  TypeLoc(QualType ty, void *opaqueData)
5934a0447b8072e0da14c0980597da9d03a1495662John McCall    : Ty(ty.getAsOpaquePtr()), Data(opaqueData) { }
60f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  TypeLoc(const Type *ty, void *opaqueData)
6134a0447b8072e0da14c0980597da9d03a1495662John McCall    : Ty(ty), Data(opaqueData) { }
62b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
6351bd803fbdade51d674598ed45da3d54190a656cJohn McCall  TypeLocClass getTypeLocClass() const {
64a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (getType().hasLocalQualifiers()) return Qualified;
6551bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return (TypeLocClass) getType()->getTypeClass();
6651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
6751bd803fbdade51d674598ed45da3d54190a656cJohn McCall
6834a0447b8072e0da14c0980597da9d03a1495662John McCall  bool isNull() const { return !Ty; }
6934a0447b8072e0da14c0980597da9d03a1495662John McCall  operator bool() const { return Ty; }
70b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
71b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// \brief Returns the size of type source info data block for the given type.
72b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  static unsigned getFullDataSizeForType(QualType Ty);
73b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
74b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// \brief Get the type for which this source info wrapper provides
75b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// information.
7651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  QualType getType() const {
7751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return QualType::getFromOpaquePtr(Ty);
7851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
7934a0447b8072e0da14c0980597da9d03a1495662John McCall
80f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *getTypePtr() const {
8134a0447b8072e0da14c0980597da9d03a1495662John McCall    return QualType::getFromOpaquePtr(Ty).getTypePtr();
8234a0447b8072e0da14c0980597da9d03a1495662John McCall  }
83b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
84b735471f3848065120d7210e557b5f0d37ed4c43Argyrios Kyrtzidis  /// \brief Get the pointer where source information is stored.
8551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void *getOpaqueData() const {
8651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return Data;
8751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
88b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
89e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara  /// \brief Get the begin source location.
90e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara  SourceLocation getBeginLoc() const;
91e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara
92e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara  /// \brief Get the end source location.
93e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara  SourceLocation getEndLoc() const;
94e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara
95833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Get the full source range.
96bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getSourceRange() const {
97e4aec0eae303e926643c7239cf7b0197ea9f63e2Abramo Bagnara    return SourceRange(getBeginLoc(), getEndLoc());
98833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
99833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
100833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Get the local source range.
101bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
102bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara    return getLocalSourceRangeImpl(*this);
10351bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
104b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
105b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// \brief Returns the size of the type source info data block.
10634a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getFullDataSize() const {
10751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getFullDataSizeForType(getType());
10834a0447b8072e0da14c0980597da9d03a1495662John McCall  }
109b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
110b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// \brief Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the
111b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// TypeLoc is a PointerLoc and next TypeLoc is for "int".
11251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  TypeLoc getNextTypeLoc() const {
11351bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getNextTypeLocImpl(*this);
11451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
115b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
11634a0447b8072e0da14c0980597da9d03a1495662John McCall  /// \brief Skips past any qualifiers, if this is qualified.
11751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header
11834a0447b8072e0da14c0980597da9d03a1495662John McCall
119723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara  TypeLoc IgnoreParens() const {
120723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    if (isa<ParenTypeLoc>(this))
121723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara      return IgnoreParensImpl(*this);
122723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    return *this;
123723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara  }
124140a2bd77539b4537010d8cd6a0a3805ce724b3eAbramo Bagnara
1254ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  /// \brief Initializes this to state that every location in this
1264ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  /// type is the given location.
1274ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  ///
1284ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  /// This method exists to provide a simple transition for code that
1294ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  /// relies on location-less types.
130c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initialize(ASTContext &Context, SourceLocation Loc) const {
131c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor    initializeImpl(Context, *this, Loc);
1324ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
1334ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
13445ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein  /// \brief Initializes this by copying its information from another
13545ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein  /// TypeLoc of the same type.
13645ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein  void initializeFullCopy(TypeLoc Other) const {
137711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    assert(getType() == Other.getType());
138711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    size_t Size = getFullDataSize();
139711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    memcpy(getOpaqueData(), Other.getOpaqueData(), Size);
140711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  }
141711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
142711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  /// \brief Initializes this by copying its information from another
143711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  /// TypeLoc of the same type.  The given size must be the full data
144711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  /// size.
145711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  void initializeFullCopy(TypeLoc Other, unsigned Size) const {
146711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    assert(getType() == Other.getType());
147711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    assert(getFullDataSize() == Size);
148711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    memcpy(getOpaqueData(), Other.getOpaqueData(), Size);
14945ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein  }
15045ab4b5f8961dadcef6545ed6956da5daf95c6cbCraig Silverstein
151b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) {
152b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis    return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data;
153b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
154b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
155b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  friend bool operator!=(const TypeLoc &LHS, const TypeLoc &RHS) {
156b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis    return !(LHS == RHS);
157b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
158b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
159b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  static bool classof(const TypeLoc *TL) { return true; }
1604ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
1614ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCallprivate:
162ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static void initializeImpl(ASTContext &Context, TypeLoc TL,
163ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                             SourceLocation Loc);
16451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static TypeLoc getNextTypeLocImpl(TypeLoc TL);
165723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara  static TypeLoc IgnoreParensImpl(TypeLoc TL);
166bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
167b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
168b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1693c385c28cf1f27b193a620d2e51f814873362cebJohn McCall/// \brief Return the TypeLoc for a type source info.
1703c385c28cf1f27b193a620d2e51f814873362cebJohn McCallinline TypeLoc TypeSourceInfo::getTypeLoc() const {
1714ab92891a53adda8c52c1947351371da58e33f64Gabor Greif  return TypeLoc(Ty, const_cast<void*>(static_cast<const void*>(this + 1)));
1723c385c28cf1f27b193a620d2e51f814873362cebJohn McCall}
1733c385c28cf1f27b193a620d2e51f814873362cebJohn McCall
17434a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with
175489f7131d0f7746525de3b26204c8eb523d84505Gabor Greif/// no direct qualifiers.
17634a0447b8072e0da14c0980597da9d03a1495662John McCallclass UnqualTypeLoc : public TypeLoc {
17734a0447b8072e0da14c0980597da9d03a1495662John McCallpublic:
17834a0447b8072e0da14c0980597da9d03a1495662John McCall  UnqualTypeLoc() {}
179f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  UnqualTypeLoc(const Type *Ty, void *Data) : TypeLoc(Ty, Data) {}
18034a0447b8072e0da14c0980597da9d03a1495662John McCall
181f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *getTypePtr() const {
182f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    return reinterpret_cast<const Type*>(Ty);
18334a0447b8072e0da14c0980597da9d03a1495662John McCall  }
18434a0447b8072e0da14c0980597da9d03a1495662John McCall
18551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  TypeLocClass getTypeLocClass() const {
18651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return (TypeLocClass) getTypePtr()->getTypeClass();
18751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
18851bd803fbdade51d674598ed45da3d54190a656cJohn McCall
18934a0447b8072e0da14c0980597da9d03a1495662John McCall  static bool classof(const TypeLoc *TL) {
190a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return !TL->getType().hasLocalQualifiers();
19134a0447b8072e0da14c0980597da9d03a1495662John McCall  }
19234a0447b8072e0da14c0980597da9d03a1495662John McCall  static bool classof(const UnqualTypeLoc *TL) { return true; }
19334a0447b8072e0da14c0980597da9d03a1495662John McCall};
19434a0447b8072e0da14c0980597da9d03a1495662John McCall
19534a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with
19634a0447b8072e0da14c0980597da9d03a1495662John McCall/// non-trivial direct qualifiers.
19734a0447b8072e0da14c0980597da9d03a1495662John McCall///
19834a0447b8072e0da14c0980597da9d03a1495662John McCall/// Currently, we intentionally do not provide source location for
19934a0447b8072e0da14c0980597da9d03a1495662John McCall/// type qualifiers.
20051bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass QualifiedTypeLoc : public TypeLoc {
20134a0447b8072e0da14c0980597da9d03a1495662John McCallpublic:
202bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
20334a0447b8072e0da14c0980597da9d03a1495662John McCall    return SourceRange();
20434a0447b8072e0da14c0980597da9d03a1495662John McCall  }
20534a0447b8072e0da14c0980597da9d03a1495662John McCall
20634a0447b8072e0da14c0980597da9d03a1495662John McCall  UnqualTypeLoc getUnqualifiedLoc() const {
20751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return UnqualTypeLoc(getTypePtr(), Data);
20834a0447b8072e0da14c0980597da9d03a1495662John McCall  }
20934a0447b8072e0da14c0980597da9d03a1495662John McCall
2104ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  /// Initializes the local data of this type source info block to
2114ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  /// provide no information.
212c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2134ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    // do nothing
2144ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
2154ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
2164ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  TypeLoc getNextTypeLoc() const {
2174ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    return getUnqualifiedLoc();
2184ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
2194ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
22034a0447b8072e0da14c0980597da9d03a1495662John McCall  /// \brief Returns the size of the type source info data block that is
22134a0447b8072e0da14c0980597da9d03a1495662John McCall  /// specific to this type.
22234a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getLocalDataSize() const {
22334a0447b8072e0da14c0980597da9d03a1495662John McCall    // In fact, we don't currently preserve any location information
22434a0447b8072e0da14c0980597da9d03a1495662John McCall    // for qualifiers.
22534a0447b8072e0da14c0980597da9d03a1495662John McCall    return 0;
22634a0447b8072e0da14c0980597da9d03a1495662John McCall  }
22734a0447b8072e0da14c0980597da9d03a1495662John McCall
22834a0447b8072e0da14c0980597da9d03a1495662John McCall  /// \brief Returns the size of the type source info data block.
22934a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getFullDataSize() const {
230ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getLocalDataSize() +
231fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      getFullDataSizeForType(getType().getLocalUnqualifiedType());
23234a0447b8072e0da14c0980597da9d03a1495662John McCall  }
23334a0447b8072e0da14c0980597da9d03a1495662John McCall
23434a0447b8072e0da14c0980597da9d03a1495662John McCall  static bool classof(const TypeLoc *TL) {
235a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return TL->getType().hasLocalQualifiers();
23634a0447b8072e0da14c0980597da9d03a1495662John McCall  }
23751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static bool classof(const QualifiedTypeLoc *TL) { return true; }
23834a0447b8072e0da14c0980597da9d03a1495662John McCall};
23934a0447b8072e0da14c0980597da9d03a1495662John McCall
24034a0447b8072e0da14c0980597da9d03a1495662John McCallinline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {
24151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  if (isa<QualifiedTypeLoc>(this))
24251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return cast<QualifiedTypeLoc>(this)->getUnqualifiedLoc();
24334a0447b8072e0da14c0980597da9d03a1495662John McCall  return cast<UnqualTypeLoc>(*this);
24434a0447b8072e0da14c0980597da9d03a1495662John McCall}
24534a0447b8072e0da14c0980597da9d03a1495662John McCall
24634a0447b8072e0da14c0980597da9d03a1495662John McCall/// A metaprogramming base class for TypeLoc classes which correspond
247f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// to a particular Type subclass.  It is accepted for a single
248f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// TypeLoc class to correspond to multiple Type classes.
24934a0447b8072e0da14c0980597da9d03a1495662John McCall///
25034a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param Base a class from which to derive
25134a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param Derived the class deriving from this one
252f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// \param TypeClass the concrete Type subclass associated with this
253f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall///   location type
25434a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param LocalData the structure type of local location data for
25534a0447b8072e0da14c0980597da9d03a1495662John McCall///   this type
25634a0447b8072e0da14c0980597da9d03a1495662John McCall///
25734a0447b8072e0da14c0980597da9d03a1495662John McCall/// sizeof(LocalData) needs to be a multiple of sizeof(void*) or
25834a0447b8072e0da14c0980597da9d03a1495662John McCall/// else the world will end.
25934a0447b8072e0da14c0980597da9d03a1495662John McCall///
26034a0447b8072e0da14c0980597da9d03a1495662John McCall/// TypeLocs with non-constant amounts of local data should override
26134a0447b8072e0da14c0980597da9d03a1495662John McCall/// getExtraLocalDataSize(); getExtraLocalData() will then point to
26234a0447b8072e0da14c0980597da9d03a1495662John McCall/// this extra memory.
26334a0447b8072e0da14c0980597da9d03a1495662John McCall///
264a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// TypeLocs with an inner type should define
265a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall///   QualType getInnerType() const
266a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// and getInnerTypeLoc() will then point to this inner type's
267a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// location data.
26851bd803fbdade51d674598ed45da3d54190a656cJohn McCall///
26951bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A word about hierarchies: this template is not designed to be
27051bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// derived from multiple times in a hierarchy.  It is also not
27151bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// designed to be used for classes where subtypes might provide
27251bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// different amounts of source information.  It should be subclassed
27351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// only at the deepest portion of the hierarchy where all children
27451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// have identical source information; if that's an abstract type,
27551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// then further descendents should inherit from
27651bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// InheritingConcreteTypeLoc instead.
27734a0447b8072e0da14c0980597da9d03a1495662John McCalltemplate <class Base, class Derived, class TypeClass, class LocalData>
27834a0447b8072e0da14c0980597da9d03a1495662John McCallclass ConcreteTypeLoc : public Base {
27934a0447b8072e0da14c0980597da9d03a1495662John McCall
28034a0447b8072e0da14c0980597da9d03a1495662John McCall  const Derived *asDerived() const {
28134a0447b8072e0da14c0980597da9d03a1495662John McCall    return static_cast<const Derived*>(this);
28234a0447b8072e0da14c0980597da9d03a1495662John McCall  }
28334a0447b8072e0da14c0980597da9d03a1495662John McCall
28434a0447b8072e0da14c0980597da9d03a1495662John McCallpublic:
28534a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getLocalDataSize() const {
28634a0447b8072e0da14c0980597da9d03a1495662John McCall    return sizeof(LocalData) + asDerived()->getExtraLocalDataSize();
28734a0447b8072e0da14c0980597da9d03a1495662John McCall  }
28834a0447b8072e0da14c0980597da9d03a1495662John McCall  // Give a default implementation that's useful for leaf types.
28934a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getFullDataSize() const {
29034a0447b8072e0da14c0980597da9d03a1495662John McCall    return asDerived()->getLocalDataSize() + getInnerTypeSize();
29134a0447b8072e0da14c0980597da9d03a1495662John McCall  }
29234a0447b8072e0da14c0980597da9d03a1495662John McCall
29334a0447b8072e0da14c0980597da9d03a1495662John McCall  static bool classofType(const Type *Ty) {
29434a0447b8072e0da14c0980597da9d03a1495662John McCall    return TypeClass::classof(Ty);
29534a0447b8072e0da14c0980597da9d03a1495662John McCall  }
29634a0447b8072e0da14c0980597da9d03a1495662John McCall
297e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  static bool classof(const TypeLoc *TL) {
298e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return Derived::classofType(TL->getTypePtr());
299e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
300e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  static bool classof(const UnqualTypeLoc *TL) {
301e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return Derived::classofType(TL->getTypePtr());
302e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
303e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  static bool classof(const Derived *TL) {
304e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return true;
305e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
306e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
3074ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  TypeLoc getNextTypeLoc() const {
3084ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    return getNextTypeLoc(asDerived()->getInnerType());
3094ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
3104ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
311f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypeClass *getTypePtr() const {
31251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return cast<TypeClass>(Base::getTypePtr());
31334a0447b8072e0da14c0980597da9d03a1495662John McCall  }
31434a0447b8072e0da14c0980597da9d03a1495662John McCall
31551bd803fbdade51d674598ed45da3d54190a656cJohn McCallprotected:
31634a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getExtraLocalDataSize() const {
31734a0447b8072e0da14c0980597da9d03a1495662John McCall    return 0;
31834a0447b8072e0da14c0980597da9d03a1495662John McCall  }
31934a0447b8072e0da14c0980597da9d03a1495662John McCall
32034a0447b8072e0da14c0980597da9d03a1495662John McCall  LocalData *getLocalData() const {
32134a0447b8072e0da14c0980597da9d03a1495662John McCall    return static_cast<LocalData*>(Base::Data);
32234a0447b8072e0da14c0980597da9d03a1495662John McCall  }
32334a0447b8072e0da14c0980597da9d03a1495662John McCall
32434a0447b8072e0da14c0980597da9d03a1495662John McCall  /// Gets a pointer past the Info structure; useful for classes with
32534a0447b8072e0da14c0980597da9d03a1495662John McCall  /// local data that can't be captured in the Info (e.g. because it's
32634a0447b8072e0da14c0980597da9d03a1495662John McCall  /// of variable size).
32734a0447b8072e0da14c0980597da9d03a1495662John McCall  void *getExtraLocalData() const {
32834a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData() + 1;
32934a0447b8072e0da14c0980597da9d03a1495662John McCall  }
330ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
33134a0447b8072e0da14c0980597da9d03a1495662John McCall  void *getNonLocalData() const {
33234a0447b8072e0da14c0980597da9d03a1495662John McCall    return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize();
33334a0447b8072e0da14c0980597da9d03a1495662John McCall  }
33434a0447b8072e0da14c0980597da9d03a1495662John McCall
335a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  struct HasNoInnerType {};
336a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  HasNoInnerType getInnerType() const { return HasNoInnerType(); }
33734a0447b8072e0da14c0980597da9d03a1495662John McCall
33834a0447b8072e0da14c0980597da9d03a1495662John McCall  TypeLoc getInnerTypeLoc() const {
33934a0447b8072e0da14c0980597da9d03a1495662John McCall    return TypeLoc(asDerived()->getInnerType(), getNonLocalData());
34034a0447b8072e0da14c0980597da9d03a1495662John McCall  }
34134a0447b8072e0da14c0980597da9d03a1495662John McCall
34234a0447b8072e0da14c0980597da9d03a1495662John McCallprivate:
34334a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getInnerTypeSize() const {
344a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall    return getInnerTypeSize(asDerived()->getInnerType());
345a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  }
346a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall
347a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  unsigned getInnerTypeSize(HasNoInnerType _) const {
34834a0447b8072e0da14c0980597da9d03a1495662John McCall    return 0;
34934a0447b8072e0da14c0980597da9d03a1495662John McCall  }
35034a0447b8072e0da14c0980597da9d03a1495662John McCall
351a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  unsigned getInnerTypeSize(QualType _) const {
352a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall    return getInnerTypeLoc().getFullDataSize();
35334a0447b8072e0da14c0980597da9d03a1495662John McCall  }
3544ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
3554ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  TypeLoc getNextTypeLoc(HasNoInnerType _) const {
3564ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    return TypeLoc();
3574ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
3584ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
3594ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  TypeLoc getNextTypeLoc(QualType T) const {
3604ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    return TypeLoc(T, getNonLocalData());
3614ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
36234a0447b8072e0da14c0980597da9d03a1495662John McCall};
36334a0447b8072e0da14c0980597da9d03a1495662John McCall
36451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A metaprogramming class designed for concrete subtypes of abstract
36551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// types where all subtypes share equivalently-structured source
36651bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// information.  See the note on ConcreteTypeLoc.
36751bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Base, class Derived, class TypeClass>
36851bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass InheritingConcreteTypeLoc : public Base {
369b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
370713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor  static bool classofType(const Type *Ty) {
371713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor    return TypeClass::classof(Ty);
372713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor  }
373713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor
37451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static bool classof(const TypeLoc *TL) {
37551bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return Derived::classofType(TL->getTypePtr());
376b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
37751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static bool classof(const UnqualTypeLoc *TL) {
37851bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return Derived::classofType(TL->getTypePtr());
379b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
38051bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static bool classof(const Derived *TL) {
38151bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return true;
382b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
383b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
384f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypeClass *getTypePtr() const {
38551bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return cast<TypeClass>(Base::getTypePtr());
3864ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
38734a0447b8072e0da14c0980597da9d03a1495662John McCall};
388b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
389ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
39051bd803fbdade51d674598ed45da3d54190a656cJohn McCallstruct TypeSpecLocInfo {
39134a0447b8072e0da14c0980597da9d03a1495662John McCall  SourceLocation NameLoc;
392b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
393b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
39451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief A reasonable base class for TypeLocs that correspond to
39551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// types that are written as a type-specifier.
396ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikieclass TypeSpecTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
397ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                               TypeSpecTypeLoc,
398ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                               Type,
399ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                               TypeSpecLocInfo> {
400b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
401ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  enum { LocalDataSize = sizeof(TypeSpecLocInfo) };
402ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
403b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getNameLoc() const {
40451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return this->getLocalData()->NameLoc;
405b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
406b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setNameLoc(SourceLocation Loc) {
40751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    this->getLocalData()->NameLoc = Loc;
408b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
409bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
410b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis    return SourceRange(getNameLoc(), getNameLoc());
411b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
412c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
4134ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setNameLoc(Loc);
4144ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
415ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
416ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const TypeLoc *TL);
417ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const TypeSpecTypeLoc *TL) { return true; }
41851bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
4194ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
420ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
421ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorstruct BuiltinLocInfo {
422ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  SourceLocation BuiltinLoc;
423ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor};
424ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
425ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor/// \brief Wrapper for source info for builtin types.
426ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorclass BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
427ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor                                              BuiltinTypeLoc,
428ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor                                              BuiltinType,
429ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor                                              BuiltinLocInfo> {
430ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorpublic:
431ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  enum { LocalDataSize = sizeof(BuiltinLocInfo) };
432ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
433ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  SourceLocation getBuiltinLoc() const {
434ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return getLocalData()->BuiltinLoc;
435ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
436ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setBuiltinLoc(SourceLocation Loc) {
437ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    getLocalData()->BuiltinLoc = Loc;
438ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
439ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
440ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  SourceLocation getNameLoc() const { return getBuiltinLoc(); }
441ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
442ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  WrittenBuiltinSpecs& getWrittenBuiltinSpecs() {
443ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
444ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
445ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
446ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
447ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
448ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
449ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool needsExtraLocalData() const {
450ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    BuiltinType::Kind bk = getTypePtr()->getKind();
451ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128)
452d038f361d2b4368af7ab85bd04d5aafcc3ea649dDouglas Gregor      || (bk >= BuiltinType::Short && bk <= BuiltinType::LongDouble)
453ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      || bk == BuiltinType::UChar
454ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      || bk == BuiltinType::SChar;
455ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
456ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
457ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  unsigned getExtraLocalDataSize() const {
458d31351288e25e8a7a2a919c99ffe281c2a41b53cDaniel Dunbar    return needsExtraLocalData() ? sizeof(WrittenBuiltinSpecs) : 0;
459ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
460ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
461bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
462ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return SourceRange(getBuiltinLoc(), getBuiltinLoc());
463ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
464ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
465ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  TypeSpecifierSign getWrittenSignSpec() const {
466ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
467ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return static_cast<TypeSpecifierSign>(getWrittenBuiltinSpecs().Sign);
468ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    else
469ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return TSS_unspecified;
470ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
471ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool hasWrittenSignSpec() const {
472ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return getWrittenSignSpec() != TSS_unspecified;
473ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
474ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setWrittenSignSpec(TypeSpecifierSign written) {
475ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
476ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      getWrittenBuiltinSpecs().Sign = written;
477ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
478ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
479ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  TypeSpecifierWidth getWrittenWidthSpec() const {
480ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
481ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return static_cast<TypeSpecifierWidth>(getWrittenBuiltinSpecs().Width);
482ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    else
483ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return TSW_unspecified;
484ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
485ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool hasWrittenWidthSpec() const {
486ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return getWrittenWidthSpec() != TSW_unspecified;
487ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
488ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setWrittenWidthSpec(TypeSpecifierWidth written) {
489ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
490ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      getWrittenBuiltinSpecs().Width = written;
491ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
492ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
493ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  TypeSpecifierType getWrittenTypeSpec() const;
494ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool hasWrittenTypeSpec() const {
495ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return getWrittenTypeSpec() != TST_unspecified;
496ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
497ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setWrittenTypeSpec(TypeSpecifierType written) {
498ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
499ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      getWrittenBuiltinSpecs().Type = written;
500ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
501ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
502ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool hasModeAttr() const {
503ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
504ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return getWrittenBuiltinSpecs().ModeAttr;
505ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    else
506ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return false;
507ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
508ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setModeAttr(bool written) {
509ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
510ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      getWrittenBuiltinSpecs().ModeAttr = written;
511ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
512ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
513c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
514ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    setBuiltinLoc(Loc);
515ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData()) {
516ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs();
517ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      wbs.Sign = TSS_unspecified;
518ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      wbs.Width = TSW_unspecified;
519ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      wbs.Type = TST_unspecified;
520ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      wbs.ModeAttr = false;
521ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    }
522ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
523ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor};
524ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
525ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
52651bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for typedefs.
527ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TypedefTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
528ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                        TypedefTypeLoc,
529ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                        TypedefType> {
53051bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic:
531162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *getTypedefNameDecl() const {
53234a0447b8072e0da14c0980597da9d03a1495662John McCall    return getTypePtr()->getDecl();
5339036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis  }
53434a0447b8072e0da14c0980597da9d03a1495662John McCall};
5359036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis
5363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// \brief Wrapper for source info for injected class names of class
5373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// templates.
5383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameTypeLoc :
5393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
5403cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                     InjectedClassNameTypeLoc,
5413cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                     InjectedClassNameType> {
542427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidispublic:
543427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidis  CXXRecordDecl *getDecl() const {
544427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidis    return getTypePtr()->getDecl();
545427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidis  }
5463cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
5473cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
548ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for unresolved typename using decls.
549ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingTypeLoc :
550ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
551ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     UnresolvedUsingTypeLoc,
552ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     UnresolvedUsingType> {
553ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
554ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const {
555ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return getTypePtr()->getDecl();
556ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
557ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
558ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
559ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for tag types.  Note that this only
560ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// records source info for the name itself; a type written 'struct foo'
561ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// should be represented as an ElaboratedTypeLoc.  We currently
562ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// only do that when C++ is enabled because of the expense of
563ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// creating an ElaboratedType node for so many type references in C.
564ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TagTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
565ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                    TagTypeLoc,
566ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                    TagType> {
567ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
568ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TagDecl *getDecl() const { return getTypePtr()->getDecl(); }
5696f155de99c59af890817146ec8526bafb6560f1fArgyrios Kyrtzidis
570ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief True if the tag was defined in this type specifier.
5716f155de99c59af890817146ec8526bafb6560f1fArgyrios Kyrtzidis  bool isDefinition() const {
5725e1cdac63c3d9c9b32fa41fa0b2d242a58a20d49John McCall    return getDecl()->isCompleteDefinition() &&
5736f155de99c59af890817146ec8526bafb6560f1fArgyrios Kyrtzidis         (getNameLoc().isInvalid() || getNameLoc() == getDecl()->getLocation());
5746f155de99c59af890817146ec8526bafb6560f1fArgyrios Kyrtzidis  }
575ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
576ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
577ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for record types.
578ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
579ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                       RecordTypeLoc,
580ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                       RecordType> {
581ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
582ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  RecordDecl *getDecl() const { return getTypePtr()->getDecl(); }
583ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
584ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
585ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for enum types.
586ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
587ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                     EnumTypeLoc,
588ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                     EnumType> {
589ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
590ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  EnumDecl *getDecl() const { return getTypePtr()->getDecl(); }
591ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
592b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
59349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Wrapper for template type parameters.
594ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TemplateTypeParmTypeLoc :
595ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
596ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     TemplateTypeParmTypeLoc,
597ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     TemplateTypeParmType> {
598960d13dde337a59dacc9dc3936c26d4aa8478986Chandler Carruthpublic:
599960d13dde337a59dacc9dc3936c26d4aa8478986Chandler Carruth  TemplateTypeParmDecl *getDecl() const { return getTypePtr()->getDecl(); }
60049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
60149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
60249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Wrapper for substituted template type parameters.
60349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmTypeLoc :
604ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
605ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     SubstTemplateTypeParmTypeLoc,
606ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     SubstTemplateTypeParmType> {
60749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
60851bd803fbdade51d674598ed45da3d54190a656cJohn McCall
609c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief Wrapper for substituted template type parameters.
610c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackTypeLoc :
611c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
612c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                     SubstTemplateTypeParmPackTypeLoc,
613c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                     SubstTemplateTypeParmPackType> {
614c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor};
615c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
6169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallstruct AttributedLocInfo {
6179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  union {
6189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Expr *ExprOperand;
6199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    /// A raw SourceLocation.
6219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned EnumOperandLoc;
6229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
6239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceRange OperandParens;
6259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceLocation AttrLoc;
6279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
6289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// \brief Type source information for an attributed type.
6309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
6319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                 AttributedTypeLoc,
6329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                 AttributedType,
6339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                 AttributedLocInfo> {
6349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
6359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedType::Kind getAttrKind() const {
6369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getTypePtr()->getAttrKind();
6379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool hasAttrExprOperand() const {
6409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return (getAttrKind() >= AttributedType::FirstExprOperandKind &&
6419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall            getAttrKind() <= AttributedType::LastExprOperandKind);
6429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool hasAttrEnumOperand() const {
6459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return (getAttrKind() >= AttributedType::FirstEnumOperandKind &&
6469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall            getAttrKind() <= AttributedType::LastEnumOperandKind);
6479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool hasAttrOperand() const {
6509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return hasAttrExprOperand() || hasAttrEnumOperand();
6519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The modified type, which is generally canonically different from
6549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// the attribute type.
6559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    int main(int, char**) __attribute__((noreturn))
6569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    ~~~     ~~~~~~~~~~~~~
6579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  TypeLoc getModifiedLoc() const {
6589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getInnerTypeLoc();
6599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The location of the attribute name, i.e.
6629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    __attribute__((regparm(1000)))
6639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///                   ^~~~~~~
6649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceLocation getAttrNameLoc() const {
6659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getLocalData()->AttrLoc;
6669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void setAttrNameLoc(SourceLocation loc) {
6689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    getLocalData()->AttrLoc = loc;
6699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The attribute's expression operand, if it has one.
6729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    void *cur_thread __attribute__((address_space(21)))
6739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///                                                  ^~
6749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Expr *getAttrExprOperand() const {
6759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrExprOperand());
6769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getLocalData()->ExprOperand;
6779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void setAttrExprOperand(Expr *e) {
6799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrExprOperand());
6809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    getLocalData()->ExprOperand = e;
6819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The location of the attribute's enumerated operand, if it has one.
6849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    void * __attribute__((objc_gc(weak)))
6859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///                                  ^~~~
6869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceLocation getAttrEnumOperandLoc() const {
6879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrEnumOperand());
6889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return SourceLocation::getFromRawEncoding(getLocalData()->EnumOperandLoc);
6899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void setAttrEnumOperandLoc(SourceLocation loc) {
6919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrEnumOperand());
6929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    getLocalData()->EnumOperandLoc = loc.getRawEncoding();
6939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The location of the parentheses around the operand, if there is
6969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// an operand.
6979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    void * __attribute__((objc_gc(weak)))
6989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///                                 ^    ^
6999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceRange getAttrOperandParensRange() const {
7009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrOperand());
7019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getLocalData()->OperandParens;
7029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
7039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void setAttrOperandParensRange(SourceRange range) {
7049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrOperand());
7059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    getLocalData()->OperandParens = range;
7069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
7079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
7089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceRange getLocalSourceRange() const {
7099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Note that this does *not* include the range of the attribute
7109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // enclosure, e.g.:
7119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    //    __attribute__((foo(bar)))
7129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    //    ^~~~~~~~~~~~~~~        ~~
7139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // or
7149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    //    [[foo(bar)]]
7159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    //    ^~        ~~
7169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // That enclosure doesn't necessarily belong to a single attribute
7179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // anyway.
7189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    SourceRange range(getAttrNameLoc());
7199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (hasAttrOperand())
7209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      range.setEnd(getAttrOperandParensRange().getEnd());
7219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return range;
7229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
7239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
724c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation loc) {
7259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    setAttrNameLoc(loc);
7269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (hasAttrExprOperand()) {
7279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      setAttrOperandParensRange(SourceRange(loc));
7289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      setAttrExprOperand(0);
7299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    } else if (hasAttrEnumOperand()) {
7309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      setAttrOperandParensRange(SourceRange(loc));
7319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      setAttrEnumOperandLoc(loc);
7329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    }
7339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
7349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
7359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getInnerType() const {
7369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getTypePtr()->getModifiedType();
7379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
7389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
7399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
740eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis
74134a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ObjCProtocolListLocInfo {
74254e14c4db764c0636160d26c5bbf491637c83a76John McCall  SourceLocation LAngleLoc;
74354e14c4db764c0636160d26c5bbf491637c83a76John McCall  SourceLocation RAngleLoc;
744ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall  bool HasBaseTypeAsWritten;
745eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis};
746eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis
74754e14c4db764c0636160d26c5bbf491637c83a76John McCall// A helper class for defining ObjC TypeLocs that can qualified with
74854e14c4db764c0636160d26c5bbf491637c83a76John McCall// protocols.
74954e14c4db764c0636160d26c5bbf491637c83a76John McCall//
75054e14c4db764c0636160d26c5bbf491637c83a76John McCall// TypeClass basically has to be either ObjCInterfaceType or
75154e14c4db764c0636160d26c5bbf491637c83a76John McCall// ObjCObjectPointerType.
752c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
753c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                 ObjCObjectTypeLoc,
754c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                 ObjCObjectType,
755c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                 ObjCProtocolListLocInfo> {
756f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  // SourceLocations are stored after Info, one for each Protocol.
757f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  SourceLocation *getProtocolLocArray() const {
75854e14c4db764c0636160d26c5bbf491637c83a76John McCall    return (SourceLocation*) this->getExtraLocalData();
75954e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
76054e14c4db764c0636160d26c5bbf491637c83a76John McCall
761f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidispublic:
762f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  SourceLocation getLAngleLoc() const {
76354e14c4db764c0636160d26c5bbf491637c83a76John McCall    return this->getLocalData()->LAngleLoc;
764f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
765f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  void setLAngleLoc(SourceLocation Loc) {
76654e14c4db764c0636160d26c5bbf491637c83a76John McCall    this->getLocalData()->LAngleLoc = Loc;
767f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
768f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
769f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  SourceLocation getRAngleLoc() const {
77054e14c4db764c0636160d26c5bbf491637c83a76John McCall    return this->getLocalData()->RAngleLoc;
771f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
772f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  void setRAngleLoc(SourceLocation Loc) {
77354e14c4db764c0636160d26c5bbf491637c83a76John McCall    this->getLocalData()->RAngleLoc = Loc;
774f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
775f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
776f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  unsigned getNumProtocols() const {
77754e14c4db764c0636160d26c5bbf491637c83a76John McCall    return this->getTypePtr()->getNumProtocols();
778f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
779f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
780f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  SourceLocation getProtocolLoc(unsigned i) const {
781f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    assert(i < getNumProtocols() && "Index is out of bounds!");
782f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    return getProtocolLocArray()[i];
783f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
784f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  void setProtocolLoc(unsigned i, SourceLocation Loc) {
785f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    assert(i < getNumProtocols() && "Index is out of bounds!");
786f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    getProtocolLocArray()[i] = Loc;
787f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
788f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
789f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  ObjCProtocolDecl *getProtocol(unsigned i) const {
790f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    assert(i < getNumProtocols() && "Index is out of bounds!");
79154e14c4db764c0636160d26c5bbf491637c83a76John McCall    return *(this->getTypePtr()->qual_begin() + i);
792f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
793ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
794c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool hasBaseTypeAsWritten() const {
795ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall    return getLocalData()->HasBaseTypeAsWritten;
796c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
797c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
798c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void setHasBaseTypeAsWritten(bool HasBaseType) {
799ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall    getLocalData()->HasBaseTypeAsWritten = HasBaseType;
800c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
801c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
802c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TypeLoc getBaseLoc() const {
803c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getInnerTypeLoc();
804c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
805c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
806bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
807f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    return SourceRange(getLAngleLoc(), getRAngleLoc());
808f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
809f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
810c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
811ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall    setHasBaseTypeAsWritten(true);
812c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    setLAngleLoc(Loc);
813c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    setRAngleLoc(Loc);
814c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    for (unsigned i = 0, e = getNumProtocols(); i != e; ++i)
815c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      setProtocolLoc(i, Loc);
8164ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
8174ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
81834a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getExtraLocalDataSize() const {
81954e14c4db764c0636160d26c5bbf491637c83a76John McCall    return this->getNumProtocols() * sizeof(SourceLocation);
82054e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
821c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
822c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getInnerType() const {
823c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getTypePtr()->getBaseType();
824c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
82554e14c4db764c0636160d26c5bbf491637c83a76John McCall};
82654e14c4db764c0636160d26c5bbf491637c83a76John McCall
82754e14c4db764c0636160d26c5bbf491637c83a76John McCall
828c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallstruct ObjCInterfaceLocInfo {
82954e14c4db764c0636160d26c5bbf491637c83a76John McCall  SourceLocation NameLoc;
83054e14c4db764c0636160d26c5bbf491637c83a76John McCall};
83154e14c4db764c0636160d26c5bbf491637c83a76John McCall
83254e14c4db764c0636160d26c5bbf491637c83a76John McCall/// \brief Wrapper for source info for ObjC interfaces.
833a8bef693d8761e31845a26e136f8d3a0983d2f46Nick Lewyckyclass ObjCInterfaceTypeLoc : public ConcreteTypeLoc<ObjCObjectTypeLoc,
834c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                    ObjCInterfaceTypeLoc,
835c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                    ObjCInterfaceType,
836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                    ObjCInterfaceLocInfo> {
83754e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic:
83854e14c4db764c0636160d26c5bbf491637c83a76John McCall  ObjCInterfaceDecl *getIFaceDecl() const {
83954e14c4db764c0636160d26c5bbf491637c83a76John McCall    return getTypePtr()->getDecl();
84054e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
84154e14c4db764c0636160d26c5bbf491637c83a76John McCall
84254e14c4db764c0636160d26c5bbf491637c83a76John McCall  SourceLocation getNameLoc() const {
84354e14c4db764c0636160d26c5bbf491637c83a76John McCall    return getLocalData()->NameLoc;
84454e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
84554e14c4db764c0636160d26c5bbf491637c83a76John McCall
84654e14c4db764c0636160d26c5bbf491637c83a76John McCall  void setNameLoc(SourceLocation Loc) {
84754e14c4db764c0636160d26c5bbf491637c83a76John McCall    getLocalData()->NameLoc = Loc;
84854e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
84954e14c4db764c0636160d26c5bbf491637c83a76John McCall
850bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
851c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return SourceRange(getNameLoc());
85254e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
85354e14c4db764c0636160d26c5bbf491637c83a76John McCall
854c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
85554e14c4db764c0636160d26c5bbf491637c83a76John McCall    setNameLoc(Loc);
856f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
85754e14c4db764c0636160d26c5bbf491637c83a76John McCall};
85854e14c4db764c0636160d26c5bbf491637c83a76John McCall
859075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarastruct ParenLocInfo {
860075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceLocation LParenLoc;
861075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceLocation RParenLoc;
862075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
863075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
864075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenTypeLoc
865075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  : public ConcreteTypeLoc<UnqualTypeLoc, ParenTypeLoc, ParenType,
866075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                           ParenLocInfo> {
867075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
868075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceLocation getLParenLoc() const {
869075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return this->getLocalData()->LParenLoc;
870075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
871075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceLocation getRParenLoc() const {
872075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return this->getLocalData()->RParenLoc;
873075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
874075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void setLParenLoc(SourceLocation Loc) {
875075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    this->getLocalData()->LParenLoc = Loc;
876075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
877075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void setRParenLoc(SourceLocation Loc) {
878075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    this->getLocalData()->RParenLoc = Loc;
879075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
880075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
881075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceRange getLocalSourceRange() const {
882075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return SourceRange(getLParenLoc(), getRParenLoc());
883075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
884075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
885c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
886075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    setLParenLoc(Loc);
887075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    setRParenLoc(Loc);
888075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
889075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
890075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  TypeLoc getInnerLoc() const {
891075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return getInnerTypeLoc();
892075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
893075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
894075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const {
895075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return this->getTypePtr()->getInnerType();
896075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
897075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
898075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
899f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
90051bd803fbdade51d674598ed45da3d54190a656cJohn McCallstruct PointerLikeLocInfo {
90134a0447b8072e0da14c0980597da9d03a1495662John McCall  SourceLocation StarLoc;
902f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis};
903f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
904ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// A base class for
90551bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo>
90651bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived,
90751bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                  TypeClass, LocalData> {
908ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic:
90951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  SourceLocation getSigilLoc() const {
91051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return this->getLocalData()->StarLoc;
911b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
91251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void setSigilLoc(SourceLocation Loc) {
91351bd803fbdade51d674598ed45da3d54190a656cJohn McCall    this->getLocalData()->StarLoc = Loc;
914b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
915b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
916b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  TypeLoc getPointeeLoc() const {
91751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return this->getInnerTypeLoc();
918b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
919b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
920bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
92151bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return SourceRange(getSigilLoc(), getSigilLoc());
922b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
923b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
924c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
92551bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
9264ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
9274ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
92851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  QualType getInnerType() const {
92951bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return this->getTypePtr()->getPointeeType();
93051bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
93134a0447b8072e0da14c0980597da9d03a1495662John McCall};
932b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
933b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
93451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for pointers.
93551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc,
93651bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                 PointerType> {
93751bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic:
93851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  SourceLocation getStarLoc() const {
93951bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
94051bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
94151bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void setStarLoc(SourceLocation Loc) {
94251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
94351bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
944b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
945b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
94651bd803fbdade51d674598ed45da3d54190a656cJohn McCall
947b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for block pointers.
94851bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc,
94951bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                      BlockPointerType> {
950b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
951b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getCaretLoc() const {
95251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
953b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
954b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setCaretLoc(SourceLocation Loc) {
95551bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
956b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
95734a0447b8072e0da14c0980597da9d03a1495662John McCall};
958b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
959b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnarastruct MemberPointerLocInfo : public PointerLikeLocInfo {
960b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo *ClassTInfo;
961b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara};
962b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
963b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for member pointers.
96451bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc,
965b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara                                                       MemberPointerType,
966b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara                                                       MemberPointerLocInfo> {
967b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
968b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getStarLoc() const {
96951bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
970b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
971b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setStarLoc(SourceLocation Loc) {
97251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
9734ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
974b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
975b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  const Type *getClass() const {
976b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    return getTypePtr()->getClass();
977b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
978b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo *getClassTInfo() const {
979b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    return getLocalData()->ClassTInfo;
980b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
981b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  void setClassTInfo(TypeSourceInfo* TI) {
982b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    getLocalData()->ClassTInfo = TI;
983b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
984b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
985b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
986b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    setSigilLoc(Loc);
987b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    setClassTInfo(0);
988b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
989b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
990b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  SourceRange getLocalSourceRange() const {
991b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (TypeSourceInfo *TI = getClassTInfo())
992b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return SourceRange(TI->getTypeLoc().getBeginLoc(), getStarLoc());
993b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    else
994b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return SourceRange(getStarLoc());
995b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
99634a0447b8072e0da14c0980597da9d03a1495662John McCall};
997b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
998c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Wraps an ObjCPointerType with source location information.
999c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectPointerTypeLoc :
1000c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    public PointerLikeTypeLoc<ObjCObjectPointerTypeLoc,
1001c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                              ObjCObjectPointerType> {
1002c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
1003c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  SourceLocation getStarLoc() const {
1004c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getSigilLoc();
1005c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
1006c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
1007c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void setStarLoc(SourceLocation Loc) {
1008c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    setSigilLoc(Loc);
1009c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
1010c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
1011c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
1012b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
101351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc,
101451bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                   ReferenceType> {
101554e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic:
101654e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getInnerType() const {
101754e14c4db764c0636160d26c5bbf491637c83a76John McCall    return getTypePtr()->getPointeeTypeAsWritten();
101854e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
1019b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
1020b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1021bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallclass LValueReferenceTypeLoc :
1022bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall    public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1023bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall                                     LValueReferenceTypeLoc,
1024bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall                                     LValueReferenceType> {
1025b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
1026b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getAmpLoc() const {
102751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
1028b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1029b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setAmpLoc(SourceLocation Loc) {
103051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
1031b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
103251bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
1033b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1034bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallclass RValueReferenceTypeLoc :
1035bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall    public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1036bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall                                     RValueReferenceTypeLoc,
1037bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall                                     RValueReferenceType> {
103851bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic:
103951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  SourceLocation getAmpAmpLoc() const {
104051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
1041b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
104251bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void setAmpAmpLoc(SourceLocation Loc) {
104351bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
1044b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
104551bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
1046b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1047b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
104834a0447b8072e0da14c0980597da9d03a1495662John McCallstruct FunctionLocInfo {
1049796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  SourceLocation LocalRangeBegin;
1050796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  SourceLocation LocalRangeEnd;
1051dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  bool TrailingReturn;
1052b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
1053b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1054b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for functions.
105551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
105651bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                               FunctionTypeLoc,
105751bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                               FunctionType,
105851bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                               FunctionLocInfo> {
1059b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
1060796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  SourceLocation getLocalRangeBegin() const {
1061796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    return getLocalData()->LocalRangeBegin;
1062b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1063796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  void setLocalRangeBegin(SourceLocation L) {
1064796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    getLocalData()->LocalRangeBegin = L;
1065b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1066b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1067796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  SourceLocation getLocalRangeEnd() const {
1068796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    return getLocalData()->LocalRangeEnd;
1069b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1070796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  void setLocalRangeEnd(SourceLocation L) {
1071796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    getLocalData()->LocalRangeEnd = L;
1072b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1073b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1074dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  bool getTrailingReturn() const {
1075dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    return getLocalData()->TrailingReturn;
1076dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
1077dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  void setTrailingReturn(bool Trailing) {
1078dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    getLocalData()->TrailingReturn = Trailing;
1079dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
1080dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
1081ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  ArrayRef<ParmVarDecl *> getParams() const {
1082ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    return ArrayRef<ParmVarDecl *>(getParmArray(), getNumArgs());
1083ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  }
1084ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman
1085a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  // ParmVarDecls* are stored after Info, one for each argument.
1086a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  ParmVarDecl **getParmArray() const {
1087a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    return (ParmVarDecl**) getExtraLocalData();
1088a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  }
1089a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor
1090b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  unsigned getNumArgs() const {
109134a0447b8072e0da14c0980597da9d03a1495662John McCall    if (isa<FunctionNoProtoType>(getTypePtr()))
1092b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis      return 0;
109334a0447b8072e0da14c0980597da9d03a1495662John McCall    return cast<FunctionProtoType>(getTypePtr())->getNumArgs();
1094b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1095b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; }
1096b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; }
1097b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1098b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  TypeLoc getResultLoc() const {
109934a0447b8072e0da14c0980597da9d03a1495662John McCall    return getInnerTypeLoc();
1100b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1101b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1102bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1103796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    return SourceRange(getLocalRangeBegin(), getLocalRangeEnd());
1104b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1105b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1106c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1107796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    setLocalRangeBegin(Loc);
1108796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara    setLocalRangeEnd(Loc);
1109dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    setTrailingReturn(false);
11104ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    for (unsigned i = 0, e = getNumArgs(); i != e; ++i)
11114ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall      setArg(i, NULL);
11124ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
11134ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
1114b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// \brief Returns the size of the type source info data block that is
1115b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// specific to this type.
111634a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getExtraLocalDataSize() const {
111734a0447b8072e0da14c0980597da9d03a1495662John McCall    return getNumArgs() * sizeof(ParmVarDecl*);
1118b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1119b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
112034a0447b8072e0da14c0980597da9d03a1495662John McCall  QualType getInnerType() const { return getTypePtr()->getResultType(); }
112134a0447b8072e0da14c0980597da9d03a1495662John McCall};
112234a0447b8072e0da14c0980597da9d03a1495662John McCall
112351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionProtoTypeLoc :
112451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<FunctionTypeLoc,
112551bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     FunctionProtoTypeLoc,
112651bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     FunctionProtoType> {
112751bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
112851bd803fbdade51d674598ed45da3d54190a656cJohn McCall
112951bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionNoProtoTypeLoc :
113051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<FunctionTypeLoc,
113151bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     FunctionNoProtoTypeLoc,
113251bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     FunctionNoProtoType> {
113351bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
113451bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1135b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
113634a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ArrayLocInfo {
113734a0447b8072e0da14c0980597da9d03a1495662John McCall  SourceLocation LBracketLoc, RBracketLoc;
113834a0447b8072e0da14c0980597da9d03a1495662John McCall  Expr *Size;
1139b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
1140b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1141b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for arrays.
114251bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
114351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                            ArrayTypeLoc,
114451bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                            ArrayType,
114551bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                            ArrayLocInfo> {
1146b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
1147b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getLBracketLoc() const {
114834a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData()->LBracketLoc;
1149b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1150b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setLBracketLoc(SourceLocation Loc) {
115134a0447b8072e0da14c0980597da9d03a1495662John McCall    getLocalData()->LBracketLoc = Loc;
1152b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1153b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1154b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getRBracketLoc() const {
115534a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData()->RBracketLoc;
1156b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1157b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setRBracketLoc(SourceLocation Loc) {
115834a0447b8072e0da14c0980597da9d03a1495662John McCall    getLocalData()->RBracketLoc = Loc;
1159b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1160b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
116185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  SourceRange getBracketsRange() const {
116285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return SourceRange(getLBracketLoc(), getRBracketLoc());
116385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
116485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
1165b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  Expr *getSizeExpr() const {
116634a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData()->Size;
1167b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1168b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setSizeExpr(Expr *Size) {
116934a0447b8072e0da14c0980597da9d03a1495662John McCall    getLocalData()->Size = Size;
1170b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1171b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1172b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  TypeLoc getElementLoc() const {
117334a0447b8072e0da14c0980597da9d03a1495662John McCall    return getInnerTypeLoc();
1174b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1175b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1176bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1177b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis    return SourceRange(getLBracketLoc(), getRBracketLoc());
1178b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1179b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1180c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
11814ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setLBracketLoc(Loc);
11824ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setRBracketLoc(Loc);
11834ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setSizeExpr(NULL);
11844ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
11854ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
118634a0447b8072e0da14c0980597da9d03a1495662John McCall  QualType getInnerType() const { return getTypePtr()->getElementType(); }
1187b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
1188b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
118951bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ConstantArrayTypeLoc :
119051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<ArrayTypeLoc,
119151bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     ConstantArrayTypeLoc,
119251bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     ConstantArrayType> {
119351bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
119451bd803fbdade51d674598ed45da3d54190a656cJohn McCall
119551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass IncompleteArrayTypeLoc :
119651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<ArrayTypeLoc,
119751bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     IncompleteArrayTypeLoc,
119851bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     IncompleteArrayType> {
119951bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
120051bd803fbdade51d674598ed45da3d54190a656cJohn McCall
120151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DependentSizedArrayTypeLoc :
120251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<ArrayTypeLoc,
120351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     DependentSizedArrayTypeLoc,
120451bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     DependentSizedArrayType> {
120551bd803fbdade51d674598ed45da3d54190a656cJohn McCall
120651bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
120751bd803fbdade51d674598ed45da3d54190a656cJohn McCall
120851bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass VariableArrayTypeLoc :
120951bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<ArrayTypeLoc,
121051bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     VariableArrayTypeLoc,
121151bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     VariableArrayType> {
121251bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
121351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1214833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1215833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall// Location information for a TemplateName.  Rudimentary for now.
1216833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstruct TemplateNameLocInfo {
1217833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation NameLoc;
1218833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall};
1219833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1220833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstruct TemplateSpecializationLocInfo : TemplateNameLocInfo {
1221833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation LAngleLoc;
1222833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation RAngleLoc;
1223833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall};
1224833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1225833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallclass TemplateSpecializationTypeLoc :
1226833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    public ConcreteTypeLoc<UnqualTypeLoc,
1227833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                           TemplateSpecializationTypeLoc,
1228833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                           TemplateSpecializationType,
1229833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                           TemplateSpecializationLocInfo> {
1230833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallpublic:
1231833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation getLAngleLoc() const {
1232833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getLocalData()->LAngleLoc;
1233833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1234833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void setLAngleLoc(SourceLocation Loc) {
1235833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getLocalData()->LAngleLoc = Loc;
1236833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1237833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1238833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation getRAngleLoc() const {
1239833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getLocalData()->RAngleLoc;
1240833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1241833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void setRAngleLoc(SourceLocation Loc) {
1242833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getLocalData()->RAngleLoc = Loc;
1243833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1244833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1245833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  unsigned getNumArgs() const {
1246833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getTypePtr()->getNumArgs();
1247833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1248833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
1249833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getArgInfos()[i] = AI;
1250833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1251833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
1252833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getArgInfos()[i];
1253833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1254833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1255833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLoc getArgLoc(unsigned i) const {
1256833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
1257833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1258833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1259833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation getTemplateNameLoc() const {
1260833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getLocalData()->NameLoc;
1261833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1262833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void setTemplateNameLoc(SourceLocation Loc) {
1263833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getLocalData()->NameLoc = Loc;
1264833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1265833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1266833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief - Copy the location information from the given info.
1267833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void copy(TemplateSpecializationTypeLoc Loc) {
1268833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    unsigned size = getFullDataSize();
1269833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    assert(size == Loc.getFullDataSize());
1270833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1271833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // We're potentially copying Expr references here.  We don't
1272a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    // bother retaining them because TypeSourceInfos live forever, so
1273833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // as long as the Expr was retained when originally written into
1274833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // the TypeLoc, we're okay.
1275833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    memcpy(Data, Loc.Data, size);
1276833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1277833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1278bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1279833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return SourceRange(getTemplateNameLoc(), getRAngleLoc());
1280833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1281833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1282c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1283833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    setLAngleLoc(Loc);
1284833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    setRAngleLoc(Loc);
1285833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    setTemplateNameLoc(Loc);
1286c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor    initializeArgLocs(Context, getNumArgs(), getTypePtr()->getArgs(),
128733500955d731c73717af52088b7fc0e7a85681e7John McCall                      getArgInfos(), Loc);
128833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
1289833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1290c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  static void initializeArgLocs(ASTContext &Context, unsigned NumArgs,
129133500955d731c73717af52088b7fc0e7a85681e7John McCall                                const TemplateArgument *Args,
129233500955d731c73717af52088b7fc0e7a85681e7John McCall                                TemplateArgumentLocInfo *ArgInfos,
1293c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor                                SourceLocation Loc);
1294833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1295833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  unsigned getExtraLocalDataSize() const {
1296833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getNumArgs() * sizeof(TemplateArgumentLocInfo);
1297833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1298833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1299833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallprivate:
1300833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo *getArgInfos() const {
1301833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
1302833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1303833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall};
1304833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1305ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//===----------------------------------------------------------------------===//
1306ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//
1307ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//  All of these need proper implementations.
1308ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//
1309ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//===----------------------------------------------------------------------===//
131051bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1311ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: size expression and attribute locations (or keyword if we
1312ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// ever fully support altivec syntax).
1313ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass VectorTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1314ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                       VectorTypeLoc,
1315ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                       VectorType> {
131651bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
131751bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1318ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: size expression and attribute locations.
131951bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc,
132051bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                          ExtVectorTypeLoc,
132151bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                          ExtVectorType> {
132251bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
132351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1324ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: attribute locations.
132551bd803fbdade51d674598ed45da3d54190a656cJohn McCall// For some reason, this isn't a subtype of VectorType.
132651bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DependentSizedExtVectorTypeLoc :
1327ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1328ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     DependentSizedExtVectorTypeLoc,
1329ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     DependentSizedExtVectorType> {
133051bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
133151bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1332ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: location of the '_Complex' keyword.
1333ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass ComplexTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1334ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                        ComplexTypeLoc,
1335ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                        ComplexType> {
133651bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
133751bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1338cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeofLocInfo {
1339cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation TypeofLoc;
1340cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation LParenLoc;
1341cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation RParenLoc;
134251bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
134351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1344cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeOfExprTypeLocInfo : public TypeofLocInfo {
1345cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall};
1346cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1347cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeOfTypeLocInfo : public TypeofLocInfo {
1348cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* UnderlyingTInfo;
1349cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall};
1350cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1351cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCalltemplate <class Derived, class TypeClass, class LocalData = TypeofLocInfo>
1352cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeofLikeTypeLoc
1353cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> {
1354cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic:
1355cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation getTypeofLoc() const {
1356cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getLocalData()->TypeofLoc;
1357cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1358cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setTypeofLoc(SourceLocation Loc) {
1359cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    this->getLocalData()->TypeofLoc = Loc;
1360cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1361cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1362cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation getLParenLoc() const {
1363cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getLocalData()->LParenLoc;
1364cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1365cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setLParenLoc(SourceLocation Loc) {
1366cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    this->getLocalData()->LParenLoc = Loc;
1367cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1368cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1369cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation getRParenLoc() const {
1370cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getLocalData()->RParenLoc;
1371cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1372cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setRParenLoc(SourceLocation Loc) {
1373cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    this->getLocalData()->RParenLoc = Loc;
1374cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1375cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1376cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceRange getParensRange() const {
1377cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return SourceRange(getLParenLoc(), getRParenLoc());
1378cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1379cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setParensRange(SourceRange range) {
1380cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      setLParenLoc(range.getBegin());
1381cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      setRParenLoc(range.getEnd());
1382cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1383cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1384bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1385cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return SourceRange(getTypeofLoc(), getRParenLoc());
1386cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1387cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1388c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1389cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    setTypeofLoc(Loc);
1390cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    setLParenLoc(Loc);
1391cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    setRParenLoc(Loc);
1392cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1393cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall};
1394cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1395cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeOfExprTypeLoc : public TypeofLikeTypeLoc<TypeOfExprTypeLoc,
1396cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall                                                   TypeOfExprType,
1397cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall                                                   TypeOfExprTypeLocInfo> {
1398cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic:
1399cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Expr* getUnderlyingExpr() const {
1400cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return getTypePtr()->getUnderlyingExpr();
1401cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1402cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  // Reimplemented to account for GNU/C++ extension
1403cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  //     typeof unary-expression
1404cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  // where there are no parentheses.
1405bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const;
1406cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall};
1407cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1408cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeOfTypeLoc
1409cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  : public TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo> {
1410cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic:
1411cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  QualType getUnderlyingType() const {
1412cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getTypePtr()->getUnderlyingType();
1413cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1414cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* getUnderlyingTInfo() const {
1415cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getLocalData()->UnderlyingTInfo;
1416cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1417cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setUnderlyingTInfo(TypeSourceInfo* TI) const {
1418cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    this->getLocalData()->UnderlyingTInfo = TI;
1419cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
142051bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
142151bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1422ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: location of the 'decltype' and parens.
1423ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1424ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                         DecltypeTypeLoc,
1425ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                         DecltypeType> {
1426427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidispublic:
1427427964e15f1b9595659cea3fcb4dd808a00f37b5Argyrios Kyrtzidis  Expr *getUnderlyingExpr() const { return getTypePtr()->getUnderlyingExpr(); }
142851bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
142951bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1430ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntstruct UnaryTransformTypeLocInfo {
1431ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  // FIXME: While there's only one unary transform right now, future ones may
1432ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  // need different representations
1433ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  SourceLocation KWLoc, LParenLoc, RParenLoc;
1434ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  TypeSourceInfo *UnderlyingTInfo;
1435ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt};
1436ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
1437ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntclass UnaryTransformTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1438ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    UnaryTransformTypeLoc,
1439ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    UnaryTransformType,
1440ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    UnaryTransformTypeLocInfo> {
1441ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic:
1442ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  SourceLocation getKWLoc() const { return getLocalData()->KWLoc; }
1443ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  void setKWLoc(SourceLocation Loc) { getLocalData()->KWLoc = Loc; }
1444ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
1445ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  SourceLocation getLParenLoc() const { return getLocalData()->LParenLoc; }
1446ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  void setLParenLoc(SourceLocation Loc) { getLocalData()->LParenLoc = Loc; }
1447ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
1448ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
1449ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
1450ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
1451ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  TypeSourceInfo* getUnderlyingTInfo() const {
1452ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    return getLocalData()->UnderlyingTInfo;
1453ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
1454ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  void setUnderlyingTInfo(TypeSourceInfo *TInfo) {
1455ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    getLocalData()->UnderlyingTInfo = TInfo;
1456ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
1457ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
1458ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  SourceRange getLocalSourceRange() const {
1459ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    return SourceRange(getKWLoc(), getRParenLoc());
1460ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
1461ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
1462ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  SourceRange getParensRange() const {
1463ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    return SourceRange(getLParenLoc(), getRParenLoc());
1464ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
1465ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  void setParensRange(SourceRange Range) {
1466ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    setLParenLoc(Range.getBegin());
1467ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    setRParenLoc(Range.getEnd());
1468ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
1469ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
1470ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1471ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    setKWLoc(Loc);
1472ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    setRParenLoc(Loc);
1473ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    setLParenLoc(Loc);
1474ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
1475ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt};
1476ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
147734b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
147834b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                        AutoTypeLoc,
147934b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                        AutoType> {
148034b41d939a1328f484511c6002ba2456db879a29Richard Smith};
148134b41d939a1328f484511c6002ba2456db879a29Richard Smith
1482e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarastruct ElaboratedLocInfo {
1483e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation KeywordLoc;
1484ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14859e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  /// \brief Opaque data pointer used to reconstruct a nested-name-specifier
1486ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// from
14879e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  void *QualifierData;
1488e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara};
1489e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1490e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnaraclass ElaboratedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1491e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                 ElaboratedTypeLoc,
1492e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                 ElaboratedType,
1493e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                 ElaboratedLocInfo> {
1494e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarapublic:
1495e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation getKeywordLoc() const {
1496e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return this->getLocalData()->KeywordLoc;
1497e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1498e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void setKeywordLoc(SourceLocation Loc) {
1499e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    this->getLocalData()->KeywordLoc = Loc;
1500e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1501e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
15029e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
1503ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
15049e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                  getLocalData()->QualifierData);
1505e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1506ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15079e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1508ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(QualifierLoc.getNestedNameSpecifier()
15099e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                            == getTypePtr()->getQualifier() &&
15109e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor           "Inconsistent nested-name-specifier pointer");
15119e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1512e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1513e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1514bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1515e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    if (getKeywordLoc().isValid())
15169e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      if (getQualifierLoc())
15179e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor        return SourceRange(getKeywordLoc(), getQualifierLoc().getEndLoc());
1518e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      else
1519e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara        return SourceRange(getKeywordLoc());
1520e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    else
15219e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      return getQualifierLoc().getSourceRange();
1522e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1523e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
15249e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc);
1525e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1526e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  TypeLoc getNamedTypeLoc() const {
1527e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return getInnerTypeLoc();
1528e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1529e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1530e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType getInnerType() const {
1531e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return getTypePtr()->getNamedType();
1532e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1533e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1534e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void copy(ElaboratedTypeLoc Loc) {
1535e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    unsigned size = getFullDataSize();
1536e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    assert(size == Loc.getFullDataSize());
1537e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    memcpy(Data, Loc.Data, size);
1538e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
153951bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
154051bd803fbdade51d674598ed45da3d54190a656cJohn McCall
154133500955d731c73717af52088b7fc0e7a85681e7John McCall// This is exactly the structure of an ElaboratedTypeLoc whose inner
154233500955d731c73717af52088b7fc0e7a85681e7John McCall// type is some sort of TypeDeclTypeLoc.
154333500955d731c73717af52088b7fc0e7a85681e7John McCallstruct DependentNameLocInfo : ElaboratedLocInfo {
1544e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation NameLoc;
1545ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15462494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  /// \brief Data associated with the nested-name-specifier location.
15472494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  void *QualifierData;
1548e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara};
1549e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1550e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnaraclass DependentNameTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1551e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                    DependentNameTypeLoc,
1552e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                    DependentNameType,
1553e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                    DependentNameLocInfo> {
1554e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarapublic:
1555e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation getKeywordLoc() const {
1556e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return this->getLocalData()->KeywordLoc;
1557e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1558e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void setKeywordLoc(SourceLocation Loc) {
1559e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    this->getLocalData()->KeywordLoc = Loc;
1560e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1561e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
15622494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
1563ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
15642494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                  getLocalData()->QualifierData);
1565e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1566ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15672494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
1568ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(QualifierLoc.getNestedNameSpecifier()
15692494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            == getTypePtr()->getQualifier() &&
15702494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor           "Inconsistent nested-name-specifier pointer");
15712494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1572e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1573ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1574e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation getNameLoc() const {
1575e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return this->getLocalData()->NameLoc;
1576e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1577e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void setNameLoc(SourceLocation Loc) {
1578e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    this->getLocalData()->NameLoc = Loc;
1579e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1580e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1581bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1582e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    if (getKeywordLoc().isValid())
1583e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      return SourceRange(getKeywordLoc(), getNameLoc());
1584e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    else
15852494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor      return SourceRange(getQualifierLoc().getBeginLoc(), getNameLoc());
1586e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1587e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1588e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void copy(DependentNameTypeLoc Loc) {
1589e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    unsigned size = getFullDataSize();
1590e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    assert(size == Loc.getFullDataSize());
1591e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    memcpy(Data, Loc.Data, size);
1592e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1593e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
15942494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc);
159551bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
159651bd803fbdade51d674598ed45da3d54190a656cJohn McCall
159794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregorstruct DependentTemplateSpecializationLocInfo : DependentNameLocInfo {
15989e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  SourceLocation KeywordLoc;
159933500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation LAngleLoc;
160033500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation RAngleLoc;
160133500955d731c73717af52088b7fc0e7a85681e7John McCall  // followed by a TemplateArgumentLocInfo[]
160233500955d731c73717af52088b7fc0e7a85681e7John McCall};
160333500955d731c73717af52088b7fc0e7a85681e7John McCall
160433500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationTypeLoc :
160533500955d731c73717af52088b7fc0e7a85681e7John McCall    public ConcreteTypeLoc<UnqualTypeLoc,
160633500955d731c73717af52088b7fc0e7a85681e7John McCall                           DependentTemplateSpecializationTypeLoc,
160733500955d731c73717af52088b7fc0e7a85681e7John McCall                           DependentTemplateSpecializationType,
160833500955d731c73717af52088b7fc0e7a85681e7John McCall                           DependentTemplateSpecializationLocInfo> {
160933500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
161033500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation getKeywordLoc() const {
161133500955d731c73717af52088b7fc0e7a85681e7John McCall    return this->getLocalData()->KeywordLoc;
161233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
161333500955d731c73717af52088b7fc0e7a85681e7John McCall  void setKeywordLoc(SourceLocation Loc) {
161433500955d731c73717af52088b7fc0e7a85681e7John McCall    this->getLocalData()->KeywordLoc = Loc;
161533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
161633500955d731c73717af52088b7fc0e7a85681e7John McCall
161794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
161894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (!getLocalData()->QualifierData)
161994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return NestedNameSpecifierLoc();
1620ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1621ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
162294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                  getLocalData()->QualifierData);
162333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
1624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
162594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
162694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (!QualifierLoc) {
1627ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      // Even if we have a nested-name-specifier in the dependent
162894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      // template specialization type, we won't record the nested-name-specifier
162994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      // location information when this type-source location information is
163094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      // part of a nested-name-specifier.
163194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      getLocalData()->QualifierData = 0;
163294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return;
163394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    }
1634ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1635ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(QualifierLoc.getNestedNameSpecifier()
163694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                        == getTypePtr()->getQualifier() &&
163794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor           "Inconsistent nested-name-specifier pointer");
163894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
163933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
164033500955d731c73717af52088b7fc0e7a85681e7John McCall
164133500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation getNameLoc() const {
164233500955d731c73717af52088b7fc0e7a85681e7John McCall    return this->getLocalData()->NameLoc;
164333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
164433500955d731c73717af52088b7fc0e7a85681e7John McCall  void setNameLoc(SourceLocation Loc) {
164533500955d731c73717af52088b7fc0e7a85681e7John McCall    this->getLocalData()->NameLoc = Loc;
164633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
164733500955d731c73717af52088b7fc0e7a85681e7John McCall
164833500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation getLAngleLoc() const {
164933500955d731c73717af52088b7fc0e7a85681e7John McCall    return this->getLocalData()->LAngleLoc;
165033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
165133500955d731c73717af52088b7fc0e7a85681e7John McCall  void setLAngleLoc(SourceLocation Loc) {
165233500955d731c73717af52088b7fc0e7a85681e7John McCall    this->getLocalData()->LAngleLoc = Loc;
165333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
165433500955d731c73717af52088b7fc0e7a85681e7John McCall
165533500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation getRAngleLoc() const {
165633500955d731c73717af52088b7fc0e7a85681e7John McCall    return this->getLocalData()->RAngleLoc;
165733500955d731c73717af52088b7fc0e7a85681e7John McCall  }
165833500955d731c73717af52088b7fc0e7a85681e7John McCall  void setRAngleLoc(SourceLocation Loc) {
165933500955d731c73717af52088b7fc0e7a85681e7John McCall    this->getLocalData()->RAngleLoc = Loc;
166033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
166133500955d731c73717af52088b7fc0e7a85681e7John McCall
166233500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const {
166333500955d731c73717af52088b7fc0e7a85681e7John McCall    return getTypePtr()->getNumArgs();
166433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
166533500955d731c73717af52088b7fc0e7a85681e7John McCall
166633500955d731c73717af52088b7fc0e7a85681e7John McCall  void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
166733500955d731c73717af52088b7fc0e7a85681e7John McCall    getArgInfos()[i] = AI;
166833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
166933500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
167033500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgInfos()[i];
167133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
167233500955d731c73717af52088b7fc0e7a85681e7John McCall
167333500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentLoc getArgLoc(unsigned i) const {
167433500955d731c73717af52088b7fc0e7a85681e7John McCall    return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
167533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
167633500955d731c73717af52088b7fc0e7a85681e7John McCall
167733500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceRange getLocalSourceRange() const {
167833500955d731c73717af52088b7fc0e7a85681e7John McCall    if (getKeywordLoc().isValid())
167933500955d731c73717af52088b7fc0e7a85681e7John McCall      return SourceRange(getKeywordLoc(), getRAngleLoc());
168094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    else if (getQualifierLoc())
168194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return SourceRange(getQualifierLoc().getBeginLoc(), getRAngleLoc());
16829e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    else
16839e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      return SourceRange(getNameLoc(), getRAngleLoc());
168433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
168533500955d731c73717af52088b7fc0e7a85681e7John McCall
168633500955d731c73717af52088b7fc0e7a85681e7John McCall  void copy(DependentTemplateSpecializationTypeLoc Loc) {
168733500955d731c73717af52088b7fc0e7a85681e7John McCall    unsigned size = getFullDataSize();
168833500955d731c73717af52088b7fc0e7a85681e7John McCall    assert(size == Loc.getFullDataSize());
168933500955d731c73717af52088b7fc0e7a85681e7John McCall    memcpy(Data, Loc.Data, size);
169033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
169133500955d731c73717af52088b7fc0e7a85681e7John McCall
169294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc);
169333500955d731c73717af52088b7fc0e7a85681e7John McCall
169433500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getExtraLocalDataSize() const {
169533500955d731c73717af52088b7fc0e7a85681e7John McCall    return getNumArgs() * sizeof(TemplateArgumentLocInfo);
169633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
169733500955d731c73717af52088b7fc0e7a85681e7John McCall
169833500955d731c73717af52088b7fc0e7a85681e7John McCallprivate:
169933500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentLocInfo *getArgInfos() const {
170033500955d731c73717af52088b7fc0e7a85681e7John McCall    return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
170133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
170233500955d731c73717af52088b7fc0e7a85681e7John McCall};
170333500955d731c73717af52088b7fc0e7a85681e7John McCall
17047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
17057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorstruct PackExpansionTypeLocInfo {
17067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  SourceLocation EllipsisLoc;
17077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
17087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
17097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionTypeLoc
1710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  : public ConcreteTypeLoc<UnqualTypeLoc, PackExpansionTypeLoc,
17117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor                           PackExpansionType, PackExpansionTypeLocInfo> {
17127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic:
17137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  SourceLocation getEllipsisLoc() const {
17147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return this->getLocalData()->EllipsisLoc;
17157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
17167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
17177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  void setEllipsisLoc(SourceLocation Loc) {
17187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    this->getLocalData()->EllipsisLoc = Loc;
17197536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
17207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
17217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  SourceRange getLocalSourceRange() const {
17227536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return SourceRange(getEllipsisLoc(), getEllipsisLoc());
17237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
17247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
1725c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
17267536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    setEllipsisLoc(Loc);
17277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
17287536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
17297536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  TypeLoc getPatternLoc() const {
17307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return getInnerTypeLoc();
17317536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
17327536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
17337536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType getInnerType() const {
17347536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return this->getTypePtr()->getPattern();
17357536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
17367536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
17377536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
1738b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanstruct AtomicTypeLocInfo {
1739b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  SourceLocation KWLoc, LParenLoc, RParenLoc;
1740b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman};
1741b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1742b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanclass AtomicTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, AtomicTypeLoc,
1743b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman                                             AtomicType, AtomicTypeLocInfo> {
1744ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic:
1745b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  TypeLoc getValueLoc() const {
1746b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return this->getInnerTypeLoc();
1747b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1748b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1749b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  SourceRange getLocalSourceRange() const {
1750b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return SourceRange(getKWLoc(), getRParenLoc());
1751b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1752b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1753b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  SourceLocation getKWLoc() const {
1754b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return this->getLocalData()->KWLoc;
1755b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1756b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void setKWLoc(SourceLocation Loc) {
1757b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    this->getLocalData()->KWLoc = Loc;
1758b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1759b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1760b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  SourceLocation getLParenLoc() const {
1761b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return this->getLocalData()->LParenLoc;
1762b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1763b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void setLParenLoc(SourceLocation Loc) {
1764b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    this->getLocalData()->LParenLoc = Loc;
1765b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1766b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1767b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  SourceLocation getRParenLoc() const {
1768b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return this->getLocalData()->RParenLoc;
1769b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1770b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void setRParenLoc(SourceLocation Loc) {
1771b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    this->getLocalData()->RParenLoc = Loc;
1772b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1773b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1774b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  SourceRange getParensRange() const {
1775b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return SourceRange(getLParenLoc(), getRParenLoc());
1776b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1777b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void setParensRange(SourceRange Range) {
1778b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    setLParenLoc(Range.getBegin());
1779b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    setRParenLoc(Range.getEnd());
1780b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1781b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1782b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1783b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    setKWLoc(Loc);
1784b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    setLParenLoc(Loc);
1785b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    setRParenLoc(Loc);
1786b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1787b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1788b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType getInnerType() const {
1789b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return this->getTypePtr()->getValueType();
1790b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
1791b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman};
1792b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1793b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
1794b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}
1795b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1796b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#endif
1797