TypeLoc.h revision b6ab6c1ca733fda2302a1c5066bdfc6218c89e41
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:
162c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  static void initializeImpl(ASTContext &Context, TypeLoc TL, SourceLocation Loc);
16351bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static TypeLoc getNextTypeLocImpl(TypeLoc TL);
164723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara  static TypeLoc IgnoreParensImpl(TypeLoc TL);
165bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
166b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
167b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1683c385c28cf1f27b193a620d2e51f814873362cebJohn McCall/// \brief Return the TypeLoc for a type source info.
1693c385c28cf1f27b193a620d2e51f814873362cebJohn McCallinline TypeLoc TypeSourceInfo::getTypeLoc() const {
1704ab92891a53adda8c52c1947351371da58e33f64Gabor Greif  return TypeLoc(Ty, const_cast<void*>(static_cast<const void*>(this + 1)));
1713c385c28cf1f27b193a620d2e51f814873362cebJohn McCall}
1723c385c28cf1f27b193a620d2e51f814873362cebJohn McCall
17334a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with
174489f7131d0f7746525de3b26204c8eb523d84505Gabor Greif/// no direct qualifiers.
17534a0447b8072e0da14c0980597da9d03a1495662John McCallclass UnqualTypeLoc : public TypeLoc {
17634a0447b8072e0da14c0980597da9d03a1495662John McCallpublic:
17734a0447b8072e0da14c0980597da9d03a1495662John McCall  UnqualTypeLoc() {}
178f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  UnqualTypeLoc(const Type *Ty, void *Data) : TypeLoc(Ty, Data) {}
17934a0447b8072e0da14c0980597da9d03a1495662John McCall
180f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *getTypePtr() const {
181f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    return reinterpret_cast<const Type*>(Ty);
18234a0447b8072e0da14c0980597da9d03a1495662John McCall  }
18334a0447b8072e0da14c0980597da9d03a1495662John McCall
18451bd803fbdade51d674598ed45da3d54190a656cJohn McCall  TypeLocClass getTypeLocClass() const {
18551bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return (TypeLocClass) getTypePtr()->getTypeClass();
18651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
18751bd803fbdade51d674598ed45da3d54190a656cJohn McCall
18834a0447b8072e0da14c0980597da9d03a1495662John McCall  static bool classof(const TypeLoc *TL) {
189a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return !TL->getType().hasLocalQualifiers();
19034a0447b8072e0da14c0980597da9d03a1495662John McCall  }
19134a0447b8072e0da14c0980597da9d03a1495662John McCall  static bool classof(const UnqualTypeLoc *TL) { return true; }
19234a0447b8072e0da14c0980597da9d03a1495662John McCall};
19334a0447b8072e0da14c0980597da9d03a1495662John McCall
19434a0447b8072e0da14c0980597da9d03a1495662John McCall/// \brief Wrapper of type source information for a type with
19534a0447b8072e0da14c0980597da9d03a1495662John McCall/// non-trivial direct qualifiers.
19634a0447b8072e0da14c0980597da9d03a1495662John McCall///
19734a0447b8072e0da14c0980597da9d03a1495662John McCall/// Currently, we intentionally do not provide source location for
19834a0447b8072e0da14c0980597da9d03a1495662John McCall/// type qualifiers.
19951bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass QualifiedTypeLoc : public TypeLoc {
20034a0447b8072e0da14c0980597da9d03a1495662John McCallpublic:
201bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
20234a0447b8072e0da14c0980597da9d03a1495662John McCall    return SourceRange();
20334a0447b8072e0da14c0980597da9d03a1495662John McCall  }
20434a0447b8072e0da14c0980597da9d03a1495662John McCall
20534a0447b8072e0da14c0980597da9d03a1495662John McCall  UnqualTypeLoc getUnqualifiedLoc() const {
20651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return UnqualTypeLoc(getTypePtr(), Data);
20734a0447b8072e0da14c0980597da9d03a1495662John McCall  }
20834a0447b8072e0da14c0980597da9d03a1495662John McCall
2094ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  /// Initializes the local data of this type source info block to
2104ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  /// provide no information.
211c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
2124ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    // do nothing
2134ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
2144ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
2154ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  TypeLoc getNextTypeLoc() const {
2164ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    return getUnqualifiedLoc();
2174ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
2184ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
21934a0447b8072e0da14c0980597da9d03a1495662John McCall  /// \brief Returns the size of the type source info data block that is
22034a0447b8072e0da14c0980597da9d03a1495662John McCall  /// specific to this type.
22134a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getLocalDataSize() const {
22234a0447b8072e0da14c0980597da9d03a1495662John McCall    // In fact, we don't currently preserve any location information
22334a0447b8072e0da14c0980597da9d03a1495662John McCall    // for qualifiers.
22434a0447b8072e0da14c0980597da9d03a1495662John McCall    return 0;
22534a0447b8072e0da14c0980597da9d03a1495662John McCall  }
22634a0447b8072e0da14c0980597da9d03a1495662John McCall
22734a0447b8072e0da14c0980597da9d03a1495662John McCall  /// \brief Returns the size of the type source info data block.
22834a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getFullDataSize() const {
22934a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalDataSize() +
230fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      getFullDataSizeForType(getType().getLocalUnqualifiedType());
23134a0447b8072e0da14c0980597da9d03a1495662John McCall  }
23234a0447b8072e0da14c0980597da9d03a1495662John McCall
23334a0447b8072e0da14c0980597da9d03a1495662John McCall  static bool classof(const TypeLoc *TL) {
234a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return TL->getType().hasLocalQualifiers();
23534a0447b8072e0da14c0980597da9d03a1495662John McCall  }
23651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static bool classof(const QualifiedTypeLoc *TL) { return true; }
23734a0447b8072e0da14c0980597da9d03a1495662John McCall};
23834a0447b8072e0da14c0980597da9d03a1495662John McCall
23934a0447b8072e0da14c0980597da9d03a1495662John McCallinline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {
24051bd803fbdade51d674598ed45da3d54190a656cJohn McCall  if (isa<QualifiedTypeLoc>(this))
24151bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return cast<QualifiedTypeLoc>(this)->getUnqualifiedLoc();
24234a0447b8072e0da14c0980597da9d03a1495662John McCall  return cast<UnqualTypeLoc>(*this);
24334a0447b8072e0da14c0980597da9d03a1495662John McCall}
24434a0447b8072e0da14c0980597da9d03a1495662John McCall
24534a0447b8072e0da14c0980597da9d03a1495662John McCall/// A metaprogramming base class for TypeLoc classes which correspond
246f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// to a particular Type subclass.  It is accepted for a single
247f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// TypeLoc class to correspond to multiple Type classes.
24834a0447b8072e0da14c0980597da9d03a1495662John McCall///
24934a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param Base a class from which to derive
25034a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param Derived the class deriving from this one
251f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall/// \param TypeClass the concrete Type subclass associated with this
252f2130a6e3cef10b435feadf6ad8bebaaf9a81a88John McCall///   location type
25334a0447b8072e0da14c0980597da9d03a1495662John McCall/// \param LocalData the structure type of local location data for
25434a0447b8072e0da14c0980597da9d03a1495662John McCall///   this type
25534a0447b8072e0da14c0980597da9d03a1495662John McCall///
25634a0447b8072e0da14c0980597da9d03a1495662John McCall/// sizeof(LocalData) needs to be a multiple of sizeof(void*) or
25734a0447b8072e0da14c0980597da9d03a1495662John McCall/// else the world will end.
25834a0447b8072e0da14c0980597da9d03a1495662John McCall///
25934a0447b8072e0da14c0980597da9d03a1495662John McCall/// TypeLocs with non-constant amounts of local data should override
26034a0447b8072e0da14c0980597da9d03a1495662John McCall/// getExtraLocalDataSize(); getExtraLocalData() will then point to
26134a0447b8072e0da14c0980597da9d03a1495662John McCall/// this extra memory.
26234a0447b8072e0da14c0980597da9d03a1495662John McCall///
263a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// TypeLocs with an inner type should define
264a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall///   QualType getInnerType() const
265a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// and getInnerTypeLoc() will then point to this inner type's
266a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall/// location data.
26751bd803fbdade51d674598ed45da3d54190a656cJohn McCall///
26851bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A word about hierarchies: this template is not designed to be
26951bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// derived from multiple times in a hierarchy.  It is also not
27051bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// designed to be used for classes where subtypes might provide
27151bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// different amounts of source information.  It should be subclassed
27251bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// only at the deepest portion of the hierarchy where all children
27351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// have identical source information; if that's an abstract type,
27451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// then further descendents should inherit from
27551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// InheritingConcreteTypeLoc instead.
27634a0447b8072e0da14c0980597da9d03a1495662John McCalltemplate <class Base, class Derived, class TypeClass, class LocalData>
27734a0447b8072e0da14c0980597da9d03a1495662John McCallclass ConcreteTypeLoc : public Base {
27834a0447b8072e0da14c0980597da9d03a1495662John McCall
27934a0447b8072e0da14c0980597da9d03a1495662John McCall  const Derived *asDerived() const {
28034a0447b8072e0da14c0980597da9d03a1495662John McCall    return static_cast<const Derived*>(this);
28134a0447b8072e0da14c0980597da9d03a1495662John McCall  }
28234a0447b8072e0da14c0980597da9d03a1495662John McCall
28334a0447b8072e0da14c0980597da9d03a1495662John McCallpublic:
28434a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getLocalDataSize() const {
28534a0447b8072e0da14c0980597da9d03a1495662John McCall    return sizeof(LocalData) + asDerived()->getExtraLocalDataSize();
28634a0447b8072e0da14c0980597da9d03a1495662John McCall  }
28734a0447b8072e0da14c0980597da9d03a1495662John McCall  // Give a default implementation that's useful for leaf types.
28834a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getFullDataSize() const {
28934a0447b8072e0da14c0980597da9d03a1495662John McCall    return asDerived()->getLocalDataSize() + getInnerTypeSize();
29034a0447b8072e0da14c0980597da9d03a1495662John McCall  }
29134a0447b8072e0da14c0980597da9d03a1495662John McCall
29234a0447b8072e0da14c0980597da9d03a1495662John McCall  static bool classofType(const Type *Ty) {
29334a0447b8072e0da14c0980597da9d03a1495662John McCall    return TypeClass::classof(Ty);
29434a0447b8072e0da14c0980597da9d03a1495662John McCall  }
29534a0447b8072e0da14c0980597da9d03a1495662John McCall
296e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  static bool classof(const TypeLoc *TL) {
297e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return Derived::classofType(TL->getTypePtr());
298e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
299e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  static bool classof(const UnqualTypeLoc *TL) {
300e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return Derived::classofType(TL->getTypePtr());
301e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
302e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  static bool classof(const Derived *TL) {
303e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return true;
304e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
305e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
3064ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  TypeLoc getNextTypeLoc() const {
3074ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    return getNextTypeLoc(asDerived()->getInnerType());
3084ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
3094ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
310f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypeClass *getTypePtr() const {
31151bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return cast<TypeClass>(Base::getTypePtr());
31234a0447b8072e0da14c0980597da9d03a1495662John McCall  }
31334a0447b8072e0da14c0980597da9d03a1495662John McCall
31451bd803fbdade51d674598ed45da3d54190a656cJohn McCallprotected:
31534a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getExtraLocalDataSize() const {
31634a0447b8072e0da14c0980597da9d03a1495662John McCall    return 0;
31734a0447b8072e0da14c0980597da9d03a1495662John McCall  }
31834a0447b8072e0da14c0980597da9d03a1495662John McCall
31934a0447b8072e0da14c0980597da9d03a1495662John McCall  LocalData *getLocalData() const {
32034a0447b8072e0da14c0980597da9d03a1495662John McCall    return static_cast<LocalData*>(Base::Data);
32134a0447b8072e0da14c0980597da9d03a1495662John McCall  }
32234a0447b8072e0da14c0980597da9d03a1495662John McCall
32334a0447b8072e0da14c0980597da9d03a1495662John McCall  /// Gets a pointer past the Info structure; useful for classes with
32434a0447b8072e0da14c0980597da9d03a1495662John McCall  /// local data that can't be captured in the Info (e.g. because it's
32534a0447b8072e0da14c0980597da9d03a1495662John McCall  /// of variable size).
32634a0447b8072e0da14c0980597da9d03a1495662John McCall  void *getExtraLocalData() const {
32734a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData() + 1;
32834a0447b8072e0da14c0980597da9d03a1495662John McCall  }
32934a0447b8072e0da14c0980597da9d03a1495662John McCall
33034a0447b8072e0da14c0980597da9d03a1495662John McCall  void *getNonLocalData() const {
33134a0447b8072e0da14c0980597da9d03a1495662John McCall    return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize();
33234a0447b8072e0da14c0980597da9d03a1495662John McCall  }
33334a0447b8072e0da14c0980597da9d03a1495662John McCall
334a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  struct HasNoInnerType {};
335a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  HasNoInnerType getInnerType() const { return HasNoInnerType(); }
33634a0447b8072e0da14c0980597da9d03a1495662John McCall
33734a0447b8072e0da14c0980597da9d03a1495662John McCall  TypeLoc getInnerTypeLoc() const {
33834a0447b8072e0da14c0980597da9d03a1495662John McCall    return TypeLoc(asDerived()->getInnerType(), getNonLocalData());
33934a0447b8072e0da14c0980597da9d03a1495662John McCall  }
34034a0447b8072e0da14c0980597da9d03a1495662John McCall
34134a0447b8072e0da14c0980597da9d03a1495662John McCallprivate:
34234a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getInnerTypeSize() const {
343a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall    return getInnerTypeSize(asDerived()->getInnerType());
344a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  }
345a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall
346a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  unsigned getInnerTypeSize(HasNoInnerType _) const {
34734a0447b8072e0da14c0980597da9d03a1495662John McCall    return 0;
34834a0447b8072e0da14c0980597da9d03a1495662John McCall  }
34934a0447b8072e0da14c0980597da9d03a1495662John McCall
350a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall  unsigned getInnerTypeSize(QualType _) const {
351a6f56429aa9a02e71426e99db8b0ae94d0115215John McCall    return getInnerTypeLoc().getFullDataSize();
35234a0447b8072e0da14c0980597da9d03a1495662John McCall  }
3534ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
3544ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  TypeLoc getNextTypeLoc(HasNoInnerType _) const {
3554ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    return TypeLoc();
3564ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
3574ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
3584ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  TypeLoc getNextTypeLoc(QualType T) const {
3594ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    return TypeLoc(T, getNonLocalData());
3604ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
36134a0447b8072e0da14c0980597da9d03a1495662John McCall};
36234a0447b8072e0da14c0980597da9d03a1495662John McCall
36351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A metaprogramming class designed for concrete subtypes of abstract
36451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// types where all subtypes share equivalently-structured source
36551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// information.  See the note on ConcreteTypeLoc.
36651bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Base, class Derived, class TypeClass>
36751bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass InheritingConcreteTypeLoc : public Base {
368b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
369713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor  static bool classofType(const Type *Ty) {
370713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor    return TypeClass::classof(Ty);
371713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor  }
372713da40fb093cb6ab50ddc57e1697fddf9802104Douglas Gregor
37351bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static bool classof(const TypeLoc *TL) {
37451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return Derived::classofType(TL->getTypePtr());
375b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
37651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static bool classof(const UnqualTypeLoc *TL) {
37751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return Derived::classofType(TL->getTypePtr());
378b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
37951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  static bool classof(const Derived *TL) {
38051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return true;
381b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
382b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
383f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypeClass *getTypePtr() const {
38451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return cast<TypeClass>(Base::getTypePtr());
3854ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
38634a0447b8072e0da14c0980597da9d03a1495662John McCall};
387b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
388ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
38951bd803fbdade51d674598ed45da3d54190a656cJohn McCallstruct TypeSpecLocInfo {
39034a0447b8072e0da14c0980597da9d03a1495662John McCall  SourceLocation NameLoc;
391b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
392b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
39351bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief A reasonable base class for TypeLocs that correspond to
39451bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// types that are written as a type-specifier.
395ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TypeSpecTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
396ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                               TypeSpecTypeLoc,
397ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                               Type,
398ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                               TypeSpecLocInfo> {
399b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
400ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  enum { LocalDataSize = sizeof(TypeSpecLocInfo) };
401ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
402b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getNameLoc() const {
40351bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return this->getLocalData()->NameLoc;
404b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
405b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setNameLoc(SourceLocation Loc) {
40651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    this->getLocalData()->NameLoc = Loc;
407b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
408bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
409b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis    return SourceRange(getNameLoc(), getNameLoc());
410b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
411c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
4124ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setNameLoc(Loc);
4134ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
414ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
415ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const TypeLoc *TL);
416ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const TypeSpecTypeLoc *TL) { return true; }
41751bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
4184ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
419ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
420ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorstruct BuiltinLocInfo {
421ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  SourceLocation BuiltinLoc;
422ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor};
423ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
424ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor/// \brief Wrapper for source info for builtin types.
425ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorclass BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
426ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor                                              BuiltinTypeLoc,
427ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor                                              BuiltinType,
428ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor                                              BuiltinLocInfo> {
429ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregorpublic:
430ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  enum { LocalDataSize = sizeof(BuiltinLocInfo) };
431ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
432ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  SourceLocation getBuiltinLoc() const {
433ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return getLocalData()->BuiltinLoc;
434ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
435ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setBuiltinLoc(SourceLocation Loc) {
436ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    getLocalData()->BuiltinLoc = Loc;
437ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
438ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
439ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  SourceLocation getNameLoc() const { return getBuiltinLoc(); }
440ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
441ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  WrittenBuiltinSpecs& getWrittenBuiltinSpecs() {
442ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
443ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
444ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
445ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
446ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
447ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
448ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool needsExtraLocalData() const {
449ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    BuiltinType::Kind bk = getTypePtr()->getKind();
450ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128)
451d038f361d2b4368af7ab85bd04d5aafcc3ea649dDouglas Gregor      || (bk >= BuiltinType::Short && bk <= BuiltinType::LongDouble)
452ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      || bk == BuiltinType::UChar
453ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      || bk == BuiltinType::SChar;
454ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
455ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
456ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  unsigned getExtraLocalDataSize() const {
457d31351288e25e8a7a2a919c99ffe281c2a41b53cDaniel Dunbar    return needsExtraLocalData() ? sizeof(WrittenBuiltinSpecs) : 0;
458ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
459ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
460bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
461ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return SourceRange(getBuiltinLoc(), getBuiltinLoc());
462ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
463ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
464ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  TypeSpecifierSign getWrittenSignSpec() const {
465ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
466ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return static_cast<TypeSpecifierSign>(getWrittenBuiltinSpecs().Sign);
467ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    else
468ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return TSS_unspecified;
469ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
470ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool hasWrittenSignSpec() const {
471ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return getWrittenSignSpec() != TSS_unspecified;
472ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
473ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setWrittenSignSpec(TypeSpecifierSign written) {
474ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
475ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      getWrittenBuiltinSpecs().Sign = written;
476ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
477ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
478ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  TypeSpecifierWidth getWrittenWidthSpec() const {
479ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
480ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return static_cast<TypeSpecifierWidth>(getWrittenBuiltinSpecs().Width);
481ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    else
482ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return TSW_unspecified;
483ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
484ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool hasWrittenWidthSpec() const {
485ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return getWrittenWidthSpec() != TSW_unspecified;
486ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
487ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setWrittenWidthSpec(TypeSpecifierWidth written) {
488ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
489ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      getWrittenBuiltinSpecs().Width = written;
490ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
491ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
492ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  TypeSpecifierType getWrittenTypeSpec() const;
493ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool hasWrittenTypeSpec() const {
494ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    return getWrittenTypeSpec() != TST_unspecified;
495ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
496ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setWrittenTypeSpec(TypeSpecifierType written) {
497ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
498ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      getWrittenBuiltinSpecs().Type = written;
499ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
500ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
501ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  bool hasModeAttr() const {
502ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
503ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return getWrittenBuiltinSpecs().ModeAttr;
504ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    else
505ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      return false;
506ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
507ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  void setModeAttr(bool written) {
508ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData())
509ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      getWrittenBuiltinSpecs().ModeAttr = written;
510ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
511ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
512c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
513ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    setBuiltinLoc(Loc);
514ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    if (needsExtraLocalData()) {
515ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs();
516ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      wbs.Sign = TSS_unspecified;
517ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      wbs.Width = TSW_unspecified;
518ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      wbs.Type = TST_unspecified;
519ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor      wbs.ModeAttr = false;
520ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    }
521ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  }
522ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor};
523ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
524ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor
52551bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for typedefs.
526ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TypedefTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
527ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                        TypedefTypeLoc,
528ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                        TypedefType> {
52951bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic:
5309036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis  TypedefDecl *getTypedefDecl() const {
53134a0447b8072e0da14c0980597da9d03a1495662John McCall    return getTypePtr()->getDecl();
5329036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis  }
53334a0447b8072e0da14c0980597da9d03a1495662John McCall};
5349036d5e369aae65e3baccdeed74c796e3d367b3dArgyrios Kyrtzidis
5353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// \brief Wrapper for source info for injected class names of class
5363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// templates.
5373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameTypeLoc :
5383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
5393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                     InjectedClassNameTypeLoc,
5403cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                     InjectedClassNameType> {
5413cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
5423cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
543ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for unresolved typename using decls.
544ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingTypeLoc :
545ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
546ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     UnresolvedUsingTypeLoc,
547ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     UnresolvedUsingType> {
548ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
549ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const {
550ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return getTypePtr()->getDecl();
551ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
552ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
553ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
554ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for tag types.  Note that this only
555ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// records source info for the name itself; a type written 'struct foo'
556ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// should be represented as an ElaboratedTypeLoc.  We currently
557ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// only do that when C++ is enabled because of the expense of
558ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// creating an ElaboratedType node for so many type references in C.
559ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TagTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
560ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                    TagTypeLoc,
561ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                    TagType> {
562ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
563ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TagDecl *getDecl() const { return getTypePtr()->getDecl(); }
564ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
565ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
566ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for record types.
567ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
568ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                       RecordTypeLoc,
569ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                       RecordType> {
570ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
571ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  RecordDecl *getDecl() const { return getTypePtr()->getDecl(); }
572ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
573ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
574ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Wrapper for source info for enum types.
575ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
576ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                     EnumTypeLoc,
577ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                     EnumType> {
578ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
579ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  EnumDecl *getDecl() const { return getTypePtr()->getDecl(); }
580ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
581b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
58249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Wrapper for template type parameters.
583ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass TemplateTypeParmTypeLoc :
584ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
585ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     TemplateTypeParmTypeLoc,
586ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     TemplateTypeParmType> {
58749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
58849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
58949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Wrapper for substituted template type parameters.
59049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmTypeLoc :
591ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
592ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     SubstTemplateTypeParmTypeLoc,
593ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     SubstTemplateTypeParmType> {
59449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
59551bd803fbdade51d674598ed45da3d54190a656cJohn McCall
596c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief Wrapper for substituted template type parameters.
597c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackTypeLoc :
598c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
599c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                     SubstTemplateTypeParmPackTypeLoc,
600c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                     SubstTemplateTypeParmPackType> {
601c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor};
602c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
6039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallstruct AttributedLocInfo {
6049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  union {
6059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Expr *ExprOperand;
6069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    /// A raw SourceLocation.
6089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned EnumOperandLoc;
6099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
6109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceRange OperandParens;
6129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceLocation AttrLoc;
6149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
6159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// \brief Type source information for an attributed type.
6179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
6189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                 AttributedTypeLoc,
6199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                 AttributedType,
6209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                 AttributedLocInfo> {
6219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
6229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedType::Kind getAttrKind() const {
6239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getTypePtr()->getAttrKind();
6249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool hasAttrExprOperand() const {
6279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return (getAttrKind() >= AttributedType::FirstExprOperandKind &&
6289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall            getAttrKind() <= AttributedType::LastExprOperandKind);
6299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool hasAttrEnumOperand() const {
6329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return (getAttrKind() >= AttributedType::FirstEnumOperandKind &&
6339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall            getAttrKind() <= AttributedType::LastEnumOperandKind);
6349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool hasAttrOperand() const {
6379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return hasAttrExprOperand() || hasAttrEnumOperand();
6389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The modified type, which is generally canonically different from
6419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// the attribute type.
6429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    int main(int, char**) __attribute__((noreturn))
6439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    ~~~     ~~~~~~~~~~~~~
6449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  TypeLoc getModifiedLoc() const {
6459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getInnerTypeLoc();
6469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The location of the attribute name, i.e.
6499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    __attribute__((regparm(1000)))
6509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///                   ^~~~~~~
6519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceLocation getAttrNameLoc() const {
6529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getLocalData()->AttrLoc;
6539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void setAttrNameLoc(SourceLocation loc) {
6559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    getLocalData()->AttrLoc = loc;
6569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The attribute's expression operand, if it has one.
6599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    void *cur_thread __attribute__((address_space(21)))
6609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///                                                  ^~
6619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Expr *getAttrExprOperand() const {
6629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrExprOperand());
6639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getLocalData()->ExprOperand;
6649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void setAttrExprOperand(Expr *e) {
6669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrExprOperand());
6679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    getLocalData()->ExprOperand = e;
6689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The location of the attribute's enumerated operand, if it has one.
6719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    void * __attribute__((objc_gc(weak)))
6729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///                                  ^~~~
6739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceLocation getAttrEnumOperandLoc() const {
6749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrEnumOperand());
6759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return SourceLocation::getFromRawEncoding(getLocalData()->EnumOperandLoc);
6769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void setAttrEnumOperandLoc(SourceLocation loc) {
6789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrEnumOperand());
6799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    getLocalData()->EnumOperandLoc = loc.getRawEncoding();
6809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// The location of the parentheses around the operand, if there is
6839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  /// an operand.
6849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///    void * __attribute__((objc_gc(weak)))
6859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  ///                                 ^    ^
6869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceRange getAttrOperandParensRange() const {
6879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrOperand());
6889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getLocalData()->OperandParens;
6899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void setAttrOperandParensRange(SourceRange range) {
6919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    assert(hasAttrOperand());
6929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    getLocalData()->OperandParens = range;
6939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
6949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
6959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  SourceRange getLocalSourceRange() const {
6969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Note that this does *not* include the range of the attribute
6979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // enclosure, e.g.:
6989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    //    __attribute__((foo(bar)))
6999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    //    ^~~~~~~~~~~~~~~        ~~
7009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // or
7019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    //    [[foo(bar)]]
7029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    //    ^~        ~~
7039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // That enclosure doesn't necessarily belong to a single attribute
7049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // anyway.
7059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    SourceRange range(getAttrNameLoc());
7069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (hasAttrOperand())
7079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      range.setEnd(getAttrOperandParensRange().getEnd());
7089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return range;
7099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
7109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
711c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation loc) {
7129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    setAttrNameLoc(loc);
7139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (hasAttrExprOperand()) {
7149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      setAttrOperandParensRange(SourceRange(loc));
7159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      setAttrExprOperand(0);
7169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    } else if (hasAttrEnumOperand()) {
7179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      setAttrOperandParensRange(SourceRange(loc));
7189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      setAttrEnumOperandLoc(loc);
7199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    }
7209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
7219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
7229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getInnerType() const {
7239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return getTypePtr()->getModifiedType();
7249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
7259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
7269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
727eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis
72834a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ObjCProtocolListLocInfo {
72954e14c4db764c0636160d26c5bbf491637c83a76John McCall  SourceLocation LAngleLoc;
73054e14c4db764c0636160d26c5bbf491637c83a76John McCall  SourceLocation RAngleLoc;
731ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall  bool HasBaseTypeAsWritten;
732eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis};
733eb66759e9a1d7c041354d132a14674b2d948059bArgyrios Kyrtzidis
73454e14c4db764c0636160d26c5bbf491637c83a76John McCall// A helper class for defining ObjC TypeLocs that can qualified with
73554e14c4db764c0636160d26c5bbf491637c83a76John McCall// protocols.
73654e14c4db764c0636160d26c5bbf491637c83a76John McCall//
73754e14c4db764c0636160d26c5bbf491637c83a76John McCall// TypeClass basically has to be either ObjCInterfaceType or
73854e14c4db764c0636160d26c5bbf491637c83a76John McCall// ObjCObjectPointerType.
739c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
740c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                 ObjCObjectTypeLoc,
741c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                 ObjCObjectType,
742c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                 ObjCProtocolListLocInfo> {
743f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  // SourceLocations are stored after Info, one for each Protocol.
744f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  SourceLocation *getProtocolLocArray() const {
74554e14c4db764c0636160d26c5bbf491637c83a76John McCall    return (SourceLocation*) this->getExtraLocalData();
74654e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
74754e14c4db764c0636160d26c5bbf491637c83a76John McCall
748f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidispublic:
749f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  SourceLocation getLAngleLoc() const {
75054e14c4db764c0636160d26c5bbf491637c83a76John McCall    return this->getLocalData()->LAngleLoc;
751f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
752f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  void setLAngleLoc(SourceLocation Loc) {
75354e14c4db764c0636160d26c5bbf491637c83a76John McCall    this->getLocalData()->LAngleLoc = Loc;
754f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
755f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
756f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  SourceLocation getRAngleLoc() const {
75754e14c4db764c0636160d26c5bbf491637c83a76John McCall    return this->getLocalData()->RAngleLoc;
758f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
759f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  void setRAngleLoc(SourceLocation Loc) {
76054e14c4db764c0636160d26c5bbf491637c83a76John McCall    this->getLocalData()->RAngleLoc = Loc;
761f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
762f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
763f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  unsigned getNumProtocols() const {
76454e14c4db764c0636160d26c5bbf491637c83a76John McCall    return this->getTypePtr()->getNumProtocols();
765f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
766f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
767f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  SourceLocation getProtocolLoc(unsigned i) const {
768f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    assert(i < getNumProtocols() && "Index is out of bounds!");
769f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    return getProtocolLocArray()[i];
770f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
771f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  void setProtocolLoc(unsigned i, SourceLocation Loc) {
772f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    assert(i < getNumProtocols() && "Index is out of bounds!");
773f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    getProtocolLocArray()[i] = Loc;
774f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
775f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
776f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  ObjCProtocolDecl *getProtocol(unsigned i) const {
777f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    assert(i < getNumProtocols() && "Index is out of bounds!");
77854e14c4db764c0636160d26c5bbf491637c83a76John McCall    return *(this->getTypePtr()->qual_begin() + i);
779f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
780f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
781c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool hasBaseTypeAsWritten() const {
782ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall    return getLocalData()->HasBaseTypeAsWritten;
783c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
784c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
785c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void setHasBaseTypeAsWritten(bool HasBaseType) {
786ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall    getLocalData()->HasBaseTypeAsWritten = HasBaseType;
787c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
788c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
789c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TypeLoc getBaseLoc() const {
790c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getInnerTypeLoc();
791c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
792c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
793bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
794f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis    return SourceRange(getLAngleLoc(), getRAngleLoc());
795f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
796f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
797c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
798ca6773808f8e75ffa86847e9d12885c69e9de53eJohn McCall    setHasBaseTypeAsWritten(true);
799c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    setLAngleLoc(Loc);
800c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    setRAngleLoc(Loc);
801c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    for (unsigned i = 0, e = getNumProtocols(); i != e; ++i)
802c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      setProtocolLoc(i, Loc);
8034ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
8044ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
80534a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getExtraLocalDataSize() const {
80654e14c4db764c0636160d26c5bbf491637c83a76John McCall    return this->getNumProtocols() * sizeof(SourceLocation);
80754e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
808c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
809c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getInnerType() const {
810c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getTypePtr()->getBaseType();
811c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
81254e14c4db764c0636160d26c5bbf491637c83a76John McCall};
81354e14c4db764c0636160d26c5bbf491637c83a76John McCall
81454e14c4db764c0636160d26c5bbf491637c83a76John McCall
815c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallstruct ObjCInterfaceLocInfo {
81654e14c4db764c0636160d26c5bbf491637c83a76John McCall  SourceLocation NameLoc;
81754e14c4db764c0636160d26c5bbf491637c83a76John McCall};
81854e14c4db764c0636160d26c5bbf491637c83a76John McCall
81954e14c4db764c0636160d26c5bbf491637c83a76John McCall/// \brief Wrapper for source info for ObjC interfaces.
820a8bef693d8761e31845a26e136f8d3a0983d2f46Nick Lewyckyclass ObjCInterfaceTypeLoc : public ConcreteTypeLoc<ObjCObjectTypeLoc,
821c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                    ObjCInterfaceTypeLoc,
822c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                    ObjCInterfaceType,
823c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                                    ObjCInterfaceLocInfo> {
82454e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic:
82554e14c4db764c0636160d26c5bbf491637c83a76John McCall  ObjCInterfaceDecl *getIFaceDecl() const {
82654e14c4db764c0636160d26c5bbf491637c83a76John McCall    return getTypePtr()->getDecl();
82754e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
82854e14c4db764c0636160d26c5bbf491637c83a76John McCall
82954e14c4db764c0636160d26c5bbf491637c83a76John McCall  SourceLocation getNameLoc() const {
83054e14c4db764c0636160d26c5bbf491637c83a76John McCall    return getLocalData()->NameLoc;
83154e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
83254e14c4db764c0636160d26c5bbf491637c83a76John McCall
83354e14c4db764c0636160d26c5bbf491637c83a76John McCall  void setNameLoc(SourceLocation Loc) {
83454e14c4db764c0636160d26c5bbf491637c83a76John McCall    getLocalData()->NameLoc = Loc;
83554e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
83654e14c4db764c0636160d26c5bbf491637c83a76John McCall
837bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
838c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return SourceRange(getNameLoc());
83954e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
84054e14c4db764c0636160d26c5bbf491637c83a76John McCall
841c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
84254e14c4db764c0636160d26c5bbf491637c83a76John McCall    setNameLoc(Loc);
843f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis  }
84454e14c4db764c0636160d26c5bbf491637c83a76John McCall};
84554e14c4db764c0636160d26c5bbf491637c83a76John McCall
846075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarastruct ParenLocInfo {
847075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceLocation LParenLoc;
848075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceLocation RParenLoc;
849075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
850075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
851075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenTypeLoc
852075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  : public ConcreteTypeLoc<UnqualTypeLoc, ParenTypeLoc, ParenType,
853075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                           ParenLocInfo> {
854075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
855075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceLocation getLParenLoc() const {
856075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return this->getLocalData()->LParenLoc;
857075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
858075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceLocation getRParenLoc() const {
859075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return this->getLocalData()->RParenLoc;
860075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
861075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void setLParenLoc(SourceLocation Loc) {
862075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    this->getLocalData()->LParenLoc = Loc;
863075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
864075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void setRParenLoc(SourceLocation Loc) {
865075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    this->getLocalData()->RParenLoc = Loc;
866075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
867075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
868075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  SourceRange getLocalSourceRange() const {
869075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return SourceRange(getLParenLoc(), getRParenLoc());
870075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
871075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
872c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
873075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    setLParenLoc(Loc);
874075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    setRParenLoc(Loc);
875075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
876075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
877075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  TypeLoc getInnerLoc() const {
878075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return getInnerTypeLoc();
879075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
880075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
881075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const {
882075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return this->getTypePtr()->getInnerType();
883075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
884075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
885075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
886f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
88751bd803fbdade51d674598ed45da3d54190a656cJohn McCallstruct PointerLikeLocInfo {
88834a0447b8072e0da14c0980597da9d03a1495662John McCall  SourceLocation StarLoc;
889f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis};
890f352bddf015e537350416c296dd2963524f554f9Argyrios Kyrtzidis
89151bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// A base class for
89251bd803fbdade51d674598ed45da3d54190a656cJohn McCalltemplate <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo>
89351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived,
89451bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                  TypeClass, LocalData> {
895bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallpublic:
89651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  SourceLocation getSigilLoc() const {
89751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return this->getLocalData()->StarLoc;
898b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
89951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void setSigilLoc(SourceLocation Loc) {
90051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    this->getLocalData()->StarLoc = Loc;
901b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
902b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
903b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  TypeLoc getPointeeLoc() const {
90451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return this->getInnerTypeLoc();
905b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
906b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
907bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
90851bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return SourceRange(getSigilLoc(), getSigilLoc());
909b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
910b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
911c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
91251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
9134ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
9144ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
91551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  QualType getInnerType() const {
91651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return this->getTypePtr()->getPointeeType();
91751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
91834a0447b8072e0da14c0980597da9d03a1495662John McCall};
919b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
920b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
92151bd803fbdade51d674598ed45da3d54190a656cJohn McCall/// \brief Wrapper for source info for pointers.
92251bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc,
92351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                 PointerType> {
92451bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic:
92551bd803fbdade51d674598ed45da3d54190a656cJohn McCall  SourceLocation getStarLoc() const {
92651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
92751bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
92851bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void setStarLoc(SourceLocation Loc) {
92951bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
93051bd803fbdade51d674598ed45da3d54190a656cJohn McCall  }
931b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
932b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
93351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
934b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for block pointers.
93551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc,
93651bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                      BlockPointerType> {
937b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
938b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getCaretLoc() const {
93951bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
940b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
941b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setCaretLoc(SourceLocation Loc) {
94251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
943b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
94434a0447b8072e0da14c0980597da9d03a1495662John McCall};
945b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
946b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnarastruct MemberPointerLocInfo : public PointerLikeLocInfo {
947b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo *ClassTInfo;
948b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara};
949b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
950b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for member pointers.
95151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc,
952b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara                                                       MemberPointerType,
953b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara                                                       MemberPointerLocInfo> {
954b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
955b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getStarLoc() const {
95651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
957b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
958b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setStarLoc(SourceLocation Loc) {
95951bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
9604ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
961b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
962b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  const Type *getClass() const {
963b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    return getTypePtr()->getClass();
964b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
965b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo *getClassTInfo() const {
966b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    return getLocalData()->ClassTInfo;
967b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
968b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  void setClassTInfo(TypeSourceInfo* TI) {
969b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    getLocalData()->ClassTInfo = TI;
970b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
971b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
972b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
973b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    setSigilLoc(Loc);
974b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    setClassTInfo(0);
975b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
976b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
977b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  SourceRange getLocalSourceRange() const {
978b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (TypeSourceInfo *TI = getClassTInfo())
979b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return SourceRange(TI->getTypeLoc().getBeginLoc(), getStarLoc());
980b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    else
981b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return SourceRange(getStarLoc());
982b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
98334a0447b8072e0da14c0980597da9d03a1495662John McCall};
984b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
985c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Wraps an ObjCPointerType with source location information.
986c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectPointerTypeLoc :
987c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    public PointerLikeTypeLoc<ObjCObjectPointerTypeLoc,
988c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                              ObjCObjectPointerType> {
989c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
990c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  SourceLocation getStarLoc() const {
991c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getSigilLoc();
992c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
993c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
994c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void setStarLoc(SourceLocation Loc) {
995c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    setSigilLoc(Loc);
996c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
997c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
998c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
999b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
100051bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc,
100151bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                   ReferenceType> {
100254e14c4db764c0636160d26c5bbf491637c83a76John McCallpublic:
100354e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getInnerType() const {
100454e14c4db764c0636160d26c5bbf491637c83a76John McCall    return getTypePtr()->getPointeeTypeAsWritten();
100554e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
1006b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
1007b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1008bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallclass LValueReferenceTypeLoc :
1009bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall    public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1010bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall                                     LValueReferenceTypeLoc,
1011bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall                                     LValueReferenceType> {
1012b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
1013b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getAmpLoc() const {
101451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
1015b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1016b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setAmpLoc(SourceLocation Loc) {
101751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
1018b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
101951bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
1020b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1021bb833dcc562f686a0652865d1945cfa3a421379cJohn McCallclass RValueReferenceTypeLoc :
1022bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall    public InheritingConcreteTypeLoc<ReferenceTypeLoc,
1023bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall                                     RValueReferenceTypeLoc,
1024bb833dcc562f686a0652865d1945cfa3a421379cJohn McCall                                     RValueReferenceType> {
102551bd803fbdade51d674598ed45da3d54190a656cJohn McCallpublic:
102651bd803fbdade51d674598ed45da3d54190a656cJohn McCall  SourceLocation getAmpAmpLoc() const {
102751bd803fbdade51d674598ed45da3d54190a656cJohn McCall    return getSigilLoc();
1028b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
102951bd803fbdade51d674598ed45da3d54190a656cJohn McCall  void setAmpAmpLoc(SourceLocation Loc) {
103051bd803fbdade51d674598ed45da3d54190a656cJohn McCall    setSigilLoc(Loc);
1031b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
103251bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
1033b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1034b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
103534a0447b8072e0da14c0980597da9d03a1495662John McCallstruct FunctionLocInfo {
103634a0447b8072e0da14c0980597da9d03a1495662John McCall  SourceLocation LParenLoc, RParenLoc;
1037dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  bool TrailingReturn;
1038b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
1039b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1040b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for functions.
104151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
104251bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                               FunctionTypeLoc,
104351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                               FunctionType,
104451bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                               FunctionLocInfo> {
1045b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
1046b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getLParenLoc() const {
104734a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData()->LParenLoc;
1048b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1049b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setLParenLoc(SourceLocation Loc) {
105034a0447b8072e0da14c0980597da9d03a1495662John McCall    getLocalData()->LParenLoc = Loc;
1051b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1052b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1053b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getRParenLoc() const {
105434a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData()->RParenLoc;
1055b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1056b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setRParenLoc(SourceLocation Loc) {
105734a0447b8072e0da14c0980597da9d03a1495662John McCall    getLocalData()->RParenLoc = Loc;
1058b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1059b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1060dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  bool getTrailingReturn() const {
1061dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    return getLocalData()->TrailingReturn;
1062dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
1063dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  void setTrailingReturn(bool Trailing) {
1064dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    getLocalData()->TrailingReturn = Trailing;
1065dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
1066dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
1067a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  // ParmVarDecls* are stored after Info, one for each argument.
1068a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  ParmVarDecl **getParmArray() const {
1069a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    return (ParmVarDecl**) getExtraLocalData();
1070a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  }
1071a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor
1072b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  unsigned getNumArgs() const {
107334a0447b8072e0da14c0980597da9d03a1495662John McCall    if (isa<FunctionNoProtoType>(getTypePtr()))
1074b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis      return 0;
107534a0447b8072e0da14c0980597da9d03a1495662John McCall    return cast<FunctionProtoType>(getTypePtr())->getNumArgs();
1076b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1077b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; }
1078b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; }
1079b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1080b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  TypeLoc getResultLoc() const {
108134a0447b8072e0da14c0980597da9d03a1495662John McCall    return getInnerTypeLoc();
1082b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1083b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1084bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1085b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis    return SourceRange(getLParenLoc(), getRParenLoc());
1086b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1087b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1088c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
10894ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setLParenLoc(Loc);
10904ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setRParenLoc(Loc);
1091dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    setTrailingReturn(false);
10924ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    for (unsigned i = 0, e = getNumArgs(); i != e; ++i)
10934ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall      setArg(i, NULL);
10944ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
10954ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
1096b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// \brief Returns the size of the type source info data block that is
1097b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  /// specific to this type.
109834a0447b8072e0da14c0980597da9d03a1495662John McCall  unsigned getExtraLocalDataSize() const {
109934a0447b8072e0da14c0980597da9d03a1495662John McCall    return getNumArgs() * sizeof(ParmVarDecl*);
1100b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1101b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
110234a0447b8072e0da14c0980597da9d03a1495662John McCall  QualType getInnerType() const { return getTypePtr()->getResultType(); }
110334a0447b8072e0da14c0980597da9d03a1495662John McCall};
110434a0447b8072e0da14c0980597da9d03a1495662John McCall
110551bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionProtoTypeLoc :
110651bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<FunctionTypeLoc,
110751bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     FunctionProtoTypeLoc,
110851bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     FunctionProtoType> {
110951bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
111051bd803fbdade51d674598ed45da3d54190a656cJohn McCall
111151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass FunctionNoProtoTypeLoc :
111251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<FunctionTypeLoc,
111351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     FunctionNoProtoTypeLoc,
111451bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     FunctionNoProtoType> {
111551bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
111651bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1117b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
111834a0447b8072e0da14c0980597da9d03a1495662John McCallstruct ArrayLocInfo {
111934a0447b8072e0da14c0980597da9d03a1495662John McCall  SourceLocation LBracketLoc, RBracketLoc;
112034a0447b8072e0da14c0980597da9d03a1495662John McCall  Expr *Size;
1121b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
1122b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1123b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Wrapper for source info for arrays.
112451bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
112551bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                            ArrayTypeLoc,
112651bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                            ArrayType,
112751bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                            ArrayLocInfo> {
1128b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidispublic:
1129b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getLBracketLoc() const {
113034a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData()->LBracketLoc;
1131b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1132b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setLBracketLoc(SourceLocation Loc) {
113334a0447b8072e0da14c0980597da9d03a1495662John McCall    getLocalData()->LBracketLoc = Loc;
1134b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1135b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1136b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  SourceLocation getRBracketLoc() const {
113734a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData()->RBracketLoc;
1138b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1139b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setRBracketLoc(SourceLocation Loc) {
114034a0447b8072e0da14c0980597da9d03a1495662John McCall    getLocalData()->RBracketLoc = Loc;
1141b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1142b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
114385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  SourceRange getBracketsRange() const {
114485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return SourceRange(getLBracketLoc(), getRBracketLoc());
114585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
114685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
1147b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  Expr *getSizeExpr() const {
114834a0447b8072e0da14c0980597da9d03a1495662John McCall    return getLocalData()->Size;
1149b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1150b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  void setSizeExpr(Expr *Size) {
115134a0447b8072e0da14c0980597da9d03a1495662John McCall    getLocalData()->Size = Size;
1152b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1153b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1154b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  TypeLoc getElementLoc() const {
115534a0447b8072e0da14c0980597da9d03a1495662John McCall    return getInnerTypeLoc();
1156b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1157b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1158bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1159b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis    return SourceRange(getLBracketLoc(), getRBracketLoc());
1160b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis  }
1161b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1162c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
11634ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setLBracketLoc(Loc);
11644ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setRBracketLoc(Loc);
11654ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall    setSizeExpr(NULL);
11664ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall  }
11674ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71aJohn McCall
116834a0447b8072e0da14c0980597da9d03a1495662John McCall  QualType getInnerType() const { return getTypePtr()->getElementType(); }
1169b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis};
1170b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
117151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ConstantArrayTypeLoc :
117251bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<ArrayTypeLoc,
117351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     ConstantArrayTypeLoc,
117451bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     ConstantArrayType> {
117551bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
117651bd803fbdade51d674598ed45da3d54190a656cJohn McCall
117751bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass IncompleteArrayTypeLoc :
117851bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<ArrayTypeLoc,
117951bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     IncompleteArrayTypeLoc,
118051bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     IncompleteArrayType> {
118151bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
118251bd803fbdade51d674598ed45da3d54190a656cJohn McCall
118351bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DependentSizedArrayTypeLoc :
118451bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<ArrayTypeLoc,
118551bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     DependentSizedArrayTypeLoc,
118651bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     DependentSizedArrayType> {
118751bd803fbdade51d674598ed45da3d54190a656cJohn McCall
118851bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
118951bd803fbdade51d674598ed45da3d54190a656cJohn McCall
119051bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass VariableArrayTypeLoc :
119151bd803fbdade51d674598ed45da3d54190a656cJohn McCall    public InheritingConcreteTypeLoc<ArrayTypeLoc,
119251bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     VariableArrayTypeLoc,
119351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                     VariableArrayType> {
119451bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
119551bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1196833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1197833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall// Location information for a TemplateName.  Rudimentary for now.
1198833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstruct TemplateNameLocInfo {
1199833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation NameLoc;
1200833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall};
1201833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1202833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstruct TemplateSpecializationLocInfo : TemplateNameLocInfo {
1203833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation LAngleLoc;
1204833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation RAngleLoc;
1205833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall};
1206833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1207833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallclass TemplateSpecializationTypeLoc :
1208833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    public ConcreteTypeLoc<UnqualTypeLoc,
1209833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                           TemplateSpecializationTypeLoc,
1210833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                           TemplateSpecializationType,
1211833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                           TemplateSpecializationLocInfo> {
1212833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallpublic:
1213833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation getLAngleLoc() const {
1214833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getLocalData()->LAngleLoc;
1215833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1216833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void setLAngleLoc(SourceLocation Loc) {
1217833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getLocalData()->LAngleLoc = Loc;
1218833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1219833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1220833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation getRAngleLoc() const {
1221833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getLocalData()->RAngleLoc;
1222833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1223833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void setRAngleLoc(SourceLocation Loc) {
1224833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getLocalData()->RAngleLoc = Loc;
1225833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1226833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1227833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  unsigned getNumArgs() const {
1228833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getTypePtr()->getNumArgs();
1229833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1230833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
1231833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getArgInfos()[i] = AI;
1232833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1233833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
1234833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getArgInfos()[i];
1235833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1236833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1237833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLoc getArgLoc(unsigned i) const {
1238833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
1239833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1240833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1241833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation getTemplateNameLoc() const {
1242833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getLocalData()->NameLoc;
1243833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1244833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void setTemplateNameLoc(SourceLocation Loc) {
1245833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getLocalData()->NameLoc = Loc;
1246833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1247833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1248833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief - Copy the location information from the given info.
1249833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void copy(TemplateSpecializationTypeLoc Loc) {
1250833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    unsigned size = getFullDataSize();
1251833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    assert(size == Loc.getFullDataSize());
1252833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1253833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // We're potentially copying Expr references here.  We don't
1254a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    // bother retaining them because TypeSourceInfos live forever, so
1255833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // as long as the Expr was retained when originally written into
1256833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // the TypeLoc, we're okay.
1257833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    memcpy(Data, Loc.Data, size);
1258833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1259833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1260bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1261833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return SourceRange(getTemplateNameLoc(), getRAngleLoc());
1262833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1263833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1264c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1265833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    setLAngleLoc(Loc);
1266833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    setRAngleLoc(Loc);
1267833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    setTemplateNameLoc(Loc);
1268c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor    initializeArgLocs(Context, getNumArgs(), getTypePtr()->getArgs(),
126933500955d731c73717af52088b7fc0e7a85681e7John McCall                      getArgInfos(), Loc);
127033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
1271833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1272c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  static void initializeArgLocs(ASTContext &Context, unsigned NumArgs,
127333500955d731c73717af52088b7fc0e7a85681e7John McCall                                const TemplateArgument *Args,
127433500955d731c73717af52088b7fc0e7a85681e7John McCall                                TemplateArgumentLocInfo *ArgInfos,
1275c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor                                SourceLocation Loc);
1276833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1277833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  unsigned getExtraLocalDataSize() const {
1278833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return getNumArgs() * sizeof(TemplateArgumentLocInfo);
1279833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1280833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1281833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallprivate:
1282833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo *getArgInfos() const {
1283833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
1284833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
1285833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall};
1286833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1287ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//===----------------------------------------------------------------------===//
1288ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//
1289ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//  All of these need proper implementations.
1290ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//
1291ed97649e9574b9d854fa4d6109c9333ae0993554John McCall//===----------------------------------------------------------------------===//
129251bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1293ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: size expression and attribute locations (or keyword if we
1294ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// ever fully support altivec syntax).
1295ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass VectorTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1296ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                       VectorTypeLoc,
1297ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                       VectorType> {
129851bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
129951bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1300ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: size expression and attribute locations.
130151bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc,
130251bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                          ExtVectorTypeLoc,
130351bd803fbdade51d674598ed45da3d54190a656cJohn McCall                                                          ExtVectorType> {
130451bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
130551bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1306ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: attribute locations.
130751bd803fbdade51d674598ed45da3d54190a656cJohn McCall// For some reason, this isn't a subtype of VectorType.
130851bd803fbdade51d674598ed45da3d54190a656cJohn McCallclass DependentSizedExtVectorTypeLoc :
1309ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1310ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     DependentSizedExtVectorTypeLoc,
1311ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                     DependentSizedExtVectorType> {
131251bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
131351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1314ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: location of the '_Complex' keyword.
1315ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass ComplexTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1316ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                        ComplexTypeLoc,
1317ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                        ComplexType> {
131851bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
131951bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1320cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeofLocInfo {
1321cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation TypeofLoc;
1322cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation LParenLoc;
1323cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation RParenLoc;
132451bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
132551bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1326cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeOfExprTypeLocInfo : public TypeofLocInfo {
1327cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall};
1328cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1329cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallstruct TypeOfTypeLocInfo : public TypeofLocInfo {
1330cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* UnderlyingTInfo;
1331cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall};
1332cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1333cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCalltemplate <class Derived, class TypeClass, class LocalData = TypeofLocInfo>
1334cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeofLikeTypeLoc
1335cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> {
1336cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic:
1337cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation getTypeofLoc() const {
1338cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getLocalData()->TypeofLoc;
1339cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1340cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setTypeofLoc(SourceLocation Loc) {
1341cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    this->getLocalData()->TypeofLoc = Loc;
1342cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1343cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1344cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation getLParenLoc() const {
1345cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getLocalData()->LParenLoc;
1346cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1347cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setLParenLoc(SourceLocation Loc) {
1348cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    this->getLocalData()->LParenLoc = Loc;
1349cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1350cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1351cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceLocation getRParenLoc() const {
1352cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getLocalData()->RParenLoc;
1353cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1354cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setRParenLoc(SourceLocation Loc) {
1355cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    this->getLocalData()->RParenLoc = Loc;
1356cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1357cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1358cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  SourceRange getParensRange() const {
1359cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return SourceRange(getLParenLoc(), getRParenLoc());
1360cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1361cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setParensRange(SourceRange range) {
1362cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      setLParenLoc(range.getBegin());
1363cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      setRParenLoc(range.getEnd());
1364cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1365cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1366bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1367cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return SourceRange(getTypeofLoc(), getRParenLoc());
1368cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1369cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1370c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
1371cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    setTypeofLoc(Loc);
1372cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    setLParenLoc(Loc);
1373cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    setRParenLoc(Loc);
1374cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1375cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall};
1376cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1377cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeOfExprTypeLoc : public TypeofLikeTypeLoc<TypeOfExprTypeLoc,
1378cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall                                                   TypeOfExprType,
1379cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall                                                   TypeOfExprTypeLocInfo> {
1380cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic:
1381cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  Expr* getUnderlyingExpr() const {
1382cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return getTypePtr()->getUnderlyingExpr();
1383cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1384cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  // Reimplemented to account for GNU/C++ extension
1385cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  //     typeof unary-expression
1386cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  // where there are no parentheses.
1387bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const;
1388cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall};
1389cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall
1390cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallclass TypeOfTypeLoc
1391cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  : public TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo> {
1392cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCallpublic:
1393cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  QualType getUnderlyingType() const {
1394cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getTypePtr()->getUnderlyingType();
1395cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1396cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* getUnderlyingTInfo() const {
1397cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    return this->getLocalData()->UnderlyingTInfo;
1398cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
1399cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  void setUnderlyingTInfo(TypeSourceInfo* TI) const {
1400cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    this->getLocalData()->UnderlyingTInfo = TI;
1401cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  }
140251bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
140351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
1404ed97649e9574b9d854fa4d6109c9333ae0993554John McCall// FIXME: location of the 'decltype' and parens.
1405ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
1406ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                         DecltypeTypeLoc,
1407ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                                                         DecltypeType> {
140851bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
140951bd803fbdade51d674598ed45da3d54190a656cJohn McCall
141034b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
141134b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                        AutoTypeLoc,
141234b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                        AutoType> {
141334b41d939a1328f484511c6002ba2456db879a29Richard Smith};
141434b41d939a1328f484511c6002ba2456db879a29Richard Smith
1415e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarastruct ElaboratedLocInfo {
1416e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation KeywordLoc;
14179e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor
14189e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  /// \brief Opaque data pointer used to reconstruct a nested-name-specifier
14199e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  /// from
14209e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  void *QualifierData;
1421e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara};
1422e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1423e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnaraclass ElaboratedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1424e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                 ElaboratedTypeLoc,
1425e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                 ElaboratedType,
1426e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                 ElaboratedLocInfo> {
1427e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarapublic:
1428e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation getKeywordLoc() const {
1429e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return this->getLocalData()->KeywordLoc;
1430e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1431e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void setKeywordLoc(SourceLocation Loc) {
1432e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    this->getLocalData()->KeywordLoc = Loc;
1433e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1434e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
14359e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
14369e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
14379e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                  getLocalData()->QualifierData);
1438e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
14399e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor
14409e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
14419e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    assert(QualifierLoc.getNestedNameSpecifier()
14429e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                            == getTypePtr()->getQualifier() &&
14439e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor           "Inconsistent nested-name-specifier pointer");
14449e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1445e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1446e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1447bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1448e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    if (getKeywordLoc().isValid())
14499e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      if (getQualifierLoc())
14509e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor        return SourceRange(getKeywordLoc(), getQualifierLoc().getEndLoc());
1451e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      else
1452e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara        return SourceRange(getKeywordLoc());
1453e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    else
14549e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      return getQualifierLoc().getSourceRange();
1455e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1456e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
14579e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc);
1458e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1459e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  TypeLoc getNamedTypeLoc() const {
1460e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return getInnerTypeLoc();
1461e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1462e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1463e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType getInnerType() const {
1464e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return getTypePtr()->getNamedType();
1465e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1466e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1467e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void copy(ElaboratedTypeLoc Loc) {
1468e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    unsigned size = getFullDataSize();
1469e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    assert(size == Loc.getFullDataSize());
1470e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    memcpy(Data, Loc.Data, size);
1471e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
147251bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
147351bd803fbdade51d674598ed45da3d54190a656cJohn McCall
147433500955d731c73717af52088b7fc0e7a85681e7John McCall// This is exactly the structure of an ElaboratedTypeLoc whose inner
147533500955d731c73717af52088b7fc0e7a85681e7John McCall// type is some sort of TypeDeclTypeLoc.
147633500955d731c73717af52088b7fc0e7a85681e7John McCallstruct DependentNameLocInfo : ElaboratedLocInfo {
1477e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation NameLoc;
14782494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor
14792494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  /// \brief Data associated with the nested-name-specifier location.
14802494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  void *QualifierData;
1481e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara};
1482e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1483e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnaraclass DependentNameTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
1484e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                    DependentNameTypeLoc,
1485e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                    DependentNameType,
1486e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                                    DependentNameLocInfo> {
1487e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnarapublic:
1488e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation getKeywordLoc() const {
1489e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return this->getLocalData()->KeywordLoc;
1490e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1491e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void setKeywordLoc(SourceLocation Loc) {
1492e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    this->getLocalData()->KeywordLoc = Loc;
1493e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1494e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
14952494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
14962494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
14972494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                  getLocalData()->QualifierData);
1498e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
14992494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor
15002494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
15012494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    assert(QualifierLoc.getNestedNameSpecifier()
15022494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            == getTypePtr()->getQualifier() &&
15032494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor           "Inconsistent nested-name-specifier pointer");
15042494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
1505e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
15062494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor
1507e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  SourceLocation getNameLoc() const {
1508e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    return this->getLocalData()->NameLoc;
1509e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1510e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void setNameLoc(SourceLocation Loc) {
1511e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    this->getLocalData()->NameLoc = Loc;
1512e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1513e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1514bd054dba8a3023821f2a0951b0fae05e3522a7c9Abramo Bagnara  SourceRange getLocalSourceRange() const {
1515e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    if (getKeywordLoc().isValid())
1516e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      return SourceRange(getKeywordLoc(), getNameLoc());
1517e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    else
15182494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor      return SourceRange(getQualifierLoc().getBeginLoc(), getNameLoc());
1519e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1520e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
1521e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  void copy(DependentNameTypeLoc Loc) {
1522e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    unsigned size = getFullDataSize();
1523e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    assert(size == Loc.getFullDataSize());
1524e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    memcpy(Data, Loc.Data, size);
1525e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
1526e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
15272494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc);
152851bd803fbdade51d674598ed45da3d54190a656cJohn McCall};
152951bd803fbdade51d674598ed45da3d54190a656cJohn McCall
153094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregorstruct DependentTemplateSpecializationLocInfo : DependentNameLocInfo {
15319e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  SourceLocation KeywordLoc;
153233500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation LAngleLoc;
153333500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation RAngleLoc;
153433500955d731c73717af52088b7fc0e7a85681e7John McCall  // followed by a TemplateArgumentLocInfo[]
153533500955d731c73717af52088b7fc0e7a85681e7John McCall};
153633500955d731c73717af52088b7fc0e7a85681e7John McCall
153733500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationTypeLoc :
153833500955d731c73717af52088b7fc0e7a85681e7John McCall    public ConcreteTypeLoc<UnqualTypeLoc,
153933500955d731c73717af52088b7fc0e7a85681e7John McCall                           DependentTemplateSpecializationTypeLoc,
154033500955d731c73717af52088b7fc0e7a85681e7John McCall                           DependentTemplateSpecializationType,
154133500955d731c73717af52088b7fc0e7a85681e7John McCall                           DependentTemplateSpecializationLocInfo> {
154233500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
154333500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation getKeywordLoc() const {
154433500955d731c73717af52088b7fc0e7a85681e7John McCall    return this->getLocalData()->KeywordLoc;
154533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
154633500955d731c73717af52088b7fc0e7a85681e7John McCall  void setKeywordLoc(SourceLocation Loc) {
154733500955d731c73717af52088b7fc0e7a85681e7John McCall    this->getLocalData()->KeywordLoc = Loc;
154833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
154933500955d731c73717af52088b7fc0e7a85681e7John McCall
155094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
155194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (!getLocalData()->QualifierData)
155294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return NestedNameSpecifierLoc();
155394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
155494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
155594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                  getLocalData()->QualifierData);
155633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
155794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
155894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
155994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (!QualifierLoc) {
156094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      // Even if we have a nested-name-specifier in the dependent
156194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      // template specialization type, we won't record the nested-name-specifier
156294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      // location information when this type-source location information is
156394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      // part of a nested-name-specifier.
156494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      getLocalData()->QualifierData = 0;
156594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return;
156694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    }
156794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
156894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    assert(QualifierLoc.getNestedNameSpecifier()
156994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                        == getTypePtr()->getQualifier() &&
157094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor           "Inconsistent nested-name-specifier pointer");
157194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
157233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
157333500955d731c73717af52088b7fc0e7a85681e7John McCall
157433500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation getNameLoc() const {
157533500955d731c73717af52088b7fc0e7a85681e7John McCall    return this->getLocalData()->NameLoc;
157633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
157733500955d731c73717af52088b7fc0e7a85681e7John McCall  void setNameLoc(SourceLocation Loc) {
157833500955d731c73717af52088b7fc0e7a85681e7John McCall    this->getLocalData()->NameLoc = Loc;
157933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
158033500955d731c73717af52088b7fc0e7a85681e7John McCall
158133500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation getLAngleLoc() const {
158233500955d731c73717af52088b7fc0e7a85681e7John McCall    return this->getLocalData()->LAngleLoc;
158333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
158433500955d731c73717af52088b7fc0e7a85681e7John McCall  void setLAngleLoc(SourceLocation Loc) {
158533500955d731c73717af52088b7fc0e7a85681e7John McCall    this->getLocalData()->LAngleLoc = Loc;
158633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
158733500955d731c73717af52088b7fc0e7a85681e7John McCall
158833500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceLocation getRAngleLoc() const {
158933500955d731c73717af52088b7fc0e7a85681e7John McCall    return this->getLocalData()->RAngleLoc;
159033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
159133500955d731c73717af52088b7fc0e7a85681e7John McCall  void setRAngleLoc(SourceLocation Loc) {
159233500955d731c73717af52088b7fc0e7a85681e7John McCall    this->getLocalData()->RAngleLoc = Loc;
159333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
159433500955d731c73717af52088b7fc0e7a85681e7John McCall
159533500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const {
159633500955d731c73717af52088b7fc0e7a85681e7John McCall    return getTypePtr()->getNumArgs();
159733500955d731c73717af52088b7fc0e7a85681e7John McCall  }
159833500955d731c73717af52088b7fc0e7a85681e7John McCall
159933500955d731c73717af52088b7fc0e7a85681e7John McCall  void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
160033500955d731c73717af52088b7fc0e7a85681e7John McCall    getArgInfos()[i] = AI;
160133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
160233500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
160333500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgInfos()[i];
160433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
160533500955d731c73717af52088b7fc0e7a85681e7John McCall
160633500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentLoc getArgLoc(unsigned i) const {
160733500955d731c73717af52088b7fc0e7a85681e7John McCall    return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
160833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
160933500955d731c73717af52088b7fc0e7a85681e7John McCall
161033500955d731c73717af52088b7fc0e7a85681e7John McCall  SourceRange getLocalSourceRange() const {
161133500955d731c73717af52088b7fc0e7a85681e7John McCall    if (getKeywordLoc().isValid())
161233500955d731c73717af52088b7fc0e7a85681e7John McCall      return SourceRange(getKeywordLoc(), getRAngleLoc());
161394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    else if (getQualifierLoc())
161494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return SourceRange(getQualifierLoc().getBeginLoc(), getRAngleLoc());
16159e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    else
16169e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      return SourceRange(getNameLoc(), getRAngleLoc());
161733500955d731c73717af52088b7fc0e7a85681e7John McCall  }
161833500955d731c73717af52088b7fc0e7a85681e7John McCall
161933500955d731c73717af52088b7fc0e7a85681e7John McCall  void copy(DependentTemplateSpecializationTypeLoc Loc) {
162033500955d731c73717af52088b7fc0e7a85681e7John McCall    unsigned size = getFullDataSize();
162133500955d731c73717af52088b7fc0e7a85681e7John McCall    assert(size == Loc.getFullDataSize());
162233500955d731c73717af52088b7fc0e7a85681e7John McCall    memcpy(Data, Loc.Data, size);
162333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
162433500955d731c73717af52088b7fc0e7a85681e7John McCall
162594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc);
162633500955d731c73717af52088b7fc0e7a85681e7John McCall
162733500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getExtraLocalDataSize() const {
162833500955d731c73717af52088b7fc0e7a85681e7John McCall    return getNumArgs() * sizeof(TemplateArgumentLocInfo);
162933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
163033500955d731c73717af52088b7fc0e7a85681e7John McCall
163133500955d731c73717af52088b7fc0e7a85681e7John McCallprivate:
163233500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentLocInfo *getArgInfos() const {
163333500955d731c73717af52088b7fc0e7a85681e7John McCall    return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
163433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
163533500955d731c73717af52088b7fc0e7a85681e7John McCall};
163633500955d731c73717af52088b7fc0e7a85681e7John McCall
16377536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
16387536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorstruct PackExpansionTypeLocInfo {
16397536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  SourceLocation EllipsisLoc;
16407536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
16417536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
16427536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionTypeLoc
16437536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  : public ConcreteTypeLoc<UnqualTypeLoc, PackExpansionTypeLoc,
16447536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor                           PackExpansionType, PackExpansionTypeLocInfo> {
16457536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic:
16467536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  SourceLocation getEllipsisLoc() const {
16477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return this->getLocalData()->EllipsisLoc;
16487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
16497536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
16507536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  void setEllipsisLoc(SourceLocation Loc) {
16517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    this->getLocalData()->EllipsisLoc = Loc;
16527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
16537536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
16547536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  SourceRange getLocalSourceRange() const {
16557536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return SourceRange(getEllipsisLoc(), getEllipsisLoc());
16567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
16577536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
1658c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
16597536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    setEllipsisLoc(Loc);
16607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
16617536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
16627536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  TypeLoc getPatternLoc() const {
16637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return getInnerTypeLoc();
16647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
16657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
16667536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType getInnerType() const {
16677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return this->getTypePtr()->getPattern();
16687536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
16697536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
16707536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
1671b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis}
1672b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis
1673b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#endif
1674