TreeTransform.h revision c8fc90a854b4ccba21c85884676a80334159dd94
157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
3577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//                     The LLVM Compiler Infrastructure
4577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
5577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file is distributed under the University of Illinois Open Source
6577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// License. See LICENSE.TXT for details.
757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===//
8577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
9577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//  This file implements a semantic tree transformation that takes a given
10577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//  AST and rebuilds it, possibly transforming some nodes in the process.
11577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
1257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===//
1357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
172d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h"
18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h"
198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor#include "clang/Sema/ParsedTemplate.h"
20dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h"
21781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h"
22c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h"
237cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h"
243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith#include "clang/AST/DeclTemplate.h"
25657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h"
26b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h"
27b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h"
2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h"
2943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h"
3043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h"
3119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h"
3219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h"
33b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h"
34a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h"
357e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h"
36577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm>
37577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
38577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang {
39781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema;
401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one
42577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another.
43577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide
461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template
47577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the
48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the
49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar
50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and
51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters.
52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow
541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can
55577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an
56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The
57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual.
58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which
60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node
61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions,
62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation
64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g.,
65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes
66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create
67577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node.
68577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The
70670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(),
719151c11836f5fbb36cedfe4d22df7e00e77a1d42Douglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
72577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations.
74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the
76577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
7743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
78577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template
80577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX
81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change.
82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps.
85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one
871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation
88577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the
90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking
91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()).
92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
93577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform {
94d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief Private RAII object that helps us forget and then re-remember
95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// the template argument corresponding to a partially-substituted parameter
96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack.
97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  class ForgetPartiallySubstitutedPackRAII {
98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    Derived &Self;
99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    TemplateArgument Old;
100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
101d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  public:
102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Old = Self.ForgetPartiallySubstitutedPack();
104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ~ForgetPartiallySubstitutedPackRAII() {
107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Self.RememberPartiallySubstitutedPack(Old);
108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  };
110d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected:
112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &SemaRef;
1138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
115577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Initializes a new tree transformer.
116b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Derived &getDerived() { return static_cast<Derived&>(*this); }
120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Derived &getDerived() const {
1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return static_cast<const Derived&>(*this);
124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
12660d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline ExprResult Owned(Expr *E) { return E; }
12760d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline StmtResult Owned(Stmt *S) { return S; }
1289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall
129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the semantic analysis object used for
130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// this tree transform.
131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &getSema() const { return SemaRef; }
1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Whether the transformation should always rebuild AST nodes, even
134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// if none of the children have changed.
135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this function to specify when the transformation
137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// should rebuild all AST nodes.
138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlwaysRebuild() { return false; }
1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the location of the entity being transformed, if that
141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, returns no source-location information. Subclasses can
144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// provide an alternative implementation that provides better location
145577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information.
146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  SourceLocation getBaseLocation() { return SourceLocation(); }
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the name of the entity being transformed, if that
149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, returns an empty name. Subclasses can provide an alternative
152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// implementation with a more precise name.
153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  DeclarationName getBaseEntity() { return DeclarationName(); }
154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Sets the "base" location and entity when that
156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// information is known based on another transformation.
157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, the source location and entity are ignored. Subclasses can
159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// override this function to provide a customized implementation.
160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  void setBase(SourceLocation Loc, DeclarationName Entity) { }
1611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief RAII object that temporarily sets the base location and entity
163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// used for reporting diagnostics in types.
164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  class TemporaryBase {
165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TreeTransform &Self;
166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SourceLocation OldLocation;
167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclarationName OldEntity;
1681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  public:
170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TemporaryBase(TreeTransform &Self, SourceLocation Location,
1711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  DeclarationName Entity) : Self(Self) {
172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldLocation = Self.getDerived().getBaseLocation();
173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldEntity = Self.getDerived().getBaseEntity();
174ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor
175ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor      if (Location.isValid())
176ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor        Self.getDerived().setBase(Location, Entity);
177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ~TemporaryBase() {
180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Self.getDerived().setBase(OldLocation, OldEntity);
181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  };
1831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determine whether the given type \p T has already been
185577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// transformed.
186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
187577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses can provide an alternative implementation of this routine
1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// to short-circuit evaluation when it is known that a given type will
189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// not change. For example, template instantiation need not traverse
190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// non-dependent types.
191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlreadyTransformed(QualType T) {
192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T.isNull();
193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
194577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
1956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether the given call argument should be dropped, e.g.,
1966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// because it is a default argument.
1976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
1986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Subclasses can provide an alternative implementation of this routine to
1996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// determine which kinds of call arguments get dropped. By default,
2006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// CXXDefaultArgument nodes are dropped (prior to transformation).
2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool DropCallArgument(Expr *E) {
2026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return E->isDefaultArgument();
2036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
204c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Determine whether we should expand a pack expansion with the
2068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// given set of parameter packs into separate arguments by repeatedly
2078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// transforming the pattern.
2088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
209b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  /// By default, the transformer never tries to expand pack expansions.
2108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// Subclasses can override this routine to provide different behavior.
2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param EllipsisLoc The location of the ellipsis that identifies the
2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pack expansion.
2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param PatternRange The source range that covers the entire pattern of
2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// the pack expansion.
2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param Unexpanded The set of unexpanded parameter packs within the
2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pattern.
2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumUnexpanded The number of unexpanded parameter packs in
2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \p Unexpanded.
2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param ShouldExpand Will be set to \c true if the transformer should
2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// expand the corresponding pack expansions into separate arguments. When
2268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// set, \c NumExpansions must also be set.
2278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
228d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \param RetainExpansion Whether the caller should add an unexpanded
229d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack expansion after all of the expanded arguments. This is used
230d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when extending explicitly-specified template argument packs per
231d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// C++0x [temp.arg.explicit]p9.
232d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
2338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumExpansions The number of separate arguments that will be in
234cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// the expanded form of the corresponding pack expansion. This is both an
235cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// input and an output parameter, which can be set by the caller if the
236cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// number of expansions is known a priori (e.g., due to a prior substitution)
237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// and will be set by the callee when the number of expansions is known.
238cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// The callee must set this value when \c ShouldExpand is \c true; it may
239cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// set this value in other cases.
2408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \returns true if an error occurred (e.g., because the parameter packs
2428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// are to be instantiated with arguments of different lengths), false
2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
2448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// must be set.
2458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
2468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               SourceRange PatternRange,
2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               const UnexpandedParameterPack *Unexpanded,
2488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               unsigned NumUnexpanded,
2498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               bool &ShouldExpand,
250d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                               bool &RetainExpansion,
251cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                               llvm::Optional<unsigned> &NumExpansions) {
2528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    ShouldExpand = false;
2538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return false;
2548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
2558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
256d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Forget" about the partially-substituted pack template argument,
257d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when performing an instantiation that must preserve the parameter pack
258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  TemplateArgument ForgetPartiallySubstitutedPack() {
262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    return TemplateArgument();
263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  }
264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Remember" the partially-substituted pack template argument
266d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// after performing an instantiation that must preserve the parameter pack
267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
27212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// \brief Note to the derived class when a function parameter pack is
27312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// being expanded.
27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
27512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor
276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transforms the given type into another type.
277577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by creating a
279a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// TypeSourceInfo for it and delegating to the appropriate
280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// function.  This is expensive, but we don't mind, because
281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// this method is deprecated anyway;  all users should be
282a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// switched to storing TypeSourceInfos.
283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
284577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \returns the transformed type.
28543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(QualType T);
2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transforms the given type-with-location into a new
288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type-with-location.
289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ///
290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by delegating to the
291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// appropriate TransformXXXType to build a new type.  Subclasses
292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// may override this function (to take over all type
293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// transformations) or some set of the TransformXXXType functions
294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// to alter the transformation.
29543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transform the given type-with-location into a new
298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type, collecting location information in the given builder
299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// as necessary.
300577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
30143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
303657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given statement.
304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this routine transforms a statement by delegating to the
30643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// appropriate TransformXXXStmt function to transform a specific kind of
30743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// statement or the TransformExpr() function to transform an expression.
30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to transform statements using some
30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// other mechanism.
31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
31143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \returns the transformed statement.
31260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformStmt(Stmt *S);
3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
314657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given expression.
315657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  ///
316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine transforms an expression by delegating to the
317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// appropriate TransformXXXExpr function to build a new expression.
318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this function to transform expressions using some
319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// other mechanism.
320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \returns the transformed expression.
32260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformExpr(Expr *E);
3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Transform the given list of expressions.
325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// This routine transforms a list of expressions by invoking
327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \c TransformExpr() for each subexpression. However, it also provides
328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// support for variadic templates by expanding any pack expansions (if the
329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// derived class permits such expansion) along the way. When pack expansions
330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// are present, the number of outputs may not equal the number of inputs.
331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Inputs The set of expressions to be transformed.
333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param NumInputs The number of expressions in \c Inputs.
335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param IsCall If \c true, then this transform is being performed on
337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// function-call arguments, and any arguments that should be dropped, will
338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// be.
339aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Outputs The transformed input expressions will be added to this
341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// vector.
342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// due to transformation.
345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \returns true if an error occurred, false otherwise.
347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
348aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                      llvm::SmallVectorImpl<Expr *> &Outputs,
349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                      bool *ArgChanged = 0);
350aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given declaration, which is referenced from a type
352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// or expression.
353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
354dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, acts as the identity function on declarations. Subclasses
355dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// may override this function to provide alternate behavior.
3567c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
35743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
35843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Transform the definition of the given declaration.
35943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, invokes TransformDecl() to transform the declaration.
36143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().TransformDecl(Loc, D);
3647c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  }
3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3666cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// \brief Transform the given declaration, which was the first part of a
3676cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// nested-name-specifier in a member access expression.
3686cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
369c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// This specific declaration transformation only applies to the first
3706cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// identifier in a nested-name-specifier of a member access expression, e.g.,
3716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// the \c T in \c x->T::member
3726cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
3736cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// By default, invokes TransformDecl() to transform the declaration.
3746cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// Subclasses may override this function to provide alternate behavior.
375c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
3776cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  }
378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
379c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// \brief Transform the given nested-name-specifier with source-location
380c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// information.
381c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  ///
382c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// By default, transforms all of the types and declarations within the
383c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// nested-name-specifier. Subclasses may override this function to provide
384c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// alternate behavior.
385c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                    NestedNameSpecifierLoc NNS,
387c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                          QualType ObjectType = QualType(),
388c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                          NamedDecl *FirstQualifierInScope = 0);
389c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
39081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// \brief Transform the given declaration name.
39181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  ///
39281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// By default, transforms the types of conversion function, constructor,
39381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// and destructor names and then (if needed) rebuilds the declaration name.
39481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// Identifiers and selectors are returned unmodified. Sublcasses may
39581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// override this function to provide alternate behavior.
3962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo
39743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template name.
4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
401fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param SS The nested-name-specifier that qualifies the template
402fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// name. This nested-name-specifier must already have been transformed.
403fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
404fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param Name The template name to transform.
405fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
406fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param NameLoc The source location of the template name.
407fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
408fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param ObjectType If we're translating a template name within a member
409fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// access expression, this is the type of the object whose member template
410fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// is being referenced.
411fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
412fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// also refers to a name within the current (lexical) scope, this is the
414fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// declaration it refers to.
415fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
416fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// By default, transforms the template name by transforming the declarations
417fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// and nested-name-specifiers that occur within the template name.
418fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
419fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName TransformTemplateName(CXXScopeSpec &SS,
420fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     TemplateName Name,
421fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     SourceLocation NameLoc,
422fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     QualType ObjectType = QualType(),
423fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     NamedDecl *FirstQualifierInScope = 0);
424fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
425577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template argument.
426577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this operation transforms the type, expression, or
4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// declaration stored within the template argument and constructs a
429670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// new template argument from the transformed result. Subclasses may
430670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// override this function to provide alternate behavior.
431833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  ///
432833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// Returns true if there was an error.
433833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &Output);
435833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
436fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \brief Transform the given set of template arguments.
437fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
438fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// By default, this operation transforms all of the template arguments
439fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
440fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// the transformed arguments to the output list.
441fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
4427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// Note that this overload of \c TransformTemplateArguments() is merely
4437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// a convenience function. Subclasses that wish to override this behavior
4447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// should override the iterator-based member template version.
4457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
446fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Inputs The set of template arguments to be transformed.
447fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
448fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param NumInputs The number of template arguments in \p Inputs.
449fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
450fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Outputs The set of transformed template arguments output by this
451fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// routine.
452fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
453fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// Returns true if an error occurred.
454fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                  unsigned NumInputs,
4567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs) {
4577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
4587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
4597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
4607f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \brief Transform the given set of template arguments.
4617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// By default, this operation transforms all of the template arguments
4637f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
4647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// the transformed arguments to the output list.
4657f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param First An iterator to the first template argument.
4677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
4687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param Last An iterator one step past the last template argument.
4697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4707f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \param Outputs The set of transformed template arguments output by this
4717f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// routine.
4727f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4737f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// Returns true if an error occurred.
4747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename InputIterator>
4757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  bool TransformTemplateArguments(InputIterator First,
4767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  InputIterator Last,
4777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs);
4787f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
479833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &ArgLoc);
482833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
483a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// \brief Fakes up a TypeSourceInfo for a type.
484a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return SemaRef.Context.getTrivialTypeSourceInfo(T,
486833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                       getDerived().getBaseLocation());
487833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT)                                   \
49143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
493577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
49428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult
49528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  TransformSEHHandler(Stmt *Handler);
49628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
49743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
49843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
49943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateSpecializationTypeLoc TL,
50043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateName Template);
50143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
50243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
50343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
50443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentTemplateSpecializationTypeLoc TL,
505087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                               TemplateName Template,
506087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                               CXXScopeSpec &SS);
507a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
508a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  QualType
509a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
51094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                               DependentTemplateSpecializationTypeLoc TL,
51194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                         NestedNameSpecifierLoc QualifierLoc);
51294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
51321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms the parameters of a function type into the
51421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// given vectors.
51521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
51621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// The result vectors should be kept in sync; null entries in the
51721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// variables vector are acceptable.
51821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
51921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// Return true on error.
520a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  bool TransformFunctionTypeParams(SourceLocation Loc,
521a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   ParmVarDecl **Params, unsigned NumParams,
522a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   const QualType *ParamTypes,
52321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                                   llvm::SmallVectorImpl<QualType> &PTypes,
524a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
52521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
52621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms a single function-type parameter.  Return null
52721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// on error.
528fb44de956f27875def889482b5393475060392afJohn McCall  ///
529fb44de956f27875def889482b5393475060392afJohn McCall  /// \param indexAdjustment - A number to add to the parameter's
530fb44de956f27875def889482b5393475060392afJohn McCall  ///   scope index;  can be negative
5316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
532fb44de956f27875def889482b5393475060392afJohn McCall                                          int indexAdjustment,
5336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                        llvm::Optional<unsigned> NumExpansions);
53421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
53543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
536833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
53760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
53860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                        \
54160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Transform##Node(Node *S);
542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                        \
54360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Transform##Node(Node *E);
5447381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
5454bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new pointer type given its pointee type.
548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the pointer type.
550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
55185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new block pointer type given its pointee type.
554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis when building the block pointer
556577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
55785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
558577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
55985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \brief Build a new reference type given the type it references.
560577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
56185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// By default, performs semantic analysis when building the
56285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// reference type. Subclasses may override this routine to provide
56385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// different behavior.
564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
56585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \param LValue whether the type was written with an lvalue sigil
56685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// or an rvalue sigil.
56785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildReferenceType(QualType ReferentType,
56885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                bool LValue,
56985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                SourceLocation Sigil);
5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new member pointer type given the pointee type and the
572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// class type it refers into.
573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the member pointer
575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
57685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
57785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceLocation Sigil);
5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new array type given the element type, size
580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, size of the array (if known), size expression, and index type
581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// qualifiers.
582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Also by default, all of the other Rebuild*Array
586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildArrayType(QualType ElementType,
587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            ArrayType::ArraySizeModifier SizeMod,
588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            const llvm::APInt *Size,
589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            Expr *SizeExpr,
590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            unsigned IndexTypeQuals,
591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            SourceRange BracketsRange);
5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new constant array type given the element type, size
594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, (known) size of the array, and index type qualifiers.
595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
596577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildConstantArrayType(QualType ElementType,
599577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    const llvm::APInt &Size,
60185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    unsigned IndexTypeQuals,
60285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceRange BracketsRange);
603577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new incomplete array type given the element type, size
605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, and index type qualifiers.
606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildIncompleteArrayType(QualType ElementType,
610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                      ArrayType::ArraySizeModifier SizeMod,
61185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      unsigned IndexTypeQuals,
61285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      SourceRange BracketsRange);
613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new variable-length array type given the element type,
615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildVariableArrayType(QualType ElementType,
620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
6219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SizeExpr,
622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned IndexTypeQuals,
623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    SourceRange BracketsRange);
624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new dependent-sized array type given the element type,
626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedArrayType(QualType ElementType,
631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
6329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *SizeExpr,
633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          unsigned IndexTypeQuals,
634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          SourceRange BracketsRange);
635577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
636577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new vector type given the element type and
637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
64182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
642e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                             VectorType::VectorKind VecKind);
6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new extended vector type given the element type and
645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
646577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                SourceLocation AttributeLoc);
6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new potentially dependently-sized extended vector type
653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// given the element type and number of elements.
654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
6589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *SizeExpr,
659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                              SourceLocation AttributeLoc);
6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
661577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new function type.
662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the function type.
664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildFunctionProtoType(QualType T,
6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    QualType *ParamTypes,
667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned NumParamTypes,
668fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    bool Variadic, unsigned Quals,
669c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                    RefQualifierKind RefQualifier,
670fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    const FunctionType::ExtInfo &Info);
6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Build a new unprototyped function type.
673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType RebuildFunctionNoProtoType(QualType ResultType);
674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
675ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// \brief Rebuild an unresolved typename type, given the decl that
676ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// the UnresolvedUsingTypenameDecl was transformed to.
677ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType RebuildUnresolvedUsingType(Decl *D);
678ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typedef type.
680162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Typedef);
682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new class/struct/union type.
685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildRecordType(RecordDecl *Record) {
686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Record);
687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new Enum type.
690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildEnumType(EnumDecl *Enum) {
691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Enum);
692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
6937da2431c23ef1ee8acb114e39692246e1801afc2John McCall
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(expr) type.
695577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typeof type.
697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(type) type.
701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, builds a new TypeOfType with the given underlying type.
703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypeOfType(QualType Underlying);
704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
705ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// \brief Build a new unary transform type.
706ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType RebuildUnaryTransformType(QualType BaseType,
707ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                     UnaryTransformType::UTTKind UKind,
708ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                     SourceLocation Loc);
709ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++0x decltype type.
711577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
712577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the decltype type.
713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
7142a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71634b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Build a new C++0x auto type.
71734b41d939a1328f484511c6002ba2456db879a29Richard Smith  ///
71834b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// By default, builds a new AutoType with the given deduced type.
71934b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType RebuildAutoType(QualType Deduced) {
72034b41d939a1328f484511c6002ba2456db879a29Richard Smith    return SemaRef.Context.getAutoType(Deduced);
72134b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
72234b41d939a1328f484511c6002ba2456db879a29Richard Smith
723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new template specialization type.
724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the template
726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// specialization type. Subclasses may override this routine to provide
727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTemplateSpecializationType(TemplateName Template,
729833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateLoc,
73067714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                             TemplateArgumentListInfo &Args);
7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
732075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// \brief Build a new parenthesized type.
733075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ///
734075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// By default, builds a new ParenType type from the inner type.
735075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
736075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType RebuildParenType(QualType InnerType) {
737075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return SemaRef.Context.getParenType(InnerType);
738075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
739075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new qualified name type.
741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
742465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// By default, builds a new ElaboratedType type from the keyword,
743465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// the nested-name-specifier and the named type.
744465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
74521e413fe6305a198564d436ac515497716c47844John McCall  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
74621e413fe6305a198564d436ac515497716c47844John McCall                                 ElaboratedTypeKeyword Keyword,
7479e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                 NestedNameSpecifierLoc QualifierLoc,
7489e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                 QualType Named) {
7499e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    return SemaRef.Context.getElaboratedType(Keyword,
7509e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                         QualifierLoc.getNestedNameSpecifier(),
7519e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                             Named);
7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
753577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
754577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to a template-id.
755577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
756e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// By default, builds a new DependentNameType type from the
757e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// nested-name-specifier and the given type. Subclasses may override
758e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// this routine to provide different behavior.
75933500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType RebuildDependentTemplateSpecializationType(
76094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          ElaboratedTypeKeyword Keyword,
76194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
76294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          const IdentifierInfo *Name,
76394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          SourceLocation NameLoc,
76467714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                          TemplateArgumentListInfo &Args) {
76594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Rebuild the template name.
76694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // TODO: avoid TemplateName abstraction
767fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    CXXScopeSpec SS;
768fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    SS.Adopt(QualifierLoc);
76994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    TemplateName InstName
770fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
77194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
77294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (InstName.isNull())
77394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return QualType();
77494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
77594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // If it's still dependent, make a dependent specialization.
77694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (InstName.getAsDependentTemplateName())
77794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
77894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          QualifierLoc.getNestedNameSpecifier(),
77994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                                    Name,
78094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                                    Args);
78194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
78294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Otherwise, make an elaborated type wrapping a non-dependent
78394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // specialization.
78494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualType T =
78594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
78694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (T.isNull()) return QualType();
78794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
78894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
78994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return T;
79094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
79194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return SemaRef.Context.getElaboratedType(Keyword,
79294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                       QualifierLoc.getNestedNameSpecifier(),
79394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                             T);
79494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  }
79594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
796577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to an identifier.
797577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
798577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typename type
799e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// (or elaborated type). Subclasses may override this routine to provide
800577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
801e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
802e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation KeywordLoc,
8032494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                    NestedNameSpecifierLoc QualifierLoc,
8042494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                    const IdentifierInfo *Id,
805e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation IdLoc) {
8064033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    CXXScopeSpec SS;
8072494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    SS.Adopt(QualifierLoc);
808e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
8092494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
8104033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      // If the name is still dependent, just build a new dependent name type.
8114033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      if (!SemaRef.computeDeclContext(SS))
8122494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor        return SemaRef.Context.getDependentNameType(Keyword,
8132494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                          QualifierLoc.getNestedNameSpecifier(),
8142494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                                    Id);
8154033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
817465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (Keyword == ETK_None || Keyword == ETK_Typename)
8182494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor      return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
819e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor                                       *Id, IdLoc);
820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
823e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    // We had a dependent elaborated-type-specifier that has been transformed
8244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // into a non-dependent elaborated-type-specifier. Find the tag we're
8254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // referring to.
826e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
8274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    DeclContext *DC = SemaRef.computeDeclContext(SS, false);
8284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!DC)
8294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8315613876991c80a684595fe8de1f039296a0657ffJohn McCall    if (SemaRef.RequireCompleteDeclContext(SS, DC))
8325613876991c80a684595fe8de1f039296a0657ffJohn McCall      return QualType();
8335613876991c80a684595fe8de1f039296a0657ffJohn McCall
8344033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    TagDecl *Tag = 0;
8354033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SemaRef.LookupQualifiedName(Result, DC);
8364033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    switch (Result.getResultKind()) {
8374033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFound:
8384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFoundInCurrentInstantiation:
8394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
840c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Found:
8424033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        Tag = Result.getAsSingle<TagDecl>();
8434033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundOverloaded:
8464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundUnresolvedValue:
8474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        llvm_unreachable("Tag lookup cannot find non-tags");
8484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
849c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8504033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Ambiguous:
8514033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        // Let the LookupResult structure handle ambiguities.
8524033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8554033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!Tag) {
856446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // Check where the name exists but isn't a tag type and use that to emit
857446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // better diagnostics.
858446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      SemaRef.LookupQualifiedName(Result, DC);
860446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      switch (Result.getResultKind()) {
861446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::Found:
862446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundOverloaded:
863446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundUnresolvedValue: {
8643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith          NamedDecl *SomeDecl = Result.getRepresentativeDecl();
865446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          unsigned Kind = 0;
866446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
867162e1c1b487352434552147967c3dd296ebee2f7Richard Smith          else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868162e1c1b487352434552147967c3dd296ebee2f7Richard Smith          else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
869446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
8723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        }
873446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        default:
874446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          // FIXME: Would be nice to highlight just the source range.
875446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky            << Kind << Id << DC;
877446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
878446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      }
8794033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
881465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
882bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu    if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu                                              IdLoc, *Id)) {
884e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
8854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
8864033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // Build the elaborated-type-specifier type.
8904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    QualType T = SemaRef.Context.getTypeDeclType(Tag);
8912494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    return SemaRef.Context.getElaboratedType(Keyword,
8922494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                         QualifierLoc.getNestedNameSpecifier(),
8932494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                             T);
894dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8962fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// \brief Build a new pack expansion type.
8972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  ///
8982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// By default, builds a new PackExpansionType type from the given pattern.
8992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
9002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType RebuildPackExpansionType(QualType Pattern,
9012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                    SourceRange PatternRange,
902cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    SourceLocation EllipsisLoc,
903cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    llvm::Optional<unsigned> NumExpansions) {
904cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                        NumExpansions);
9062fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
9072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
908d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier, a flag
909d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// indicating whether the "template" keyword was provided, and the template
910d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// that the template name refers to.
911d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
912d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, builds the new template name directly. Subclasses may override
913d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// this routine to provide different behavior.
914fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
915d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   bool TemplateKW,
916d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   TemplateDecl *Template);
917d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
918d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier and the
919d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// name that is referred to as a template.
920d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
921d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
922d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
923d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// template name. Subclasses may override this routine to provide different
924d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// behavior.
925fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
926fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   const IdentifierInfo &Name,
927fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   SourceLocation NameLoc,
92843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   QualType ObjectType,
92943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   NamedDecl *FirstQualifierInScope);
9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
931ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// \brief Build a new template name given a nested name specifier and the
932ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// overloaded operator name that is referred to as a template.
933ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  ///
934ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// By default, performs semantic analysis to determine whether the name can
935ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
936ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// template name. Subclasses may override this routine to provide different
937ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// behavior.
938fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
939ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   OverloadedOperatorKind Operator,
940fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   SourceLocation NameLoc,
941ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   QualType ObjectType);
9421aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
9431aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// \brief Build a new template name given a template template parameter pack
9441aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// and the
9451aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  ///
9461aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
9471aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
9481aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// template name. Subclasses may override this routine to provide different
9491aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// behavior.
9501aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
9511aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                   const TemplateArgument &ArgPack) {
9521aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
9531aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  }
9541aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
95543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new compound statement.
95643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
95743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
95843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
95960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
96043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       MultiStmtArg Statements,
96143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       SourceLocation RBraceLoc,
96243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       bool IsStmtExpr) {
9639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
96443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       IsStmtExpr);
96543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
96643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
96743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new case statement.
96843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
96943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
97043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
97160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
9729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *LHS,
97343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EllipsisLoc,
9749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *RHS,
97543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation ColonLoc) {
9769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
97743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   ColonLoc);
97843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to a new case statement.
98143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
98243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
98343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
98460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
9859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().ActOnCaseStmtBody(S, Body);
9869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return S;
98743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new default statement.
99043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
99143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
99243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
99360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      SourceLocation ColonLoc,
9959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      Stmt *SubStmt) {
9969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      /*CurScope=*/0);
99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new label statement.
100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
100243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
100343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
100457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
100557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                              SourceLocation ColonLoc, Stmt *SubStmt) {
100657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new "if" statement.
101043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
101143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
101243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
101360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
101457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                           VarDecl *CondVar, Stmt *Then,
101557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                           SourceLocation ElseLoc, Stmt *Else) {
101644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis    return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
101743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Start building a new switch statement.
102043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
102143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
102243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
102360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
102457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                    Expr *Cond, VarDecl *CondVar) {
10259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1026d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                            CondVar);
102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to the switch statement.
103043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
103143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
103360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
103457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                   Stmt *Switch, Stmt *Body) {
10359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
103643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
103843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new while statement.
103943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
104043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
104143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
104257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
104357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                              VarDecl *CondVar, Stmt *Body) {
10449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
104543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
104743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new do-while statement.
104843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
104943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
105043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
105160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1052ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                           SourceLocation WhileLoc, SourceLocation LParenLoc,
1053ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                           Expr *Cond, SourceLocation RParenLoc) {
10549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
10559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Cond, RParenLoc);
105643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
105743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
105843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new for statement.
105943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
106043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
106143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1062ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1063ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            Stmt *Init, Sema::FullExprArg Cond,
1064ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            VarDecl *CondVar, Sema::FullExprArg Inc,
1065ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            SourceLocation RParenLoc, Stmt *Body) {
10669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1067ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                  CondVar, Inc, RParenLoc, Body);
106843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new goto statement.
107143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
107243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
107343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1074ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1075ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                             LabelDecl *Label) {
107657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
107743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
107843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
107943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new indirect goto statement.
108043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
108143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
108243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
108360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1084ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                     SourceLocation StarLoc,
1085ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                     Expr *Target) {
10869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
108743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new return statement.
109043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
109143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
109243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1093ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
10949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnReturnStmt(ReturnLoc, Result);
109543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
109743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new declaration statement.
109843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
109943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
110043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
110160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   SourceLocation StartLoc,
110343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EndLoc) {
1104406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith    Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1105406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith    return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
110643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1108703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// \brief Build a new inline asm statement.
1109703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  ///
1110703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// By default, performs semantic analysis to build the new statement.
1111703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// Subclasses may override this routine to provide different behavior.
111260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
1113703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsSimple,
1114703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsVolatile,
1115703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumOutputs,
1116703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumInputs,
1117ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                  IdentifierInfo **Names,
1118703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Constraints,
1119703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Exprs,
11209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Expr *AsmString,
1121703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Clobbers,
1122703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  SourceLocation RParenLoc,
1123703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool MSAsm) {
1124c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1125703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  NumInputs, Names, move(Constraints),
11269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Exprs, AsmString, Clobbers,
1127703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  RParenLoc, MSAsm);
1128703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
11294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
11304dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @try statement.
11314dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
113460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
11359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *TryBody,
11368f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                        MultiStmtArg CatchStmts,
11379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *Finally) {
11389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
11399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Finally);
11404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
11414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
1142be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Rebuild an Objective-C exception declaration.
1143be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1144be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new declaration.
1145be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1146be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1147be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                    TypeSourceInfo *TInfo, QualType T) {
1148ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    return getSema().BuildObjCExceptionDecl(TInfo, T,
1149ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getInnerLocStart(),
1150ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getLocation(),
1151ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getIdentifier());
1152be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
1153c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1154be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Build a new Objective-C @catch statement.
1155be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1156be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1157be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
115860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1159be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          SourceLocation RParenLoc,
1160be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          VarDecl *Var,
11619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Stmt *Body) {
1162be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
11639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Var, Body);
1164be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
1165c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @finally statement.
11674dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11694dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
117060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
11719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Stmt *Body) {
11729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
11734dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
1174c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11758fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @throw statement.
1176d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  ///
1177d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
1178d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
117960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
11809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Operand) {
11819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1182d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
1183c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11848fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @synchronized statement.
11858fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  ///
11868fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
11878fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
118860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
11899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *Object,
11909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Stmt *Body) {
11919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
11929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Body);
11938fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  }
1194c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor
1195f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Build a new Objective-C @autoreleasepool statement.
1196f85e193739c953358c865005855253af4f68a497John McCall  ///
1197f85e193739c953358c865005855253af4f68a497John McCall  /// By default, performs semantic analysis to build the new statement.
1198f85e193739c953358c865005855253af4f68a497John McCall  /// Subclasses may override this routine to provide different behavior.
1199f85e193739c953358c865005855253af4f68a497John McCall  StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1200f85e193739c953358c865005855253af4f68a497John McCall                                            Stmt *Body) {
1201f85e193739c953358c865005855253af4f68a497John McCall    return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1202f85e193739c953358c865005855253af4f68a497John McCall  }
1203f85e193739c953358c865005855253af4f68a497John McCall
1204f85e193739c953358c865005855253af4f68a497John McCall
1205c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// \brief Build a new Objective-C fast enumeration statement.
1206c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  ///
1207c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1208c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
120960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1210f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation LParenLoc,
1211f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Element,
1212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Expr *Collection,
1213f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation RParenLoc,
1214f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Body) {
1215c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor    return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
12169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Element,
12179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Collection,
1218c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                RParenLoc,
12199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Body);
1220c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  }
1221c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
122243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ exception declaration.
122343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
122443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new decaration.
122543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1226ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1227a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                                TypeSourceInfo *Declarator,
1228ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                SourceLocation StartLoc,
1229ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                SourceLocation IdLoc,
1230ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                IdentifierInfo *Id) {
1231efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1232efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor                                                       StartLoc, IdLoc, Id);
1233efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    if (Var)
1234efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor      getSema().CurContext->addDecl(Var);
1235efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    return Var;
123643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
123743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
123843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ catch statement.
123943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
124043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
124143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
124260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1243f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 VarDecl *ExceptionDecl,
1244f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 Stmt *Handler) {
12459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
12469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Handler));
124743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
124943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ try statement.
125043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
125143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
125243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
125360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1254f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               Stmt *TryBlock,
1255f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               MultiStmtArg Handlers) {
12569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
125743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1259ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// \brief Build a new C++0x range-based for statement.
1260ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ///
1261ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// By default, performs semantic analysis to build the new statement.
1262ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// Subclasses may override this routine to provide different behavior.
1263ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1264ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    SourceLocation ColonLoc,
1265ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Stmt *Range, Stmt *BeginEnd,
1266ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Expr *Cond, Expr *Inc,
1267ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Stmt *LoopVar,
1268ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    SourceLocation RParenLoc) {
1269ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1270ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                          Cond, Inc, LoopVar, RParenLoc);
1271ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
1272ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
1273ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// \brief Attach body to a C++0x range-based for statement.
1274ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ///
1275ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// By default, performs semantic analysis to finish the new statement.
1276ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// Subclasses may override this routine to provide different behavior.
1277ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1278ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return getSema().FinishCXXForRangeStmt(ForRange, Body);
1279ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
1280ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
128128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHTryStmt(bool IsCXXTry,
128228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation TryLoc,
128328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *TryBlock,
128428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Handler) {
128528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
128628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
128728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
128828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
128928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                  Expr *FilterExpr,
129028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                  Stmt *Block) {
129128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
129228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
129328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
129428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
129528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                   Stmt *Block) {
129628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHFinallyBlock(Loc,Block);
129728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
129828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression that references a declaration.
1300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
130360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1304f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        LookupResult &R,
1305f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        bool RequiresADL) {
1306f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1307f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1308f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1309f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1310f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Build a new expression that references a declaration.
1311f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  ///
1312f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// By default, performs semantic analysis to build the new expression.
1313f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Subclasses may override this routine to provide different behavior.
131440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1315f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                ValueDecl *VD,
1316f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                const DeclarationNameInfo &NameInfo,
1317f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                TemplateArgumentListInfo *TemplateArgs) {
1318a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    CXXScopeSpec SS;
131940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    SS.Adopt(QualifierLoc);
1320dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
1321dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: loses template args.
13222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
13232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression in parentheses.
13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
133060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                    SourceLocation RParen) {
13329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1335a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Build a new pseudo-destructor expression.
13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1337a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1338a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
133960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1340f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation OperatorLoc,
1341f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            bool isArrow,
1342f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            CXXScopeSpec &SS,
1343f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            TypeSourceInfo *ScopeType,
1344f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation CCLoc,
1345f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation TildeLoc,
1346a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed);
13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary operator expression.
13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
135260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
13532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                        UnaryOperatorKind Opc,
13549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *SubExpr) {
13559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build a new builtin offsetof expression.
13598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
13608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
13618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
136260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       TypeSourceInfo *Type,
1364f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                       Sema::OffsetOfComponent *Components,
13658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       unsigned NumComponents,
13668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       SourceLocation RParenLoc) {
13678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
13688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          NumComponents, RParenLoc);
13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1370c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1371f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// \brief Build a new sizeof, alignof or vec_step expression with a
1372f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// type argument.
13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1376f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1377f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceLocation OpLoc,
1378f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         UnaryExprOrTypeTrait ExprKind,
1379f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceRange R) {
1380f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1383f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// \brief Build a new sizeof, alignof or vec step expression with an
1384f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// expression argument.
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1387b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1388f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1389f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         UnaryExprOrTypeTrait ExprKind,
1390f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceRange R) {
139160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1392e72c55b9a11be9f00fa3f66f7ad6b73b2814e963Chandler Carruth      = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1394f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
13951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new array subscript expression.
14001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
140360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LBracketLoc,
14059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *RHS,
1406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RBracketLoc) {
14079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
14089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             LBracketLoc, RHS,
1409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             RBracketLoc);
1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new call expression.
14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
141660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Args,
1418e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   SourceLocation RParenLoc,
1419e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   Expr *ExecConfig = 0) {
14209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1421e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   move(Args), RParenLoc, ExecConfig);
1422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member access expression.
14251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1426b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
142860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1429f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               bool isArrow,
143040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                               NestedNameSpecifierLoc QualifierLoc,
1431f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               const DeclarationNameInfo &MemberNameInfo,
1432f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               ValueDecl *Member,
1433f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FoundDecl,
1434d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                        const TemplateArgumentListInfo *ExplicitTemplateArgs,
1435f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FirstQualifierInScope) {
1436d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    if (!Member->getDeclName()) {
1437f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // We have a reference to an unnamed field.  This is always the
1438f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // base of an anonymous struct/union member access, i.e. the
1439f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // field is always of record type.
144040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1441f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      assert(Member->getType()->isRecordType() &&
1442f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             "unnamed member not of record type?");
14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1444429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      ExprResult BaseResult =
1445429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley        getSema().PerformObjectMemberConversion(Base,
1446429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                                QualifierLoc.getNestedNameSpecifier(),
1447429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                                FoundDecl, Member);
1448429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      if (BaseResult.isInvalid())
1449f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
1450429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      Base = BaseResult.take();
1451f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      MemberExpr *ME =
14539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        new (getSema().Context) MemberExpr(Base, isArrow,
14542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           Member, MemberNameInfo,
1455f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           cast<FieldDecl>(Member)->getType(),
1456f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           VK, OK_Ordinary);
1457d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      return getSema().Owned(ME);
1458d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    }
14591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    CXXScopeSpec SS;
146140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    SS.Adopt(QualifierLoc);
146283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
1463429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1464429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (BaseResult.isInvalid())
1465429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      return ExprError();
1466429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    Base = BaseResult.take();
14679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    QualType BaseType = Base->getType();
1468aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
14696bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // FIXME: this involves duplicating earlier analysis in a lot of
14706bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // cases; we should avoid this when possible.
14712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
14726bb8017bb9e828d118e15e59d71c66bba323c364John McCall    R.addDecl(FoundDecl);
1473c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    R.resolveKind();
1474c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
14759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1476129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, FirstQualifierInScope,
1477c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                              R, ExplicitTemplateArgs);
1478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new binary operator expression.
14811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
148460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
14852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                         BinaryOperatorKind Opc,
14869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *LHS, Expr *RHS) {
14879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new conditional operator expression.
14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
149460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildConditionalOperator(Expr *Cond,
149556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        SourceLocation QuestionLoc,
149656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        Expr *LHS,
149756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        SourceLocation ColonLoc,
149856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        Expr *RHS) {
14999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
15009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        LHS, RHS);
1501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C-style cast expression.
15041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
150760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
15089d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                         TypeSourceInfo *TInfo,
1509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc,
15109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *SubExpr) {
1511b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall    return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
15129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubExpr);
1513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new compound literal expression.
15161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
151960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
152042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall                                              TypeSourceInfo *TInfo,
1521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation RParenLoc,
15229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Init) {
152342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
15249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Init);
1525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new extended vector element access expression.
15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
153160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildExtVectorElementExpr(Expr *Base,
1532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation OpLoc,
1533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation AccessorLoc,
1534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               IdentifierInfo &Accessor) {
1535aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
1536129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    CXXScopeSpec SS;
15372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
15389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1539129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              OpLoc, /*IsArrow*/ false,
1540129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, /*FirstQualifierInScope*/ 0,
15412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                              NameInfo,
1542129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              /* TemplateArgs */ 0);
1543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new initializer list expression.
15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
154960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildInitList(SourceLocation LBraceLoc,
1550c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             MultiExprArg Inits,
1551c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             SourceLocation RBraceLoc,
1552c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             QualType ResultTy) {
155360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1554e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1555e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    if (Result.isInvalid() || ResultTy->isDependentType())
1556e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      return move(Result);
1557c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1558e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // Patch in the result type we were given, which may have been computed
1559e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // when the initial InitListExpr was built.
1560e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1561e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    ILE->setType(ResultTy);
1562e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    return move(Result);
1563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new designated initializer expression.
15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
156960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             MultiExprArg ArrayExprs,
1571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation EqualOrColonLoc,
1572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             bool GNUSyntax,
15739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *Init) {
157460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
15769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Init);
1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1578f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.release();
1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new value-initialized expression.
15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds the implicit value initialization without performing
1587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// any semantic analysis. Subclasses may override this routine to provide
1588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
158960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildImplicitValueInitExpr(QualType T) {
1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new \c va_arg expression.
15941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
159760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
15989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SubExpr, TypeSourceInfo *TInfo,
15992cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    SourceLocation RParenLoc) {
16002cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara    return getSema().BuildVAArgExpr(BuiltinLoc,
16019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    SubExpr, TInfo,
16022cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    RParenLoc);
1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression list in parentheses.
16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
160960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        MultiExprArg SubExprs,
1611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1612c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1613f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian                                               move(SubExprs));
1614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new address-of-label expression.
16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis, using the name of the label
1619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// rather than attempting to map the label statement itself.
1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
162160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1622ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                  SourceLocation LabelLoc, LabelDecl *Label) {
162357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
1624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new GNU statement expression.
16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
163060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
16319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Stmt *SubStmt,
1632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
16339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1636b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new __builtin_choose_expr expression.
1637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
164060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
16419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Cond, Expr *LHS, Expr *RHS,
1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                     SourceLocation RParenLoc) {
1643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.ActOnChooseExpr(BuiltinLoc,
16449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Cond, LHS, RHS,
1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   RParenLoc);
1646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1648f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// \brief Build a new generic selection expression.
1649f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ///
1650f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// By default, performs semantic analysis to build the new expression.
1651f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// Subclasses may override this routine to provide different behavior.
1652f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1653f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         SourceLocation DefaultLoc,
1654f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         SourceLocation RParenLoc,
1655f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         Expr *ControllingExpr,
1656f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         TypeSourceInfo **Types,
1657f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         Expr **Exprs,
1658f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         unsigned NumAssocs) {
1659f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1660f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                ControllingExpr, Types, Exprs,
1661f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                NumAssocs);
1662f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
1663f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
1664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new overloaded operator call expression.
1665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// The semantic analysis provides the behavior of template instantiation,
1668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// copying with transformations that turn what looks like an overloaded
16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// operator call into a use of a builtin operator, performing
1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument-dependent lookup, etc. Subclasses may override this routine to
1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
167260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation OpLoc,
16749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Callee,
16759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *First,
16769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Second);
16771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++ "named" cast expression, such as static_cast or
1679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// reinterpret_cast.
1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine dispatches to one of the more-specific routines
16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
168460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           Stmt::StmtClass Class,
1686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
16879d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
16909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    switch (Class) {
1693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXStaticCastExprClass:
16949d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
16951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
16969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
1697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXDynamicCastExprClass:
16999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
17001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                    RAngleLoc, LParenLoc,
17019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    SubExpr, RParenLoc);
17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXReinterpretCastExprClass:
17049d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
17051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                        RAngleLoc, LParenLoc,
17069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                        SubExpr,
1707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        RParenLoc);
17081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXConstCastExprClass:
17109d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
17129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
17131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    default:
1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      assert(false && "Invalid C++ named cast");
1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      break;
1717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
17181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1719f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
1720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ static_cast expression.
1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
172660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LAngleLoc,
17289d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                            TypeSourceInfo *TInfo,
1729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RAngleLoc,
1730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LParenLoc,
17319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Expr *SubExpr,
1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RParenLoc) {
1733c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
17349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1735c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1736c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ dynamic_cast expression.
1740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
174360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LAngleLoc,
17459d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                             TypeSourceInfo *TInfo,
1746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RAngleLoc,
1747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LParenLoc,
17489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *SubExpr,
1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RParenLoc) {
1750c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
17519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1752c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1753c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ reinterpret_cast expression.
1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
176060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LAngleLoc,
17629d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                                 TypeSourceInfo *TInfo,
1763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RAngleLoc,
1764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LParenLoc,
17659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SubExpr,
1766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RParenLoc) {
1767c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
17689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1769c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1770c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ const_cast expression.
1774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
177760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
17799d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
17829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1784c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
17859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1786c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1787c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ functional-style cast expression.
1791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1794ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1795ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation LParenLoc,
1796ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          Expr *Sub,
1797ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation RParenLoc) {
1798ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1799f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                               MultiExprArg(&Sub, 1),
1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(type) expression.
1804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
180760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
180857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
180957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        TypeSourceInfo *Operand,
1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1811c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
181257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
181501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(expr) expression.
1817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
182060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
182157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
18229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand,
1823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
18249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
182557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
18261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
182801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(type) expression.
182901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
183001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
183101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
183201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
183301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
183401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        TypeSourceInfo *Operand,
183501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
183601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
183701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
183801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
183901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
184001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(expr) expression.
184101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
184201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
184301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
184401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
184501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
184601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        Expr *Operand,
184701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
184801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
184901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
185001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
185101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "this" expression.
1853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new "this" expression without performing any
18551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// semantic analysis. Subclasses may override this routine to provide
1856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
185760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1858ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                QualType ThisType,
1859ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                bool isImplicit) {
1860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().Owned(
1861828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                      new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1862828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                                                          isImplicit));
1863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ throw expression.
1866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
186960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
18709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXThrow(ThrowLoc, Sub);
1871b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ default-argument expression.
1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new default-argument expression, which does not
1876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// require any semantic analysis. Subclasses may override this routine to
1877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
187860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1879036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                            ParmVarDecl *Param) {
1880036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1881036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                                     Param));
1882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ zero-initialization expression.
1885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1888ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1889ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1890ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1891ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
18921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                               MultiExprArg(getSema(), 0, 0),
1893ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               RParenLoc);
1894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "new" expression.
1897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
190060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
19011bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               bool UseGlobal,
19021bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementLParen,
19031bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg PlacementArgs,
19041bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementRParen,
19051bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceRange TypeIdParens,
19061bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               QualType AllocatedType,
19071bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               TypeSourceInfo *AllocatedTypeInfo,
19081bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               Expr *ArraySize,
19091bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorLParen,
19101bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg ConstructorArgs,
19111bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorRParen) {
19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getSema().BuildCXXNew(StartLoc, UseGlobal,
1913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementLParen,
1914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(PlacementArgs),
1915b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementRParen,
19164bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                 TypeIdParens,
19171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedType,
19181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedTypeInfo,
19199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 ArraySize,
1920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorLParen,
1921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(ConstructorArgs),
1922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorRParen);
1923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "delete" expression.
1926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
192960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsGlobalDelete,
1931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsArrayForm,
19329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand) {
1933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
19349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Operand);
1935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary type trait expression.
1938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
194160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
19423d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation StartLoc,
19433d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   TypeSourceInfo *T,
19443d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation RParenLoc) {
19453d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor    return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
1946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
19486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// \brief Build a new binary type trait expression.
19496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ///
19506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// By default, performs semantic analysis to build the new expression.
19516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Subclasses may override this routine to provide different behavior.
19526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
19536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation StartLoc,
19546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *LhsT,
19556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *RhsT,
19566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation RParenLoc) {
19576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
19586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
19596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
196021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// \brief Build a new array type trait expression.
196121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ///
196221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// By default, performs semantic analysis to build the new expression.
196321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// Subclasses may override this routine to provide different behavior.
196421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
196521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   SourceLocation StartLoc,
196621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   TypeSourceInfo *TSInfo,
196721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   Expr *DimExpr,
196821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   SourceLocation RParenLoc) {
196921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
197021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
197121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
1972552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// \brief Build a new expression trait expression.
1973552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ///
1974552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// By default, performs semantic analysis to build the new expression.
1975552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// Subclasses may override this routine to provide different behavior.
1976552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1977552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   SourceLocation StartLoc,
1978552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   Expr *Queried,
1979552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   SourceLocation RParenLoc) {
1980552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1981552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
1982552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new (previously unresolved) declaration reference
1984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// expression.
1985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
198800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  ExprResult RebuildDependentScopeDeclRefExpr(
198900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
19902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                       const DeclarationNameInfo &NameInfo,
1991f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
199300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    SS.Adopt(QualifierLoc);
1994f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1995f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (TemplateArgs)
19962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
1997f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                    *TemplateArgs);
1998f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
19992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
2000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new template-id expression.
2003b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
200660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2007f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         LookupResult &R,
2008f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         bool RequiresADL,
2009d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                              const TemplateArgumentListInfo &TemplateArgs) {
2010f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
2011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
201760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstructExpr(QualType T,
20184411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                           SourceLocation Loc,
2019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           CXXConstructorDecl *Constructor,
2020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           bool IsElidable,
20218c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           MultiExprArg Args,
20228c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           bool RequiresZeroInit,
2023428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                             CXXConstructExpr::ConstructionKind ConstructKind,
2024428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           SourceRange ParenRange) {
2025ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
2026c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
20274411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                          ConvertedArgs))
2028f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2029c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
20304411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor    return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
20318c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           move_arg(ConvertedArgs),
2032428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           RequiresZeroInit, ConstructKind,
2033428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           ParenRange);
2034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
2040ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2041ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
2042ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           MultiExprArg Args,
2043ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
2044ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
2045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
2046b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
2047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
2048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2051b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2053b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
2054ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2055ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation LParenLoc,
2056ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               MultiExprArg Args,
2057ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation RParenLoc) {
2058ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
2059b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
2060b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
2061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
2062b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member reference expression.
2065b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
206860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
20697c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                QualType BaseType,
20707c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                bool IsArrow,
20717c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                SourceLocation OperatorLoc,
20727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
2073129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            NamedDecl *FirstQualifierInScope,
20742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                   const DeclarationNameInfo &MemberNameInfo,
2075129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
2076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
20777c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    SS.Adopt(QualifierLoc);
20781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2080aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
2081129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            SS, FirstQualifierInScope,
20822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            MemberNameInfo,
20832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            TemplateArgs);
2084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2085b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2086129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Build a new member reference expression.
20873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  ///
20883b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
20893b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
209060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
2091aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                               QualType BaseType,
2092129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceLocation OperatorLoc,
2093129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               bool IsArrow,
20944c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
2095c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                               NamedDecl *FirstQualifierInScope,
2096129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               LookupResult &R,
2097129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                const TemplateArgumentListInfo *TemplateArgs) {
20983b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    CXXScopeSpec SS;
20994c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    SS.Adopt(QualifierLoc);
21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2102aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
2103c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            SS, FirstQualifierInScope,
2104c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            R, TemplateArgs);
21053b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// \brief Build a new noexcept expression.
21082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ///
21092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// By default, performs semantic analysis to build the new expression.
21102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// Subclasses may override this routine to provide different behavior.
21112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
21122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
21132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
21142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2115ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Build a new expression to compute the length of a parameter pack.
2116ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2117ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation PackLoc,
2118ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation RParenLoc,
2119ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   unsigned Length) {
2120ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2121ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                                OperatorLoc, Pack, PackLoc,
2122ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                                RParenLoc, Length);
2123ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2124ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new Objective-C @encode expression.
2126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
212960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
213081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                         TypeSourceInfo *EncodeTypeInfo,
2131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc) {
213281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                           RParenLoc));
21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
2135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
213692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C class message.
213760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
213892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2139f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                          SourceLocation SelectorLoc,
214092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
2141c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
214292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
214392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
214492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return SemaRef.BuildClassMessage(ReceiverTypeInfo,
214592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     ReceiverTypeInfo->getType(),
214692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     /*SuperLoc=*/SourceLocation(),
2147f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                     Sel, Method, LBracLoc, SelectorLoc,
2148f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                     RBracLoc, move(Args));
214992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
215092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
215192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C instance message.
215260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(Expr *Receiver,
215392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2154f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                          SourceLocation SelectorLoc,
215592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
2156c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
215792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
215892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
21599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildInstanceMessage(Receiver,
21609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Receiver->getType(),
216192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        /*SuperLoc=*/SourceLocation(),
2162f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                        Sel, Method, LBracLoc, SelectorLoc,
2163f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                        RBracLoc, move(Args));
216492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
216592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
2166f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C ivar reference expression.
2167f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2168f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2169f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
217060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2171f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          SourceLocation IvarLoc,
2172f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          bool IsArrow, bool IsFreeIvar) {
2173f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    // FIXME: We lose track of the IsFreeIvar bit.
2174f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
2175429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2176f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2177f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
217860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2179f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IvarLoc,
2180d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0,
2181ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall                                                         false);
2182429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2183f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2184c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2185f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
2186f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
2187c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2188429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2189c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IvarLoc, IsArrow, SS,
2190f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
2191c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2192f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2193f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2194e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor
2195e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// \brief Build a new Objective-C property reference expression.
2196e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  ///
2197e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2198e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
219960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2200e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              ObjCPropertyDecl *Property,
2201e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              SourceLocation PropertyLoc) {
2202e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    CXXScopeSpec SS;
2203429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2204e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2205e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                   Sema::LookupMemberName);
2206e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    bool IsArrow = false;
220760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2208e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                                         /*FIME:*/PropertyLoc,
2209d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2210429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2211f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2212c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2213e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.get())
2214e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      return move(Result);
2215c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2216429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2217c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/PropertyLoc, IsArrow,
2218c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              SS,
2219e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*FirstQualifierInScope=*/0,
2220c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2221e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*TemplateArgs=*/0);
2222e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  }
2223c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
222412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// \brief Build a new Objective-C property reference expression.
22259cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  ///
22269cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
222712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// Subclasses may override this routine to provide different behavior.
222812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
222912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Getter,
223012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Setter,
223112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        SourceLocation PropertyLoc) {
223212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // Since these expressions can only be value-dependent, we do not
223312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // need to perform semantic analysis again.
223412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return Owned(
223512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
223612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  VK_LValue, OK_ObjCProperty,
223712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  PropertyLoc, Base));
22389cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  }
22399cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor
2240f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C "isa" expression.
2241f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2242f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2243f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
224460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2245f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                      bool IsArrow) {
2246f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
2247429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2248f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2249f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
225060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2251f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IsaLoc,
2252d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2253429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2254f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2255c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2256f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
2257f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
2258c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2259429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IsaLoc, IsArrow, SS,
2261f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
2262c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2263f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2264f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2265c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new shuffle vector expression.
2267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2269b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
227060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2271f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      MultiExprArg SubExprs,
2272f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      SourceLocation RParenLoc) {
2273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Find the declaration for __builtin_shufflevector
22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const IdentifierInfo &Name
2275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.Context.Idents.get("__builtin_shufflevector");
2276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
22791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Build a reference to the __builtin_shufflevector builtin
2281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
2282429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Callee
2283429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2284429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                                        VK_LValue, BuiltinLoc));
2285429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    Callee = SemaRef.UsualUnaryConversions(Callee.take());
2286429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Callee.isInvalid())
2287429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      return ExprError();
22881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Build the CallExpr
2290b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    unsigned NumSubExprs = SubExprs.size();
2291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Expr **Subs = (Expr **)SubExprs.release();
2292429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult TheCall = SemaRef.Owned(
2293429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
2294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       Subs, NumSubExprs,
22955291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor                                                   Builtin->getCallResultType(),
2296f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            Expr::getValueKindForType(Builtin->getResultType()),
2297429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                     RParenLoc));
22981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Type-check the __builtin_shufflevector expression.
2300429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
2301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
230243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
23038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Build a new template argument pack expansion.
23048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
23058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
23068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// for a template argument. Subclasses may override this routine to provide
23078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// different behavior.
23088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2309cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           SourceLocation EllipsisLoc,
2310cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
23118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    switch (Pattern.getArgument().getKind()) {
23127a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    case TemplateArgument::Expression: {
23137a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      ExprResult Result
231467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
231567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                       EllipsisLoc, NumExpansions);
23167a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      if (Result.isInvalid())
23177a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor        return TemplateArgumentLoc();
23187a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor
23197a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      return TemplateArgumentLoc(Result.get(), Result.get());
23207a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    }
2321dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
23228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Template:
2323a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor      return TemplateArgumentLoc(TemplateArgument(
2324a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                          Pattern.getArgument().getAsTemplate(),
23252be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor                                                  NumExpansions),
2326b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                 Pattern.getTemplateQualifierLoc(),
2327a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 Pattern.getTemplateNameLoc(),
2328a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 EllipsisLoc);
23298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
23308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Null:
23318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Integral:
23328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Declaration:
23338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Pack:
2334a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    case TemplateArgument::TemplateExpansion:
23358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm_unreachable("Pack expansion pattern has no parameter packs");
23368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
23378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Type:
23388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (TypeSourceInfo *Expansion
23398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor            = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2340cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           EllipsisLoc,
2341cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           NumExpansions))
23428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
23438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                   Expansion);
23448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      break;
23458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
23468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
23478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return TemplateArgumentLoc();
23488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
23498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
2350dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// \brief Build a new expression pack expansion.
2351dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  ///
2352dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
2353dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// for an expression. Subclasses may override this routine to provide
2354dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// different behavior.
235567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
235667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                  llvm::Optional<unsigned> NumExpansions) {
235767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2358dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  }
2359dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
236043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate:
2361c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2362c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     QualType ObjectType,
2363c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     NamedDecl *FirstQualifierInScope,
2364c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     CXXScopeSpec &SS);
2365b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
2366b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2367b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             QualType ObjectType,
2368b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             NamedDecl *FirstQualifierInScope,
2369b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             CXXScopeSpec &SS);
2370577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor};
2371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
237243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
237360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
237443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!S)
237543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return SemaRef.Owned(S);
23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
237743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  switch (S->getStmtClass()) {
237843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::NoStmtClass: break;
23791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
238043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform individual statement nodes
238143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                                              \
238243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
238363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node)
238443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent)
23854bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
23861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
238743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform expressions by calling TransformExpr.
238843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)
23897381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
239043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class:
23914bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
239243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    {
239360d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
239443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      if (E.isInvalid())
2395f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
23961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
239843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    }
23991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
24001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
240243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2405670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived>
240660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!E)
2408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(E);
2409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  switch (E->getStmtClass()) {
2411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::NoStmtClass: break;
2412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break;
24137381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
2414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                                              \
2415454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall    case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
24164bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
24171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
24181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
2420657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor}
2421657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor
2422657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived>
2423aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2424aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            unsigned NumInputs,
2425aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool IsCall,
2426aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                      llvm::SmallVectorImpl<Expr *> &Outputs,
2427aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool *ArgChanged) {
2428aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  for (unsigned I = 0; I != NumInputs; ++I) {
2429aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    // If requested, drop call arguments that need to be dropped.
2430aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2431aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      if (ArgChanged)
2432aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor        *ArgChanged = true;
2433aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2434aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      break;
2435aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    }
2436aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2437dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2438dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      Expr *Pattern = Expansion->getPattern();
2439dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2440dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2441dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2442dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2443dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2444dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
2445dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // be expanded.
2446dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      bool Expand = true;
2447d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
244867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> OrigNumExpansions
244967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = Expansion->getNumExpansions();
245067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
2451dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2452dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Pattern->getSourceRange(),
2453dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Unexpanded.data(),
2454dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Unexpanded.size(),
2455d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand, RetainExpansion,
2456d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
2457dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        return true;
2458dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2459dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (!Expand) {
2460dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // The transform has determined that we should perform a simple
2461dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // transformation on the pack expansion, producing another pack
2462dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // expansion.
2463dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2464dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2465dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (OutPattern.isInvalid())
2466dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2467dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2468dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
246967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                Expansion->getEllipsisLoc(),
247067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                           NumExpansions);
2471dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2472dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2473dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2474dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (ArgChanged)
2475dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          *ArgChanged = true;
2476dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2477dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        continue;
2478dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2479c8fc90a854b4ccba21c85884676a80334159dd94John McCall
2480c8fc90a854b4ccba21c85884676a80334159dd94John McCall      // Record right away that the argument was changed.  This needs
2481c8fc90a854b4ccba21c85884676a80334159dd94John McCall      // to happen even if the array expands to nothing.
2482c8fc90a854b4ccba21c85884676a80334159dd94John McCall      if (ArgChanged) *ArgChanged = true;
2483dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2484dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // The transform has determined that we should perform an elementwise
2485dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // expansion of the pattern. Do so.
2486cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
2487dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2488dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().TransformExpr(Pattern);
2489dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2490dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2491dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
249277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.get()->containsUnexpandedParameterPack()) {
249367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor          Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
249467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                     OrigNumExpansions);
249577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.isInvalid())
249677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
249777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
249877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
2499dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2500dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2501dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2502dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      continue;
2503dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    }
2504dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2505aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2506aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.isInvalid())
2507aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return true;
2508aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2509aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.get() != Inputs[I] && ArgChanged)
2510aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      *ArgChanged = true;
2511aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2512aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    Outputs.push_back(Result.get());
2513aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
2514aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2515aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  return false;
2516aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor}
2517aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2518aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived>
2519c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc
2520c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2521c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                    NestedNameSpecifierLoc NNS,
2522c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                     QualType ObjectType,
2523c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                             NamedDecl *FirstQualifierInScope) {
2524c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2525c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2526c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor       Qualifier = Qualifier.getPrefix())
2527c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Qualifiers.push_back(Qualifier);
2528c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2529c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  CXXScopeSpec SS;
2530c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  while (!Qualifiers.empty()) {
2531c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2532c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2533c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2534c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    switch (QNNS->getKind()) {
2535c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Identifier:
2536c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2537c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              *QNNS->getAsIdentifier(),
2538c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              Q.getLocalBeginLoc(),
2539c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              Q.getLocalEndLoc(),
2540c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              ObjectType, false, SS,
2541c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              FirstQualifierInScope, false))
2542c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        return NestedNameSpecifierLoc();
2543c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2544c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2545c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2546c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Namespace: {
2547c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      NamespaceDecl *NS
2548c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        = cast_or_null<NamespaceDecl>(
2549c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                    getDerived().TransformDecl(
2550c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                          Q.getLocalBeginLoc(),
2551c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                       QNNS->getAsNamespace()));
2552c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2553c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2554c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
2555c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2556c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::NamespaceAlias: {
2557c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      NamespaceAliasDecl *Alias
2558c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        = cast_or_null<NamespaceAliasDecl>(
2559c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                      getDerived().TransformDecl(Q.getLocalBeginLoc(),
2560c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                 QNNS->getAsNamespaceAlias()));
2561c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2562c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                Q.getLocalEndLoc());
2563c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2564c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
2565c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2566c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Global:
2567c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      // There is no meaningful transformation that one could perform on the
2568c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      // global scope.
2569c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2570c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2571c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2572c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::TypeSpecWithTemplate:
2573c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::TypeSpec: {
2574c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2575c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              FirstQualifierInScope, SS);
2576c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2577c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (!TL)
2578c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        return NestedNameSpecifierLoc();
2579c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2580c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2581c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor          (SemaRef.getLangOptions().CPlusPlus0x &&
2582c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor           TL.getType()->isEnumeralType())) {
2583c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        assert(!TL.getType().hasLocalQualifiers() &&
2584c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor               "Can't get cv-qualifiers here");
2585c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2586c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                  Q.getLocalEndLoc());
2587c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        break;
2588c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      }
258900c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      // If the nested-name-specifier is an invalid type def, don't emit an
259000c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      // error because a previous error should have already been emitted.
259100c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
259200c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
259300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu        SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
259400c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu          << TL.getType() << SS.getRange();
259500c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      }
2596c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      return NestedNameSpecifierLoc();
2597c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
25987c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    }
2599c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
26007c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    // The qualifier-in-scope and object type only apply to the leftmost entity.
2601c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    FirstQualifierInScope = 0;
26027c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    ObjectType = QualType();
2603c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  }
2604c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2605c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // Don't rebuild the nested-name-specifier if we don't have to.
2606c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2607c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      !getDerived().AlwaysRebuild())
2608c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    return NNS;
2609c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2610c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // If we can re-use the source-location data from the original
2611c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // nested-name-specifier, do so.
2612c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (SS.location_size() == NNS.getDataLength() &&
2613c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2614c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2615c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2616c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // Allocate new nested-name-specifier location information.
2617c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  return SS.getWithLocInContext(SemaRef.Context);
2618c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor}
2619c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2620c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived>
26212577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo
26222577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived>
262343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
26242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name = NameInfo.getName();
262581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  if (!Name)
26262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo();
262781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
262881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  switch (Name.getNameKind()) {
262981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::Identifier:
263081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCZeroArgSelector:
263181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCOneArgSelector:
263281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCMultiArgSelector:
263381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXOperatorName:
26343e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  case DeclarationName::CXXLiteralOperatorName:
263581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXUsingDirective:
26362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NameInfo;
26371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
263881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConstructorName:
263981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXDestructorName:
264081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConversionFunctionName: {
26412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *NewTInfo;
26422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CanQualType NewCanTy;
26432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
264443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewTInfo = getDerived().TransformType(OldTInfo);
264543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NewTInfo)
264643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall        return DeclarationNameInfo();
264743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
26482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
26492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    else {
26502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewTInfo = 0;
26512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
265243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      QualType NewT = getDerived().TransformType(Name.getCXXNameType());
26532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      if (NewT.isNull())
26542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        return DeclarationNameInfo();
26552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewCanTy = SemaRef.Context.getCanonicalType(NewT);
26562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
26571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationName NewName
26592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
26602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                           NewCanTy);
26612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NewNameInfo(NameInfo);
26622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setName(NewName);
26632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setNamedTypeInfo(NewTInfo);
26642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NewNameInfo;
266581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  }
26661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
26671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  assert(0 && "Unknown name kind.");
26692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return DeclarationNameInfo();
267081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor}
267181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
267281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived>
26731eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
2674fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2675fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              TemplateName Name,
2676fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              SourceLocation NameLoc,
2677fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              QualType ObjectType,
2678fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              NamedDecl *FirstQualifierInScope) {
2679fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2680fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *Template = QTN->getTemplateDecl();
2681fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    assert(Template && "qualified template name must refer to a template");
2682fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2683fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *TransTemplate
2684fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2685fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                                              Template));
2686fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransTemplate)
2687fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2688fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2689fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2690fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        SS.getScopeRep() == QTN->getQualifier() &&
2691fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransTemplate == Template)
2692fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2693fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2694fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2695fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            TransTemplate);
2696fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2697fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2698fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2699fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (SS.getScopeRep()) {
2700fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      // These apply to the scope specifier, not the template.
2701fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      ObjectType = QualType();
2702fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      FirstQualifierInScope = 0;
2703fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    }
2704fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2705fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2706fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        SS.getScopeRep() == DTN->getQualifier() &&
2707fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        ObjectType.isNull())
2708fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2709fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2710fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (DTN->isIdentifier()) {
2711fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return getDerived().RebuildTemplateName(SS,
2712fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              *DTN->getIdentifier(),
2713fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              NameLoc,
2714fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              ObjectType,
2715fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              FirstQualifierInScope);
2716fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    }
2717fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2718fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2719fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            ObjectType);
2720fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2721fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2722fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2723fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *TransTemplate
2724fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2725fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                                              Template));
2726fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransTemplate)
2727fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2728fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2729fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2730fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransTemplate == Template)
2731fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2732fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2733fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return TemplateName(TransTemplate);
2734fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2735fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2736fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (SubstTemplateTemplateParmPackStorage *SubstPack
2737fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = Name.getAsSubstTemplateTemplateParmPack()) {
2738fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateTemplateParmDecl *TransParam
2739fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    = cast_or_null<TemplateTemplateParmDecl>(
2740fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor            getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2741fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransParam)
2742fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2743fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2744fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2745fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransParam == SubstPack->getParameterPack())
2746fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2747fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2748fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(TransParam,
2749fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SubstPack->getArgumentPack());
2750fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2751fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2752fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  // These should be getting filtered out before they reach the AST.
2753fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  llvm_unreachable("overloaded function decl survived to here");
2754fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  return TemplateName();
2755fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor}
2756fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2757fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived>
2758833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc(
2759833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgument &Arg,
2760833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2761833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation Loc = getDerived().getBaseLocation();
2762670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  switch (Arg.getKind()) {
2763670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Null:
27649f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("null template argument in TreeTransform");
2765833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2766833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2767833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
2768833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg,
2769a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall               SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2770c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2771833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2772833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2773788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
2774b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor  case TemplateArgument::TemplateExpansion: {
2775b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    NestedNameSpecifierLocBuilder Builder;
2776b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    TemplateName Template = Arg.getAsTemplate();
2777b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2778b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2779b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2780b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2781b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
2782b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (Arg.getKind() == TemplateArgument::Template)
2783b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Output = TemplateArgumentLoc(Arg,
2784b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Builder.getWithLocInContext(SemaRef.Context),
2785b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Loc);
2786b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    else
2787b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Output = TemplateArgumentLoc(Arg,
2788b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Builder.getWithLocInContext(SemaRef.Context),
2789b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Loc, Loc);
2790b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
2791a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    break;
2792b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor  }
2793a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2794833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
2795833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2796833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2797833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2798833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
2799670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Integral:
2800833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
2801828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2802833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2803833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
2804833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
2805833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2806833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived>
2807833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument(
2808833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgumentLoc &Input,
2809833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2810833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgument &Arg = Input.getArgument();
2811833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
2812833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
2813833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
2814833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = Input;
2815833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
28161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2817670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Type: {
2818a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *DI = Input.getTypeSourceInfo();
2819833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (DI == NULL)
2820a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall      DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2821833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2822833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    DI = getDerived().TransformType(DI);
2823833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!DI) return true;
2824833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2825833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2826833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2827670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2829670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Declaration: {
2830833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // FIXME: we should never have to transform one of these.
2831972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    DeclarationName Name;
2832972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2833972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor      Name = ND->getDeclName();
2834788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemporaryBase Rebase(*this, Input.getLocation(), Name);
28357c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2836833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!D) return true;
2837833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2838828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Expr *SourceExpr = Input.getSourceDeclExpression();
2839828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    if (SourceExpr) {
2840828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      EnterExpressionEvaluationContext Unevaluated(getSema(),
2841f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Sema::Unevaluated);
284260d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(SourceExpr);
28439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      SourceExpr = (E.isInvalid() ? 0 : E.take());
2844828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    }
2845828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
2846828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2847833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2848670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2850788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template: {
2851b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2852b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (QualifierLoc) {
2853b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2854b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      if (!QualifierLoc)
2855b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor        return true;
2856b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    }
2857b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
28581d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    CXXScopeSpec SS;
28591d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    SS.Adopt(QualifierLoc);
2860788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemplateName Template
28611d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor      = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
28621d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor                                           Input.getTemplateNameLoc());
2863788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    if (Template.isNull())
2864788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      return true;
2865c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2866b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
2867788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateNameLoc());
2868788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return false;
2869788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  }
2870a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2871a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor  case TemplateArgument::TemplateExpansion:
2872a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    llvm_unreachable("Caller should expand pack expansions");
2873a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2874670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Expression: {
2875670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    // Template argument expressions are not potentially evaluated.
28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EnterExpressionEvaluationContext Unevaluated(getSema(),
2877f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                 Sema::Unevaluated);
28781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2879833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Expr *InputExpr = Input.getSourceExpression();
2880833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2882223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner    ExprResult E = getDerived().TransformExpr(InputExpr);
2883833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (E.isInvalid()) return true;
28849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2885833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2886670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2888670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Pack: {
2889670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2890670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    TransformedArgs.reserve(Arg.pack_size());
28911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2892670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor                                      AEnd = Arg.pack_end();
2893670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor         A != AEnd; ++A) {
28941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2895833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // FIXME: preserve source information here when we start
2896833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // caring about parameter packs.
2897833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2898828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc InputArg;
2899828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc OutputArg;
2900828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      getDerived().InventTemplateArgumentLoc(*A, InputArg);
2901828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2902833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall        return true;
2903833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2904828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TransformedArgs.push_back(OutputArg.getArgument());
2905670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    }
2906910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
2907910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    TemplateArgument *TransformedArgsPtr
2908910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2909910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2910910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor              TransformedArgsPtr);
2911910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2912910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                                  TransformedArgs.size()),
2913910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                 Input.getLocInfo());
2914833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2915670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
2916670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
29171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2918670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Work around bogus GCC warning
2919833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return true;
2920670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor}
2921670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
29227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information
29237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator.
29247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator>
29257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator {
29267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TreeTransform<Derived> &Self;
29277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  InputIterator Iter;
29287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic:
29307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc value_type;
29317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc reference;
29327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef typename std::iterator_traits<InputIterator>::difference_type
29337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    difference_type;
29347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef std::input_iterator_tag iterator_category;
29357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class pointer {
29377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Arg;
2938fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
29407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
29417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    const TemplateArgumentLoc *operator->() const { return &Arg; }
29437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
29447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator() { }
29467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
29487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                             InputIterator Iter)
29497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    : Self(Self), Iter(Iter) { }
29507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator &operator++() {
29527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++Iter;
29537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return *this;
2954fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  }
2955fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator operator++(int) {
29577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocInventIterator Old(*this);
29587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++(*this);
29597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Old;
29607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  reference operator*() const {
29637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Result;
29647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    Self.InventTemplateArgumentLoc(*Iter, Result);
29657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Result;
29667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  pointer operator->() const { return pointer(**this); }
29697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator==(const TemplateArgumentLocInventIterator &X,
29717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
29727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter == Y.Iter;
29737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
2974fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator!=(const TemplateArgumentLocInventIterator &X,
29767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
29777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter != Y.Iter;
29787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor};
29807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29817f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived>
29827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator>
29837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
29847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                        InputIterator Last,
29857f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor                                            TemplateArgumentListInfo &Outputs) {
29867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  for (; First != Last; ++First) {
29877f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    TemplateArgumentLoc Out;
29887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc In = *First;
29898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().getKind() == TemplateArgument::Pack) {
29918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Unpack argument packs, which we translate them into separate
29928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // arguments.
29937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // FIXME: We could do much better if we could guarantee that the
29947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // TemplateArgumentLocInfo for the pack expansion would be usable for
29957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // all of the template arguments in the argument pack.
29967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      typedef TemplateArgumentLocInventIterator<Derived,
29977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                TemplateArgument::pack_iterator>
29987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        PackLocIterator;
29997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      if (TransformTemplateArguments(PackLocIterator(*this,
30007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                 In.getArgument().pack_begin()),
30017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     PackLocIterator(*this,
30027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                   In.getArgument().pack_end()),
30037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     Outputs))
30047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return true;
30058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
30078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
30088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().isPackExpansion()) {
30108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // We have a pack expansion, for which we will be substituting into
30118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // the pattern.
30128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      SourceLocation Ellipsis;
3013cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> OrigNumExpansions;
30148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      TemplateArgumentLoc Pattern
3015cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3016cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                     getSema().Context);
30178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
30198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
30208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
30218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
30238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // be expanded.
30248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      bool Expand = true;
3025d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3026cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
30278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (getDerived().TryExpandParameterPacks(Ellipsis,
30288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Pattern.getSourceRange(),
30298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.data(),
30308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.size(),
3031d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand,
3032d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3033d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
30348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return true;
30358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (!Expand) {
30378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // The transform has determined that we should perform a simple
30388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // transformation on the pack expansion, producing another pack
30398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // expansion.
30408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        TemplateArgumentLoc OutPattern;
30418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
30428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
30438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
3045cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3046cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                NumExpansions);
30478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (Out.getArgument().isNull())
30488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
30518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        continue;
30528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
30538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // The transform has determined that we should perform an elementwise
30558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // expansion of the pattern. Do so.
3056cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
30578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
30588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
30608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
306277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.getArgument().containsUnexpandedParameterPack()) {
3063cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3064cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                  OrigNumExpansions);
306577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.getArgument().isNull())
306677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
306777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
306877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
30698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
30708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
30718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30723cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
30733cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
30743cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
30753cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
30763cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
30773cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
30783cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
30793cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
3080cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3081cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                OrigNumExpansions);
30823cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (Out.getArgument().isNull())
30833cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
30843cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
30853cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        Outputs.addArgument(Out);
30863cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
3087d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
30888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
30898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
30908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    // The simple case:
30928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (getDerived().TransformTemplateArgument(In, Out))
30937f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor      return true;
30947f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
30957f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    Outputs.addArgument(Out);
30967f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  }
30977f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
30987f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  return false;
30997f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
31007f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor}
31017f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
3102577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
3103577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation
3104577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
3105577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3106577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
310743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) {
3108577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (getDerived().AlreadyTransformed(T))
3109577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T;
31101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3111a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Temporary workaround.  All of these transformations should
3112a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // eventually turn into transformations on TypeLocs.
3113c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3114c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor                                                getDerived().getBaseLocation());
3115c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
311643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
31171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3118a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (!NewDI)
3119a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
31201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3121a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return NewDI->getType();
3122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
312543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3126a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlreadyTransformed(DI->getType()))
3127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return DI;
31281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLocBuilder TLB;
31301bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
3131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLoc TL = DI->getTypeLoc();
3132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TLB.reserve(TL.getFullDataSize());
31331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
313443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, TL);
3135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3136a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return 0;
31371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3138a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
314343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3144a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  switch (T.getTypeLocClass()) {
3145a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
3146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \
3147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  case TypeLoc::CLASS: \
314843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
3150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
31529f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("unhandled type loc!");
3153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return QualType();
3154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types
3157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers
3158a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function
3159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but
3160a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients.
31611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
31621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3163a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
316443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               QualifiedTypeLoc T) {
3165a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers Quals = T.getType().getLocalQualifiers();
3166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
316743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3168a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3169577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
31701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3171a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Silently suppress qualifiers if the result type can't be qualified.
3172a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: this is the right thing for template instantiation, but
3173a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // probably not for other clients.
3174a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result->isFunctionType() || Result->isReferenceType())
3175a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return Result;
31761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3177f85e193739c953358c865005855253af4f68a497John McCall  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3178e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  // resulting type.
3179e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  if (Quals.hasObjCLifetime()) {
3180e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3181e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      Quals.removeObjCLifetime();
31824020caec546d221170072d2388b57d151cb26111Douglas Gregor    else if (Result.getObjCLifetime()) {
3183e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      // Objective-C ARC:
3184e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      //   A lifetime qualifier applied to a substituted template parameter
3185e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      //   overrides the lifetime qualifier from the template argument.
3186e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      if (const SubstTemplateTypeParmType *SubstTypeParam
3187e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3188e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        QualType Replacement = SubstTypeParam->getReplacementType();
3189e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Qualifiers Qs = Replacement.getQualifiers();
3190e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Qs.removeObjCLifetime();
3191e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Replacement
3192e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor          = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3193e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                             Qs);
3194e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Result = SemaRef.Context.getSubstTemplateTypeParmType(
3195e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                        SubstTypeParam->getReplacedParameter(),
3196e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                                              Replacement);
3197e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        TLB.TypeWasModifiedSafely(Result);
3198e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      } else {
31994020caec546d221170072d2388b57d151cb26111Douglas Gregor        // Otherwise, complain about the addition of a qualifier to an
32004020caec546d221170072d2388b57d151cb26111Douglas Gregor        // already-qualified type.
32014020caec546d221170072d2388b57d151cb26111Douglas Gregor        SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
3202b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis        SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
32034020caec546d221170072d2388b57d151cb26111Douglas Gregor          << Result << R;
32044020caec546d221170072d2388b57d151cb26111Douglas Gregor
3205e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Quals.removeObjCLifetime();
3206e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      }
3207e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    }
3208e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  }
32092865474261a608c7873b87ba4af110d17907896dJohn McCall  if (!Quals.empty()) {
32102865474261a608c7873b87ba4af110d17907896dJohn McCall    Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
32112865474261a608c7873b87ba4af110d17907896dJohn McCall    TLB.push<QualifiedTypeLoc>(Result);
32122865474261a608c7873b87ba4af110d17907896dJohn McCall    // No location information to preserve.
32132865474261a608c7873b87ba4af110d17907896dJohn McCall  }
3214a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
321843fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
3219b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc
3220b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
322143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
322243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
3223b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                   CXXScopeSpec &SS) {
3224b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  QualType T = TL.getType();
322543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
3226b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TL;
3227b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
322843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeLocBuilder TLB;
322943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result;
3230b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
323143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (isa<TemplateSpecializationType>(T)) {
3232b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateSpecializationTypeLoc SpecTL
3233b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = cast<TemplateSpecializationTypeLoc>(TL);
3234b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
323543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateName Template =
3236b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      getDerived().TransformTemplateName(SS,
3237b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getTypePtr()->getTemplateName(),
3238b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getTemplateNameLoc(),
323943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         ObjectType, UnqualLookup);
3240b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    if (Template.isNull())
3241b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return TypeLoc();
3242b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3243b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3244b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                              Template);
324543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else if (isa<DependentTemplateSpecializationType>(T)) {
3246b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
3247b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = cast<DependentTemplateSpecializationTypeLoc>(TL);
3248a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
3249b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateName Template
3250b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = getDerived().RebuildTemplateName(SS,
3251b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         *SpecTL.getTypePtr()->getIdentifier(),
3252b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getNameLoc(),
3253b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         ObjectType, UnqualLookup);
3254a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    if (Template.isNull())
3255b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return TypeLoc();
3256b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3257b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3258b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                                       SpecTL,
3259087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                     Template,
3260087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       SS);
326143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else {
326243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    // Nothing special needs to be done for these.
3263b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformType(TLB, TL);
326443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
3265b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3266b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  if (Result.isNull())
3267b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TypeLoc();
3268b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3269b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
327043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
327143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
3272c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived>
3273b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo *
3274b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3275c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   QualType ObjectType,
3276c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   NamedDecl *UnqualLookup,
3277c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   CXXScopeSpec &SS) {
3278c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // FIXME: Painfully copy-paste from the above!
3279c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3280b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  QualType T = TSInfo->getType();
3281c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (getDerived().AlreadyTransformed(T))
3282b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TSInfo;
3283c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3284c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  TypeLocBuilder TLB;
3285c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  QualType Result;
3286c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3287b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  TypeLoc TL = TSInfo->getTypeLoc();
3288c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (isa<TemplateSpecializationType>(T)) {
3289c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    TemplateSpecializationTypeLoc SpecTL
3290c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      = cast<TemplateSpecializationTypeLoc>(TL);
3291c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3292b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateName Template
3293b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    = getDerived().TransformTemplateName(SS,
3294fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getTypePtr()->getTemplateName(),
3295fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getTemplateNameLoc(),
3296c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                         ObjectType, UnqualLookup);
3297c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    if (Template.isNull())
3298b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return 0;
3299c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3300c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3301c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                              Template);
3302c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  } else if (isa<DependentTemplateSpecializationType>(T)) {
3303c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
3304c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      = cast<DependentTemplateSpecializationTypeLoc>(TL);
3305c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3306a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    TemplateName Template
3307fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = getDerived().RebuildTemplateName(SS,
33087c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                         *SpecTL.getTypePtr()->getIdentifier(),
3309fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getNameLoc(),
33107c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                         ObjectType, UnqualLookup);
3311a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    if (Template.isNull())
3312b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return 0;
3313a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
3314c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3315a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                                       SpecTL,
3316087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       Template,
3317087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       SS);
3318c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  } else {
3319c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    // Nothing special needs to be done for these.
3320c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformType(TLB, TL);
3321c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  }
3322c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3323c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (Result.isNull())
3324b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return 0;
3325c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3326b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3327c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor}
3328c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline
3330a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TyLoc NewT = TLB.push<TyLoc>(T.getType());
3332a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewT.setNameLoc(T.getNameLoc());
3333a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return T.getType();
3334a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3335a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3336a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3337a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
333843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      BuiltinTypeLoc T) {
3339ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3340ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  NewT.setBuiltinLoc(T.getBuiltinLoc());
3341ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (T.needsExtraLocalData())
3342ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3343ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  return T.getType();
3344577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3345577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
33461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
334843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ComplexTypeLoc T) {
3349a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: recurse?
3350a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, T);
3351a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
33521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3353a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3354a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
335543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      PointerTypeLoc TL) {
3356c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType PointeeType
3357c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
335892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (PointeeType.isNull())
335992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return QualType();
336092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
336192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  QualType Result = TL.getType();
3362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (PointeeType->getAs<ObjCObjectType>()) {
336392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // A dependent pointer type 'T *' has is being transformed such
336492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // that an Objective-C class type is being replaced for 'T'. The
336592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // resulting pointer type is an ObjCObjectPointerType, not a
336692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // PointerType.
3367c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3368c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3369c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3370c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NewT.setStarLoc(TL.getStarLoc());
337192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return Result;
337292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
337343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
337492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (getDerived().AlwaysRebuild() ||
337592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      PointeeType != TL.getPointeeLoc().getType()) {
337692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
337792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Result.isNull())
337892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      return QualType();
337992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
3380f85e193739c953358c865005855253af4f68a497John McCall
3381f85e193739c953358c865005855253af4f68a497John McCall  // Objective-C ARC can add lifetime qualifiers to the type that we're
3382f85e193739c953358c865005855253af4f68a497John McCall  // pointing to.
3383f85e193739c953358c865005855253af4f68a497John McCall  TLB.TypeWasModifiedSafely(Result->getPointeeType());
3384f85e193739c953358c865005855253af4f68a497John McCall
338592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
338692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3387c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Result;
3388577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3389577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
33901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
33911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3392a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
339343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  BlockPointerTypeLoc TL) {
3394db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  QualType PointeeType
3395c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
3396c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (PointeeType.isNull())
3397c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return QualType();
3398c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType Result = TL.getType();
3400c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (getDerived().AlwaysRebuild() ||
3401c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      PointeeType != TL.getPointeeLoc().getType()) {
3402c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Result = getDerived().RebuildBlockPointerType(PointeeType,
3403db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor                                                  TL.getSigilLoc());
3404db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor    if (Result.isNull())
3405db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor      return QualType();
3406db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  }
3407db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor
340839968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3409db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3410db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  return Result;
3411a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
34121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
341385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type.  Note that somewhat paradoxically we
341485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value
341585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type;  we only care if the type was *written* as an l-value type
341685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type.
341785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived>
341885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType
341985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
342043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ReferenceTypeLoc TL) {
342185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  const ReferenceType *T = TL.getTypePtr();
342285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
342385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // Note that this works with the pointee-as-written.
342485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
342585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (PointeeType.isNull())
342685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return QualType();
342785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
342885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType Result = TL.getType();
342985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (getDerived().AlwaysRebuild() ||
343085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      PointeeType != T->getPointeeTypeAsWritten()) {
343185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildReferenceType(PointeeType,
343285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               T->isSpelledAsLValue(),
343385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               TL.getSigilLoc());
343485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    if (Result.isNull())
343585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      return QualType();
343685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
343785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3438f85e193739c953358c865005855253af4f68a497John McCall  // Objective-C ARC can add lifetime qualifiers to the type that we're
3439f85e193739c953358c865005855253af4f68a497John McCall  // referring to.
3440f85e193739c953358c865005855253af4f68a497John McCall  TLB.TypeWasModifiedSafely(
3441f85e193739c953358c865005855253af4f68a497John McCall                     Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3442f85e193739c953358c865005855253af4f68a497John McCall
344385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // r-value references can be rebuilt as l-value references.
344485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  ReferenceTypeLoc NewTL;
344585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (isa<LValueReferenceType>(Result))
344685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
344785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  else
344885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
344985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
345085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
345185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  return Result;
345285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall}
345385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3454a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3455a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3456a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
345743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 LValueReferenceTypeLoc TL) {
345843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3459a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
34601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3461a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3462a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3463a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
346443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 RValueReferenceTypeLoc TL) {
346543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3468577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
34691eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
347143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   MemberPointerTypeLoc TL) {
3472a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3473577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (PointeeType.isNull())
3474577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3476b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3477b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo* NewClsTInfo = 0;
3478b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  if (OldClsTInfo) {
3479b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3480b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (!NewClsTInfo)
3481b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return QualType();
3482b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
3483b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
3484b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  const MemberPointerType *T = TL.getTypePtr();
3485b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  QualType OldClsType = QualType(T->getClass(), 0);
3486b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  QualType NewClsType;
3487b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  if (NewClsTInfo)
3488b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsType = NewClsTInfo->getType();
3489b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  else {
3490b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsType = getDerived().TransformType(OldClsType);
3491b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (NewClsType.isNull())
3492b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return QualType();
3493b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
34941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3496a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3497a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      PointeeType != T->getPointeeType() ||
3498b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      NewClsType != OldClsType) {
3499b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
350085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getStarLoc());
3501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3502a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3503a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3504577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3505a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3506a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
3507b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  NewTL.setClassTInfo(NewClsTInfo);
3508a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3509a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3510577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3511577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
35121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
35131eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3514a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
351543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ConstantArrayTypeLoc TL) {
3516f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ConstantArrayType *T = TL.getTypePtr();
3517a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3518577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3519577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3521a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3522a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3523a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3524a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildConstantArrayType(ElementType,
3525a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
3526a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSize(),
352785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             T->getIndexTypeCVRQualifiers(),
352885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3529a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3530a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3531a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3532c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3533a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3534a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
35361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3537a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = TL.getSizeExpr();
3538a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Size) {
3539f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3540a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3541a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3542a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
3543a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3544a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3545577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType(
3549a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                              TypeLocBuilder &TLB,
355043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              IncompleteArrayTypeLoc TL) {
3551f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const IncompleteArrayType *T = TL.getTypePtr();
3552a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3556a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3557a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3558a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3559a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildIncompleteArrayType(ElementType,
3560a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                     T->getSizeModifier(),
356185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                           T->getIndexTypeCVRQualifiers(),
356285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                     TL.getBracketsRange());
3563a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3564a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3565a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3566c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3568a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3569a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3570a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(0);
3571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3572a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3576a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3577a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
357843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   VariableArrayTypeLoc TL) {
3579f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VariableArrayType *T = TL.getTypePtr();
3580a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3584670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3585f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3586670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
358760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
3588a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
3589a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
3590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Size = SizeResult.take();
3593a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3594a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3595a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3596a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
3597a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
3598a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildVariableArrayType(ElementType,
3599a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
36009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Size,
3601a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                             T->getIndexTypeCVRQualifiers(),
360285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3603a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3604a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3606c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3607a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3608a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3609a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3610a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
36111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3612a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
36141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3616a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3617a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
361843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             DependentSizedArrayTypeLoc TL) {
3619f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedArrayType *T = TL.getTypePtr();
3620a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3624670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3625f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
36261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // Prefer the expression from the TypeLoc;  the other may have been uniqued.
36283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *origSize = TL.getSizeExpr();
36293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!origSize) origSize = T->getSizeExpr();
36303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
36313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExprResult sizeResult
36323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    = getDerived().TransformExpr(origSize);
36333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (sizeResult.isInvalid())
3634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *size = sizeResult.get();
3637a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3638a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3639a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3640a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
36413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      size != origSize) {
3642a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3643a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                         T->getSizeModifier(),
36443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                                                         size,
3645a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                T->getIndexTypeCVRQualifiers(),
364685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                        TL.getBracketsRange());
3647a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3648a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
36501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3651a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // We might have any sort of array type now, but fortunately they
3652a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // all have the same location layout.
3653a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3654a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3655a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
36563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  NewTL.setSizeExpr(size);
3657a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
36601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3663a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                      TypeLocBuilder &TLB,
366443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentSizedExtVectorTypeLoc TL) {
3665f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedExtVectorType *T = TL.getTypePtr();
3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: ext vector locs should be nested
3668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3670577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3672670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Vector sizes are not potentially evaluated contexts
3673f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3674670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
367560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3676577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (Size.isInvalid())
3677577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3679a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3680a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3681eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      ElementType != T->getElementType() ||
3682eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      Size.get() != T->getSizeExpr()) {
3683a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
36849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                             Size.take(),
3685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                         T->getAttributeLoc());
3686a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3687a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Result might be dependent or not.
3691a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (isa<DependentSizedExtVectorType>(Result)) {
3692a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    DependentSizedExtVectorTypeLoc NewTL
3693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  } else {
3696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3697a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3698a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3699a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3700a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
37021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3704a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
370543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     VectorTypeLoc TL) {
3706f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3707577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3708577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3709577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3710577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
371482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3715e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                            T->getVectorKind());
3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3717a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3719c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3720a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3721a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
37221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3723a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
37251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3727a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
372843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        ExtVectorTypeLoc TL) {
3729f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3730577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3731577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3732577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
37331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3734a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3735a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3736a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3737a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildExtVectorType(ElementType,
3738a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               T->getNumElements(),
3739a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               /*FIXME*/ SourceLocation());
3740a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3741a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3743c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3744a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3745a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
37461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3748577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3749577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
37501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
375121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl *
37526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3753fb44de956f27875def889482b5393475060392afJohn McCall                                                   int indexAdjustment,
37546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
375521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
37566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  TypeSourceInfo *NewDI = 0;
37576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37586a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
37596a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    // If we're substituting into a pack expansion type and we know the
37606a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc OldTL = OldDI->getTypeLoc();
37616a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
37626a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37636a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLocBuilder TLB;
37646a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc NewTL = OldDI->getTypeLoc();
37656a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TLB.reserve(NewTL.getFullDataSize());
37666a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37676a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    QualType Result = getDerived().TransformType(TLB,
37686a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                               OldExpansionTL.getPatternLoc());
37696a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
37706a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
37716a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37726a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    Result = RebuildPackExpansionType(Result,
37736a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                OldExpansionTL.getPatternLoc().getSourceRange(),
37746a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      OldExpansionTL.getEllipsisLoc(),
37756a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      NumExpansions);
37766a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
37776a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
37786a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37796a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc NewExpansionTL
37806a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      = TLB.push<PackExpansionTypeLoc>(Result);
37816a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
37826a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
37836a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  } else
37846a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = getDerived().TransformType(OldDI);
378521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (!NewDI)
378621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return 0;
378721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
3788fb44de956f27875def889482b5393475060392afJohn McCall  if (NewDI == OldDI && indexAdjustment == 0)
378921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return OldParm;
3790fb44de956f27875def889482b5393475060392afJohn McCall
3791fb44de956f27875def889482b5393475060392afJohn McCall  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3792fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getDeclContext(),
3793fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getInnerLocStart(),
3794fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getLocation(),
3795fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getIdentifier(),
3796fb44de956f27875def889482b5393475060392afJohn McCall                                             NewDI->getType(),
3797fb44de956f27875def889482b5393475060392afJohn McCall                                             NewDI,
3798fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getStorageClass(),
3799fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getStorageClassAsWritten(),
3800fb44de956f27875def889482b5393475060392afJohn McCall                                             /* DefArg */ NULL);
3801fb44de956f27875def889482b5393475060392afJohn McCall  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3802fb44de956f27875def889482b5393475060392afJohn McCall                        OldParm->getFunctionScopeIndex() + indexAdjustment);
3803fb44de956f27875def889482b5393475060392afJohn McCall  return newParm;
380421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
380521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
380621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
380721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>::
3808a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  TransformFunctionTypeParams(SourceLocation Loc,
3809a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              ParmVarDecl **Params, unsigned NumParams,
3810a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              const QualType *ParamTypes,
3811a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              llvm::SmallVectorImpl<QualType> &OutParamTypes,
3812a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3813fb44de956f27875def889482b5393475060392afJohn McCall  int indexAdjustment = 0;
3814fb44de956f27875def889482b5393475060392afJohn McCall
3815a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  for (unsigned i = 0; i != NumParams; ++i) {
3816a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (ParmVarDecl *OldParm = Params[i]) {
3817fb44de956f27875def889482b5393475060392afJohn McCall      assert(OldParm->getFunctionScopeIndex() == i);
3818fb44de956f27875def889482b5393475060392afJohn McCall
38196a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      llvm::Optional<unsigned> NumExpansions;
3820406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      ParmVarDecl *NewParm = 0;
3821603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (OldParm->isParameterPack()) {
3822603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We have a function parameter pack that may need to be expanded.
3823603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3824603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3825603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Find the parameter packs that could be expanded.
3826c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3827c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3828c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc Pattern = ExpansionTL.getPatternLoc();
3829c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3830406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3831406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor
3832603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Determine whether we should expand the parameter packs.
3833603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        bool ShouldExpand = false;
3834d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor        bool RetainExpansion = false;
38356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        llvm::Optional<unsigned> OrigNumExpansions
38366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor          = ExpansionTL.getTypePtr()->getNumExpansions();
38376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        NumExpansions = OrigNumExpansions;
3838c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3839c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor                                                 Pattern.getSourceRange(),
3840603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.data(),
3841603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.size(),
3842d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 ShouldExpand,
3843d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 RetainExpansion,
3844d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 NumExpansions)) {
3845603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          return true;
3846603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3847603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3848603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        if (ShouldExpand) {
3849603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // Expand the function parameter pack into multiple, separate
3850603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // parameters.
385112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor          getDerived().ExpandingFunctionParameterPack(OldParm);
3852cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          for (unsigned I = 0; I != *NumExpansions; ++I) {
3853603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3854603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            ParmVarDecl *NewParm
38556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
3856fb44de956f27875def889482b5393475060392afJohn McCall                                                        indexAdjustment++,
38576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3858603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            if (!NewParm)
3859603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor              return true;
3860603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3861a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            OutParamTypes.push_back(NewParm->getType());
3862a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            if (PVars)
3863a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor              PVars->push_back(NewParm);
3864603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          }
3865d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3866d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // If we're supposed to retain a pack expansion, do so by temporarily
3867d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // forgetting the partially-substituted parameter pack.
3868d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          if (RetainExpansion) {
3869d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3870d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ParmVarDecl *NewParm
38716a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
3872fb44de956f27875def889482b5393475060392afJohn McCall                                                        indexAdjustment++,
38736a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3874d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (!NewParm)
3875d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              return true;
3876d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3877d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            OutParamTypes.push_back(NewParm->getType());
3878d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (PVars)
3879d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              PVars->push_back(NewParm);
3880d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          }
3881d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3882fb44de956f27875def889482b5393475060392afJohn McCall          // The next parameter should have the same adjustment as the
3883fb44de956f27875def889482b5393475060392afJohn McCall          // last thing we pushed, but we post-incremented indexAdjustment
3884fb44de956f27875def889482b5393475060392afJohn McCall          // on every push.  Also, if we push nothing, the adjustment should
3885fb44de956f27875def889482b5393475060392afJohn McCall          // go down by one.
3886fb44de956f27875def889482b5393475060392afJohn McCall          indexAdjustment--;
3887fb44de956f27875def889482b5393475060392afJohn McCall
3888603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // We're done with the pack expansion.
3889603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          continue;
3890603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3891603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3892603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We'll substitute the parameter now without expanding the pack
3893603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // expansion.
3894406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3895406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3896fb44de956f27875def889482b5393475060392afJohn McCall                                                          indexAdjustment,
3897406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor                                                          NumExpansions);
3898406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      } else {
3899406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3900fb44de956f27875def889482b5393475060392afJohn McCall                                                          indexAdjustment,
3901406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor                                                  llvm::Optional<unsigned>());
3902603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3903406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor
390421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      if (!NewParm)
390521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3906603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3907a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      OutParamTypes.push_back(NewParm->getType());
3908a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (PVars)
3909a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor        PVars->push_back(NewParm);
3910603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      continue;
3911603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    }
3912a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3913a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // Deal with the possibility that we don't have a parameter
3914a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // declaration for this parameter.
3915a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    QualType OldType = ParamTypes[i];
3916603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    bool IsPackExpansion = false;
3917cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    llvm::Optional<unsigned> NumExpansions;
3918406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor    QualType NewType;
3919603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (const PackExpansionType *Expansion
3920603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                       = dyn_cast<PackExpansionType>(OldType)) {
3921603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We have a function parameter pack that may need to be expanded.
3922603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      QualType Pattern = Expansion->getPattern();
3923603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3924603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3925603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3926603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // Determine whether we should expand the parameter packs.
3927603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      bool ShouldExpand = false;
3928d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3929a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
3930603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.data(),
3931603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.size(),
3932d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               ShouldExpand,
3933d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3934d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions)) {
393521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3936603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3937603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3938603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (ShouldExpand) {
3939603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Expand the function parameter pack into multiple, separate
3940603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // parameters.
3941cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        for (unsigned I = 0; I != *NumExpansions; ++I) {
3942603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3943603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          QualType NewType = getDerived().TransformType(Pattern);
3944603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          if (NewType.isNull())
3945603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            return true;
3946603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3947a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          OutParamTypes.push_back(NewType);
3948a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          if (PVars)
3949a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            PVars->push_back(0);
3950603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3951603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3952603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We're done with the pack expansion.
3953603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        continue;
3954603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3955603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
39563cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
39573cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
39583cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
39593cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
39603cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        QualType NewType = getDerived().TransformType(Pattern);
39613cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (NewType.isNull())
39623cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
39633cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
39643cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        OutParamTypes.push_back(NewType);
39653cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (PVars)
39663cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          PVars->push_back(0);
39673cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
3968d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3969603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We'll substitute the parameter now without expanding the pack
3970603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // expansion.
3971603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      OldType = Expansion->getPattern();
3972603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      IsPackExpansion = true;
3973406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3974406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      NewType = getDerived().TransformType(OldType);
3975406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor    } else {
3976406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      NewType = getDerived().TransformType(OldType);
3977a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    }
3978603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3979603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (NewType.isNull())
3980603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      return true;
39811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3982603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (IsPackExpansion)
3983cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NewType = getSema().Context.getPackExpansionType(NewType,
3984cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                       NumExpansions);
3985603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3986a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    OutParamTypes.push_back(NewType);
3987a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (PVars)
3988a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      PVars->push_back(0);
3989577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
39901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3991fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG
3992fb44de956f27875def889482b5393475060392afJohn McCall  if (PVars) {
3993fb44de956f27875def889482b5393475060392afJohn McCall    for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3994fb44de956f27875def889482b5393475060392afJohn McCall      if (ParmVarDecl *parm = (*PVars)[i])
3995fb44de956f27875def889482b5393475060392afJohn McCall        assert(parm->getFunctionScopeIndex() == i);
3996603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor  }
3997fb44de956f27875def889482b5393475060392afJohn McCall#endif
3998fb44de956f27875def889482b5393475060392afJohn McCall
3999fb44de956f27875def889482b5393475060392afJohn McCall  return false;
4000fb44de956f27875def889482b5393475060392afJohn McCall}
400121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
400221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
400321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType
400421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
400543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   FunctionProtoTypeLoc TL) {
40067e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // Transform the parameters and return type.
40077e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
40087e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // We instantiate in source order, with the return type first followed by
40097e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // the parameters, because users tend to expect this (even if they shouldn't
40107e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // rely on it!).
40117e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
4012dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // When the function has a trailing return type, we instantiate the
4013dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // parameters before the return type,  since the return type can then refer
4014dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // to the parameters themselves (via decltype, sizeof, etc.).
4015dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
401621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<QualType, 4> ParamTypes;
401721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
4018f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionProtoType *T = TL.getTypePtr();
40197e010a04fef171049291d8cb3047f118566da090Douglas Gregor
4020dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  QualType ResultType;
4021dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4022dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  if (TL.getTrailingReturn()) {
4023a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4024a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
4025a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
4026a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
4027a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
4028dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4029dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4030dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4031dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
4032dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4033dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
4034dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  else {
4035dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4036dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
4037dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4038dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4039a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4040a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
4041a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
4042a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
4043a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
4044dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4045dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
4046dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4047a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4048a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4049a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType() ||
4050bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor      T->getNumArgs() != ParamTypes.size() ||
4051a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4052a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionProtoType(ResultType,
4053a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.data(),
4054a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.size(),
4055a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->isVariadic(),
4056fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getTypeQuals(),
4057c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                   T->getRefQualifier(),
4058fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getExtInfo());
4059a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4060a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4061a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
40621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4063a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4064796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4065796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4066dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(TL.getTrailingReturn());
4067a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4068a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setArg(i, ParamDecls[i]);
4069a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4070a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4071577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
40721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4073577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4074577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4075a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                 TypeLocBuilder &TLB,
407643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 FunctionNoProtoTypeLoc TL) {
4077f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionNoProtoType *T = TL.getTypePtr();
4078a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4079a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (ResultType.isNull())
4080a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4081a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4082a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4083a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4084a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType())
4085a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4086a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4087a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4088796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4089796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4090dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(false);
4091a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4092a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4093577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
40941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4095ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType
4096ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
409743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 UnresolvedUsingTypeLoc TL) {
4098f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const UnresolvedUsingType *T = TL.getTypePtr();
40997c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4100ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (!D)
4101ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return QualType();
4102ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4103ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType Result = TL.getType();
4104ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4105ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Result = getDerived().RebuildUnresolvedUsingType(D);
4106ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    if (Result.isNull())
4107ed97649e9574b9d854fa4d6109c9333ae0993554John McCall      return QualType();
4108ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
4109ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4110ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // We might get an arbitrary type spec type back.  We should at
4111ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // least always get a type spec type, though.
4112ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4113ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  NewTL.setNameLoc(TL.getNameLoc());
4114ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4115ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return Result;
4116ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
4117ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4119a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
412043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypedefTypeLoc TL) {
4121f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypedefType *T = TL.getTypePtr();
4122162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *Typedef
4123162e1c1b487352434552147967c3dd296ebee2f7Richard Smith    = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4124162e1c1b487352434552147967c3dd296ebee2f7Richard Smith                                                               T->getDecl()));
4125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Typedef)
4126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
41271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4128a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Typedef != T->getDecl()) {
4131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildTypedefType(Typedef);
4132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4136a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4137a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
41381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4139a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
414443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypeOfExprTypeLoc TL) {
4145670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // typeof expressions are not potentially evaluated contexts
4146f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
41471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
414860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
4150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
4151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4154cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      E.get() != TL.getUnderlyingExpr()) {
41552a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4158577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
41601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4161a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4162cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
4163cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
4164cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
4165a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4167577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4170a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
417143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     TypeOfTypeLoc TL) {
4172cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4173cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4174cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (!New_Under_TI)
4175577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
41761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4177a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4178cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4179cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4180a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4181a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4182a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
41831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4184a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4185cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
4186cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
4187cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
4188cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setUnderlyingTInfo(New_Under_TI);
4189a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4190a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
419543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                       DecltypeTypeLoc TL) {
4196f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DecltypeType *T = TL.getTypePtr();
4197a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4198670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // decltype expressions are not potentially evaluated contexts
4199f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
42001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
420160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4202577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
4203577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
42041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4206a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      E.get() != T->getUnderlyingExpr()) {
42082a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4211577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
4213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4214a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
42161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4218577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4219577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4220577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4221ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType(
4222ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                            TypeLocBuilder &TLB,
4223ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                     UnaryTransformTypeLoc TL) {
4224ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType Result = TL.getType();
4225ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  if (Result->isDependentType()) {
4226ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    const UnaryTransformType *T = TL.getTypePtr();
4227ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    QualType NewBase =
4228ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4229ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    Result = getDerived().RebuildUnaryTransformType(NewBase,
4230ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    T->getUTTKind(),
4231ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    TL.getKWLoc());
4232ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    if (Result.isNull())
4233ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      return QualType();
4234ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
4235ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
4236ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4237ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setKWLoc(TL.getKWLoc());
4238ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setParensRange(TL.getParensRange());
4239ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4240ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  return Result;
4241ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
4242ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
4243ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived>
424434b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
424534b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                   AutoTypeLoc TL) {
424634b41d939a1328f484511c6002ba2456db879a29Richard Smith  const AutoType *T = TL.getTypePtr();
424734b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType OldDeduced = T->getDeducedType();
424834b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType NewDeduced;
424934b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (!OldDeduced.isNull()) {
425034b41d939a1328f484511c6002ba2456db879a29Richard Smith    NewDeduced = getDerived().TransformType(OldDeduced);
425134b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (NewDeduced.isNull())
425234b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
425334b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
425434b41d939a1328f484511c6002ba2456db879a29Richard Smith
425534b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType Result = TL.getType();
425634b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
425734b41d939a1328f484511c6002ba2456db879a29Richard Smith    Result = getDerived().RebuildAutoType(NewDeduced);
425834b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (Result.isNull())
425934b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
426034b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
426134b41d939a1328f484511c6002ba2456db879a29Richard Smith
426234b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
426334b41d939a1328f484511c6002ba2456db879a29Richard Smith  NewTL.setNameLoc(TL.getNameLoc());
426434b41d939a1328f484511c6002ba2456db879a29Richard Smith
426534b41d939a1328f484511c6002ba2456db879a29Richard Smith  return Result;
426634b41d939a1328f484511c6002ba2456db879a29Richard Smith}
426734b41d939a1328f484511c6002ba2456db879a29Richard Smith
426834b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived>
4269a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
427043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     RecordTypeLoc TL) {
4271f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const RecordType *T = TL.getTypePtr();
4272577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  RecordDecl *Record
42737c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
42747c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                          T->getDecl()));
4275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Record)
4276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
42771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Record != T->getDecl()) {
4281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildRecordType(Record);
4282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4283a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
42851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
4288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4290577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
42911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
429443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   EnumTypeLoc TL) {
4295f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const EnumType *T = TL.getTypePtr();
4296577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  EnumDecl *Enum
42977c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
42987c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                        T->getDecl()));
4299577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Enum)
4300577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
43011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4302a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4303a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4304a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Enum != T->getDecl()) {
4305a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildEnumType(Enum);
4306a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4307a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4309a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4310a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4311a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
43121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4313a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4314577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43157da2431c23ef1ee8acb114e39692246e1801afc2John McCall
43163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived>
43173cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType(
43183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         TypeLocBuilder &TLB,
431943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         InjectedClassNameTypeLoc TL) {
43203cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
43213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                       TL.getTypePtr()->getDecl());
43223cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  if (!D) return QualType();
43233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
43243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
43253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
43263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  return T;
43273cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
43283cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
4329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4330577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                TypeLocBuilder &TLB,
433243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TemplateTypeParmTypeLoc TL) {
4333a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
4334577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4335577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
43361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
433749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4338a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                         TypeLocBuilder &TLB,
433943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         SubstTemplateTypeParmTypeLoc TL) {
43400b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  const SubstTemplateTypeParmType *T = TL.getTypePtr();
43410b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43420b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Substitute into the replacement type, which itself might involve something
43430b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // that needs to be transformed. This only tends to occur with default
43440b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // template arguments of template template parameters.
43450b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
43460b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  QualType Replacement = getDerived().TransformType(T->getReplacementType());
43470b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  if (Replacement.isNull())
43480b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    return QualType();
43490b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43500b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Always canonicalize the replacement type.
43510b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  Replacement = SemaRef.Context.getCanonicalType(Replacement);
43520b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  QualType Result
43530b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
43540b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor                                                   Replacement);
43550b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43560b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Propagate type-source information.
43570b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  SubstTemplateTypeParmTypeLoc NewTL
43580b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
43590b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  NewTL.setNameLoc(TL.getNameLoc());
43600b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  return Result;
43610b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
436249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
436349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
436449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived>
4365c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4366c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          TypeLocBuilder &TLB,
4367c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          SubstTemplateTypeParmPackTypeLoc TL) {
4368c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  return TransformTypeSpecType(TLB, TL);
4369c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}
4370c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
4371c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived>
4372833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
437343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        TypeLocBuilder &TLB,
437443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                           TemplateSpecializationTypeLoc TL) {
437543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
4376828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
43771d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  // The nested-name-specifier never matters in a TemplateSpecializationType,
43781d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  // because we can't have a dependent nested-name-specifier anyway.
43791d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  CXXScopeSpec SS;
438043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TemplateName Template
43811d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    = getDerived().TransformTemplateName(SS, T->getTemplateName(),
43821d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor                                         TL.getTemplateNameLoc());
438343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Template.isNull())
438443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4385833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
438643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4387dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor}
438843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
43897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace {
43907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \brief Simple iterator that traverses the template arguments in a
43917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// container that provides a \c getArgLoc() member function.
43927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
43937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// This iterator is intended to be used with the iterator form of
43947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \c TreeTransform<Derived>::TransformTemplateArguments().
43957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename ArgLocContainer>
43967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class TemplateArgumentLocContainerIterator {
43977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgLocContainer *Container;
43987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    unsigned Index;
43997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
44017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc value_type;
44027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc reference;
44037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef int difference_type;
44047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef std::input_iterator_tag iterator_category;
44057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    class pointer {
44077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLoc Arg;
44087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    public:
44107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
44117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      const TemplateArgumentLoc *operator->() const {
44137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return &Arg;
44147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      }
44157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    };
44167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator() {}
44197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
44217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                 unsigned Index)
44227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      : Container(&Container), Index(Index) { }
44237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator &operator++() {
44257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++Index;
44267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return *this;
44277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator operator++(int) {
44307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLocContainerIterator Old(*this);
44317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++(*this);
44327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Old;
44337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc operator*() const {
44367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Container->getArgLoc(Index);
44377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    pointer operator->() const {
44407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return pointer(Container->getArgLoc(Index));
44417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4444f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
44457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return X.Container == Y.Container && X.Index == Y.Index;
44467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4449f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
44507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return !(X == Y);
44517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
44537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}
44547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
445643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived>
4457577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4458833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                        TypeLocBuilder &TLB,
4459833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                           TemplateSpecializationTypeLoc TL,
446043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TemplateName Template) {
4461d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo NewTemplateArgs;
4462d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4463d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
44647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
44657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgIterator;
44667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
44677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
44687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              NewTemplateArgs))
44697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    return QualType();
44701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4471833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  // FIXME: maybe don't rebuild if all the template arguments are the same.
4472833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
4473833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType Result =
4474833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getDerived().RebuildTemplateSpecializationType(Template,
4475833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                   TL.getTemplateNameLoc(),
4476d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NewTemplateArgs);
44771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4478833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  if (!Result.isNull()) {
44793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // Specializations of template template parameters are represented as
44803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // TemplateSpecializationTypes, and substitution of type alias templates
44813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // within a dependent context can transform them into
44823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // DependentTemplateSpecializationTypes.
44833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    if (isa<DependentTemplateSpecializationType>(Result)) {
44843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      DependentTemplateSpecializationTypeLoc NewTL
44853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
44863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setKeywordLoc(TL.getTemplateNameLoc());
44873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setQualifierLoc(NestedNameSpecifierLoc());
44883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setNameLoc(TL.getTemplateNameLoc());
44893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setLAngleLoc(TL.getLAngleLoc());
44903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setRAngleLoc(TL.getRAngleLoc());
44913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
44923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
44933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      return Result;
44943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    }
44953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
4496833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TemplateSpecializationTypeLoc NewTL
4497833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4498833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4499833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setLAngleLoc(TL.getLAngleLoc());
4500833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setRAngleLoc(TL.getRAngleLoc());
4501833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4502833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4503833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
45041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4505833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return Result;
4506577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
45071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4508a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived>
4509a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4510a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                     TypeLocBuilder &TLB,
4511a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                     DependentTemplateSpecializationTypeLoc TL,
4512087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                     TemplateName Template,
4513087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                     CXXScopeSpec &SS) {
4514a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  TemplateArgumentListInfo NewTemplateArgs;
4515a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4516a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4517a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  typedef TemplateArgumentLocContainerIterator<
4518a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor            DependentTemplateSpecializationTypeLoc> ArgIterator;
4519a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4520a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
4521a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                              NewTemplateArgs))
4522a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    return QualType();
4523a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4524a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  // FIXME: maybe don't rebuild if all the template arguments are the same.
4525a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4526a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4527a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    QualType Result
4528a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = getSema().Context.getDependentTemplateSpecializationType(
4529a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                TL.getTypePtr()->getKeyword(),
4530a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                         DTN->getQualifier(),
4531a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                         DTN->getIdentifier(),
4532a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                               NewTemplateArgs);
4533a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4534a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    DependentTemplateSpecializationTypeLoc NewTL
4535a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4536a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setKeywordLoc(TL.getKeywordLoc());
453794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
453894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
4539a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setNameLoc(TL.getNameLoc());
4540a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setLAngleLoc(TL.getLAngleLoc());
4541a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setRAngleLoc(TL.getRAngleLoc());
4542a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4543a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4544a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    return Result;
4545a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4546a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4547a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  QualType Result
4548a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    = getDerived().RebuildTemplateSpecializationType(Template,
4549a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                     TL.getNameLoc(),
4550a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                     NewTemplateArgs);
4551a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4552a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (!Result.isNull()) {
4553a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    /// FIXME: Wrap this in an elaborated-type-specifier?
4554a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    TemplateSpecializationTypeLoc NewTL
4555a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4556a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setTemplateNameLoc(TL.getNameLoc());
4557a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setLAngleLoc(TL.getLAngleLoc());
4558a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setRAngleLoc(TL.getRAngleLoc());
4559a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4560a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4561a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4562a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4563a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  return Result;
4564a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor}
4565a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
45661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4568465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
456943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ElaboratedTypeLoc TL) {
4570f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ElaboratedType *T = TL.getTypePtr();
4571465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
45729e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
4573465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // NOTE: the qualifier in an ElaboratedType is optional.
45749e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  if (TL.getQualifierLoc()) {
45759e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    QualifierLoc
45769e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
45779e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    if (!QualifierLoc)
4578465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      return QualType();
4579465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
45801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
458143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
458243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (NamedT.isNull())
458343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4584a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar
45853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  // C++0x [dcl.type.elab]p2:
45863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   If the identifier resolves to a typedef-name or the simple-template-id
45873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   resolves to an alias template specialization, the
45883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   elaborated-type-specifier is ill-formed.
45891804174e1591bf59118f317775b48edd0382c3f0Richard Smith  if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
45901804174e1591bf59118f317775b48edd0382c3f0Richard Smith    if (const TemplateSpecializationType *TST =
45911804174e1591bf59118f317775b48edd0382c3f0Richard Smith          NamedT->getAs<TemplateSpecializationType>()) {
45921804174e1591bf59118f317775b48edd0382c3f0Richard Smith      TemplateName Template = TST->getTemplateName();
45931804174e1591bf59118f317775b48edd0382c3f0Richard Smith      if (TypeAliasTemplateDecl *TAT =
45941804174e1591bf59118f317775b48edd0382c3f0Richard Smith          dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
45951804174e1591bf59118f317775b48edd0382c3f0Richard Smith        SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
45961804174e1591bf59118f317775b48edd0382c3f0Richard Smith                     diag::err_tag_reference_non_tag) << 4;
45971804174e1591bf59118f317775b48edd0382c3f0Richard Smith        SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
45981804174e1591bf59118f317775b48edd0382c3f0Richard Smith      }
45993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    }
46003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  }
46013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
4602a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4603a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
46049e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      QualifierLoc != TL.getQualifierLoc() ||
4605e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      NamedT != T->getNamedType()) {
460621e413fe6305a198564d436ac515497716c47844John McCall    Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
46079e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                                T->getKeyword(),
46089e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                                QualifierLoc, NamedT);
4609a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4610a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4611a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4613465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4614e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setKeywordLoc(TL.getKeywordLoc());
46159e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NewTL.setQualifierLoc(QualifierLoc);
4616a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
46181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
46209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType(
46219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                TypeLocBuilder &TLB,
46229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                AttributedTypeLoc TL) {
46239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  const AttributedType *oldType = TL.getTypePtr();
46249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
46259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (modifiedType.isNull())
46269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return QualType();
46279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType result = TL.getType();
46299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // FIXME: dependent operand expressions?
46319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (getDerived().AlwaysRebuild() ||
46329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      modifiedType != oldType->getModifiedType()) {
46339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // TODO: this is really lame; we should really be rebuilding the
46349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // equivalent type from first principles.
46359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    QualType equivalentType
46369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      = getDerived().TransformType(oldType->getEquivalentType());
46379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (equivalentType.isNull())
46389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      return QualType();
46399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
46409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               modifiedType,
46419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               equivalentType);
46429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
46439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
46459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  newTL.setAttrNameLoc(TL.getAttrNameLoc());
46469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrOperand())
46479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
46489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrExprOperand())
46499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrExprOperand(TL.getAttrExprOperand());
46509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  else if (TL.hasAttrEnumOperand())
46519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
46529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  return result;
46549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
46559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived>
4657075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType
4658075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4659075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                                           ParenTypeLoc TL) {
4660075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4661075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (Inner.isNull())
4662075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType();
4663075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4664075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Result = TL.getType();
4665075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (getDerived().AlwaysRebuild() ||
4666075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      Inner != TL.getInnerLoc().getType()) {
4667075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Result = getDerived().RebuildParenType(Inner);
4668075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    if (Result.isNull())
4669075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      return QualType();
4670075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
4671075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4672075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4673075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setLParenLoc(TL.getLParenLoc());
4674075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setRParenLoc(TL.getRParenLoc());
4675075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  return Result;
4676075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
4677075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4678075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived>
46794714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
468043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      DependentNameTypeLoc TL) {
4681f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentNameType *T = TL.getTypePtr();
4682833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
46832494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  NestedNameSpecifierLoc QualifierLoc
46842494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
46852494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  if (!QualifierLoc)
4686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
46871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
468833500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType Result
46892494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    = getDerived().RebuildDependentNameType(T->getKeyword(),
469033500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getKeywordLoc(),
46912494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            QualifierLoc,
46922494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            T->getIdentifier(),
469333500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getNameLoc());
4694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
4695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4697e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4698e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    QualType NamedT = ElabT->getNamedType();
469933500955d731c73717af52088b7fc0e7a85681e7John McCall    TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
470033500955d731c73717af52088b7fc0e7a85681e7John McCall
4701e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4702e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
47039e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
470433500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
4705e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4706e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
47072494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
4708e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setNameLoc(TL.getNameLoc());
4709e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
4710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4711577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
47121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
471433500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>::
471533500955d731c73717af52088b7fc0e7a85681e7John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
471643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL) {
471794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
471894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (TL.getQualifierLoc()) {
471994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualifierLoc
472094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
472194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (!QualifierLoc)
4722a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      return QualType();
4723a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4724a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
472543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived()
472694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor           .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
472743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
472843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
472943fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
473043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::
473194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
473294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                   DependentTemplateSpecializationTypeLoc TL,
473394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                       NestedNameSpecifierLoc QualifierLoc) {
473494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  const DependentTemplateSpecializationType *T = TL.getTypePtr();
473594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
473694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  TemplateArgumentListInfo NewTemplateArgs;
473794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
473894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
473994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
474094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  typedef TemplateArgumentLocContainerIterator<
474194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  DependentTemplateSpecializationTypeLoc> ArgIterator;
474294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
474394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
474494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                              NewTemplateArgs))
474594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return QualType();
474694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
474794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  QualType Result
474894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
474994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                              QualifierLoc,
475094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            T->getIdentifier(),
475194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            TL.getNameLoc(),
475294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            NewTemplateArgs);
475394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (Result.isNull())
475494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return QualType();
475594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
475694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
475794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualType NamedT = ElabT->getNamedType();
475894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
475994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Copy information relevant to the template specialization.
476094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    TemplateSpecializationTypeLoc NamedTL
47610a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4762a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    NamedTL.setTemplateNameLoc(TL.getNameLoc());
476394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NamedTL.setLAngleLoc(TL.getLAngleLoc());
476494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NamedTL.setRAngleLoc(TL.getRAngleLoc());
4765944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47660a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
476794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
476894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Copy information relevant to the elaborated type.
476994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
477094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setKeywordLoc(TL.getKeywordLoc());
477194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
47720a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor  } else if (isa<DependentTemplateSpecializationType>(Result)) {
47730a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
47740a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4775944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    SpecTL.setKeywordLoc(TL.getKeywordLoc());
47760a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setQualifierLoc(QualifierLoc);
4777a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    SpecTL.setNameLoc(TL.getNameLoc());
47780a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setLAngleLoc(TL.getLAngleLoc());
47790a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setRAngleLoc(TL.getRAngleLoc());
4780944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47810a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
478294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  } else {
47830a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    TemplateSpecializationTypeLoc SpecTL
47840a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4785a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    SpecTL.setTemplateNameLoc(TL.getNameLoc());
47860a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setLAngleLoc(TL.getLAngleLoc());
47870a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setRAngleLoc(TL.getRAngleLoc());
4788944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47890a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
479094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  }
479194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  return Result;
479294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor}
479394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
479494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived>
47957536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
47967536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor                                                      PackExpansionTypeLoc TL) {
47972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Pattern
47982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    = getDerived().TransformType(TLB, TL.getPatternLoc());
47992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (Pattern.isNull())
48002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    return QualType();
48012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
48022fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Result = TL.getType();
48032fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (getDerived().AlwaysRebuild() ||
48042fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      Pattern != TL.getPatternLoc().getType()) {
48052fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    Result = getDerived().RebuildPackExpansionType(Pattern,
48062fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                           TL.getPatternLoc().getSourceRange(),
4807cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                   TL.getEllipsisLoc(),
4808cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           TL.getTypePtr()->getNumExpansions());
48092fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    if (Result.isNull())
48102fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      return QualType();
48112fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
48122fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
48132fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
48142fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  NewT.setEllipsisLoc(TL.getEllipsisLoc());
48152fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  return Result;
48167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}
48177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
48187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived>
4819a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4820a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
482143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ObjCInterfaceTypeLoc TL) {
4822ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCInterfaceType is never dependent.
4823c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4824c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return TL.getType();
4825c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4826c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4827c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived>
4828c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType
4829c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
483043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjCObjectTypeLoc TL) {
4831c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // ObjCObjectType is never dependent.
4832c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4833ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
4834577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
48351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4837a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4838a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
483943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ObjCObjectPointerTypeLoc TL) {
4840ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCObjectPointerType is never dependent.
4841c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4842ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
484324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}
484424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis
4845577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
484643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation
484743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
484843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
484960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
48513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
485243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
485343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
485443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
485560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
485643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
485743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().TransformCompoundStmt(S, false);
485843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
485943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
486043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
486160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
486343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              bool IsStmtExpr) {
48647114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  bool SubStmtInvalid = false;
486543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool SubStmtChanged = false;
4866ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Statements(getSema());
486743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
486843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       B != BEnd; ++B) {
486960d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Result = getDerived().TransformStmt(*B);
48707114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    if (Result.isInvalid()) {
48717114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Immediately fail if this was a DeclStmt, since it's very
48727114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // likely that this will cause problems for future statements.
48737114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      if (isa<DeclStmt>(*B))
48747114cbab7eb6e8b714eb22f014327daf2c741c08John McCall        return StmtError();
48757114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
48767114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Otherwise, just keep processing substatements and fail later.
48777114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      SubStmtInvalid = true;
48787114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      continue;
48797114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
48801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
488143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    SubStmtChanged = SubStmtChanged || Result.get() != *B;
488243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Statements.push_back(Result.takeAs<Stmt>());
488343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
48841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48857114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  if (SubStmtInvalid)
48867114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    return StmtError();
48877114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
488843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
488943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !SubStmtChanged)
48903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
489143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
489243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
489343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          move_arg(Statements),
489443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          S->getRBracLoc(),
489543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          IsStmtExpr);
489643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
48971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
489843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
489960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49001eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
490160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS, RHS;
4902264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  {
4903264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // The case value expressions are not potentially evaluated.
4904f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
49051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4906264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the left-hand case value.
4907264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    LHS = getDerived().TransformExpr(S->getLHS());
4908264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (LHS.isInvalid())
4909f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
49101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4911264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the right-hand case value (for the GNU case-range extension).
4912264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    RHS = getDerived().TransformExpr(S->getRHS());
4913264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (RHS.isInvalid())
4914f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4915264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  }
49161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
491743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Build the case statement.
491843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Case statements are always rebuilt so that they will attached to their
491943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transformed switch statement.
492060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
49219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       LHS.get(),
492243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getEllipsisLoc(),
49239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       RHS.get(),
492443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getColonLoc());
492543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Case.isInvalid())
4926f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
492843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the case
492960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
493043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4931f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
493343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Attach the body to the case statement
49349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
493543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
493643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
493743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
493860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49391eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
494043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the default case
494160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
494243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4943f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
494543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Default statements are always rebuilt
494643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
49479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubStmt.get());
494843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
495043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
495160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49521eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
495360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
495443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4955f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
495757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
495857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getDecl());
495957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
496057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
496157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
496257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
496343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // FIXME: Pass the real colon location in.
4964ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  return getDerived().RebuildLabelStmt(S->getIdentLoc(),
496557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       cast<LabelDecl>(LD), SourceLocation(),
496657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       SubStmt.get());
496743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
497060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49711eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
497243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
497360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
49748cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  VarDecl *ConditionVar = 0;
49758cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  if (S->getConditionVariable()) {
4976c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
49778cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor      = cast_or_null<VarDecl>(
4978aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4979aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4980aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
49818cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    if (!ConditionVar)
4982f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
498399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
49848cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4985c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
498699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4987f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4988eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
4989eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor    // Convert the condition to a boolean value.
4990afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
49918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
49928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
4993afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
4994f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4995eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
49969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
4997afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
499899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
4999c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
50019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5002f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5003eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
500443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "then" branch.
500560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Then = getDerived().TransformStmt(S->getThen());
500643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Then.isInvalid())
5007f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
500943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "else" branch.
501060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Else = getDerived().TransformStmt(S->getElse());
501143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Else.isInvalid())
5012f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
501443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
50159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
501699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
501743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Then.get() == S->getThen() &&
501843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Else.get() == S->getElse())
50193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
50201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5021eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
502244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                    Then.get(),
50239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    S->getElseLoc(), Else.get());
502443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
502543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
502643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
502760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50281eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
502943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition.
503060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
5031d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  VarDecl *ConditionVar = 0;
5032d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  if (S->getConditionVariable()) {
5033c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
5034d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor      = cast_or_null<VarDecl>(
5035aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5036aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5037aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
5038d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    if (!ConditionVar)
5039f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
504099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
5041d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5042c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
504399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5044f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
504599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
50461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
504743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Rebuild the switch statement.
504860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Switch
50499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5050586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                          ConditionVar);
505143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Switch.isInvalid())
5052f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
505443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body of the switch statement.
505560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
505643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5057f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
505943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Complete the switch statement.
50609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
50619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Body.get());
506243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
50631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
506443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
506560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
506743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
506860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
50695656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  VarDecl *ConditionVar = 0;
50705656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  if (S->getConditionVariable()) {
5071c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
50725656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      = cast_or_null<VarDecl>(
5073aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5074aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5075aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
50765656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    if (!ConditionVar)
5077f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
507899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
50795656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5080c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
508199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5082f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5083afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
5084afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
5085afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
50868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
50878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5088afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5089f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
50909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE;
5091afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
509299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
50931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
50959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5096f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5097eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
509843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
509960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
510043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5101f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
510343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
51049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
510599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
510643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
51079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(S);
51081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5109eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
51109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       ConditionVar, Body.get());
511143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
511460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
511543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
511760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
511843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5119f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5121eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  // Transform the condition
512260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(S->getCond());
5123eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  if (Cond.isInvalid())
5124f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5125eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
512643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
512743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Cond.get() == S->getCond() &&
512843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
51293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
51301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
51329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    /*FIXME:*/S->getWhileLoc(), Cond.get(),
513343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    S->getRParenLoc());
513443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
513760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
51381eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) {
513943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the initialization statement
514060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Init = getDerived().TransformStmt(S->getInit());
514143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Init.isInvalid())
5142f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
514443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
514560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
514699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  VarDecl *ConditionVar = 0;
514799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  if (S->getConditionVariable()) {
5148c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
514999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      = cast_or_null<VarDecl>(
5150aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5151aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5152aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
515399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (!ConditionVar)
5154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
515599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
515699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5157c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
515899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5159f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5160afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
5161afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
5162afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
51638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
51648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5165afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5166f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5167afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
51689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
5169afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
517099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
51711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
51739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5174f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5175eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
517643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the increment
517760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Inc = getDerived().TransformExpr(S->getInc());
517843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Inc.isInvalid())
5179f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
51829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (S->getInc() && !FullInc.get())
5183f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5184eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
518543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
518660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
518743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5188f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
519043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
519143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Init.get() == S->getInit() &&
51929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
519343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Inc.get() == S->getInc() &&
519443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
51953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
51961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
519743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
51989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Init.get(), FullCond, ConditionVar,
51999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     FullInc, S->getRParenLoc(), Body.get());
520043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
520143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
520243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
520360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52041eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
520557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
520657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getLabel());
520757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
520857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
520957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
521043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Goto statements must always be rebuilt, to resolve the label.
52111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
521257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                      cast<LabelDecl>(LD));
521343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
521443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
521543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
521660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
521860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Target = getDerived().TransformExpr(S->getTarget());
521943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Target.isInvalid())
5220f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
52211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
522243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
522343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Target.get() == S->getTarget())
52243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
522543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
522643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
52279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Target.get());
522843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
522943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
523043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
523160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
52333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
523443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
523643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
523760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52381eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
52393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
524043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
524243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
524360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
524560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = getDerived().TransformExpr(S->getRetValue());
524643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Result.isInvalid())
5247f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
524843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
52491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: We always rebuild the return statement because there is no way
525043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // to tell whether the return type of the function has changed.
52519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
525243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
525443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
525560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52561eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
525743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool DeclChanged = false;
525843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  llvm::SmallVector<Decl *, 4> Decls;
525943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
526043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       D != DEnd; ++D) {
5261aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor    Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5262aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                         *D);
526343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (!Transformed)
5264f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
52651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
526643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Transformed != *D)
526743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      DeclChanged = true;
52681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
526943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Decls.push_back(Transformed);
527043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
52711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
527243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() && !DeclChanged)
52733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
52741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
527643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getStartLoc(), S->getEndLoc());
527743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
527943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
528060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
528143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
5282c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5283ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Constraints(getSema());
5284ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Exprs(getSema());
5285ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  llvm::SmallVector<IdentifierInfo *, 4> Names;
5286a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson
528760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AsmString;
5288ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Clobbers(getSema());
5289703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5290703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  bool ExprsChanged = false;
5291c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5292703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the outputs.
5293703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5294ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getOutputIdentifier(I));
5295c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5296703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
52973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getOutputConstraintLiteral(I));
5298c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5299703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the output expr.
5300703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *OutputExpr = S->getOutputExpr(I);
530160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(OutputExpr);
5302703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
5303f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5304c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5305703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != OutputExpr;
5306c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
5308703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
5309c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5310703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the inputs.
5311703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5312ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getInputIdentifier(I));
5313c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5314703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
53153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getInputConstraintLiteral(I));
5316c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5317703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the input expr.
5318703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *InputExpr = S->getInputExpr(I);
531960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(InputExpr);
5320703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
5321f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5322c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5323703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != InputExpr;
5324c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
5326703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
5327c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5328703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
53293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5330703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5331703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the clobbers.
5332703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
53333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Clobbers.push_back(S->getClobber(I));
5334703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5335703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // No need to transform the asm string literal.
5336703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  AsmString = SemaRef.Owned(S->getAsmString());
5337703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5338703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5339703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isSimple(),
5340703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isVolatile(),
5341703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumOutputs(),
5342703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumInputs(),
5343a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson                                     Names.data(),
5344703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Constraints),
5345703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Exprs),
53469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     AsmString.get(),
5347703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Clobbers),
5348703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getRParenLoc(),
5349703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isMSAsm());
535043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
535143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
535243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
535343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
535460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
53551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
53564dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body of the @try.
535760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
53584dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (TryBody.isInvalid())
5359f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53618f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  // Transform the @catch statements (if present).
53628f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  bool AnyCatchChanged = false;
5363ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> CatchStmts(SemaRef);
53648f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
536560d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
53664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Catch.isInvalid())
5367f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
53688f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    if (Catch.get() != S->getCatchStmt(I))
53698f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      AnyCatchChanged = true;
53708f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    CatchStmts.push_back(Catch.release());
53714dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
5372c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53734dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the @finally statement (if present).
537460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Finally;
53754dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (S->getFinallyStmt()) {
53764dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    Finally = getDerived().TransformStmt(S->getFinallyStmt());
53774dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Finally.isInvalid())
5378f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
53794dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
53804dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
53814dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
53824dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
53834dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      TryBody.get() == S->getTryBody() &&
53848f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      !AnyCatchChanged &&
53854dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Finally.get() == S->getFinallyStmt())
53863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5387c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53884dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
53899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
53909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           move_arg(CatchStmts), Finally.get());
539143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
53921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
539343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
539460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
53951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5396be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  // Transform the @catch parameter, if there is one.
5397be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *Var = 0;
5398be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (VarDecl *FromVar = S->getCatchParamDecl()) {
5399be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    TypeSourceInfo *TSInfo = 0;
5400be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (FromVar->getTypeSourceInfo()) {
5401be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5402be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (!TSInfo)
5403f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5404be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
5405c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5406be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    QualType T;
5407be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (TSInfo)
5408be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = TSInfo->getType();
5409be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    else {
5410be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = getDerived().TransformType(FromVar->getType());
5411be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (T.isNull())
5412f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5413be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
5414c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5415be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5416be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (!Var)
5417f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5418be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
5419c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
542060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5421be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (Body.isInvalid())
5422f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5423c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5424c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5425be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                             S->getRParenLoc(),
54269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Var, Body.get());
542743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
542943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
543060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54311eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
54324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body.
543360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
54344dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (Body.isInvalid())
5435f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5436c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54374dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
54384dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
54394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Body.get() == S->getFinallyBody())
54403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
54414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
54424dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
54434dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
54449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                               Body.get());
544543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
544743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
544860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54491eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
545060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand;
5451d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (S->getThrowExpr()) {
5452d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    Operand = getDerived().TransformExpr(S->getThrowExpr());
5453d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    if (Operand.isInvalid())
5454f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5455d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
5456c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5457d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5458d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor      Operand.get() == S->getThrowExpr())
54593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return getSema().Owned(S);
5460c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
546243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
546443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
546560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
546643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
54671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCAtSynchronizedStmt *S) {
54688fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the object we are locking.
546960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
54708fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Object.isInvalid())
5471f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54738fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the body.
547460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
54758fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Body.isInvalid())
5476f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5477c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54788fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // If nothing change, just retain the current statement.
54798fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
54808fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Object.get() == S->getSynchExpr() &&
54818fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Body.get() == S->getSynchBody())
54823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
54838fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor
54848fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Build a new statement.
54858fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
54869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    Object.get(), Body.get());
548743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
548843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
548943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
549060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
5491f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5492f85e193739c953358c865005855253af4f68a497John McCall                                              ObjCAutoreleasePoolStmt *S) {
5493f85e193739c953358c865005855253af4f68a497John McCall  // Transform the body.
5494f85e193739c953358c865005855253af4f68a497John McCall  StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5495f85e193739c953358c865005855253af4f68a497John McCall  if (Body.isInvalid())
5496f85e193739c953358c865005855253af4f68a497John McCall    return StmtError();
5497f85e193739c953358c865005855253af4f68a497John McCall
5498f85e193739c953358c865005855253af4f68a497John McCall  // If nothing changed, just retain this statement.
5499f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
5500f85e193739c953358c865005855253af4f68a497John McCall      Body.get() == S->getSubStmt())
5501f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(S);
5502f85e193739c953358c865005855253af4f68a497John McCall
5503f85e193739c953358c865005855253af4f68a497John McCall  // Build a new statement.
5504f85e193739c953358c865005855253af4f68a497John McCall  return getDerived().RebuildObjCAutoreleasePoolStmt(
5505f85e193739c953358c865005855253af4f68a497John McCall                        S->getAtLoc(), Body.get());
5506f85e193739c953358c865005855253af4f68a497John McCall}
5507f85e193739c953358c865005855253af4f68a497John McCall
5508f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
5509f85e193739c953358c865005855253af4f68a497John McCallStmtResult
551043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt(
55111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCForCollectionStmt *S) {
5512c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the element statement.
551360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Element = getDerived().TransformStmt(S->getElement());
5514c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Element.isInvalid())
5515f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5516c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5517c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the collection expression.
551860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5519c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Collection.isInvalid())
5520f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5521c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5522c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the body.
552360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
5524c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Body.isInvalid())
5525f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5526c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5527c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // If nothing changed, just retain this statement.
5528c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
5529c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Element.get() == S->getElement() &&
5530c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Collection.get() == S->getCollection() &&
5531c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Body.get() == S->getBody())
55323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5533c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5534c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Build a new statement.
5535c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5536c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   /*FIXME:*/S->getForLoc(),
55379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Element.get(),
55389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Collection.get(),
5539c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   S->getRParenLoc(),
55409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Body.get());
554143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
554243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
554343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
554443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
554560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
554643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
554743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the exception declaration, if any.
554843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  VarDecl *Var = 0;
554943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (S->getExceptionDecl()) {
555043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    VarDecl *ExceptionDecl = S->getExceptionDecl();
555183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    TypeSourceInfo *T = getDerived().TransformType(
555283cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getTypeSourceInfo());
555383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    if (!T)
5554f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
55551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
555683cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
5557ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getInnerLocStart(),
5558ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getLocation(),
5559ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getIdentifier());
5560ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor    if (!Var || Var->isInvalidDecl())
5561f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
556243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
55631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
556443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the actual exception handler.
556560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5566ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor  if (Handler.isInvalid())
5567f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
55681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
556943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
557043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !Var &&
557143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Handler.get() == S->getHandlerBlock())
55723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
557343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
557443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
557543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          Var,
55769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Handler.get());
557743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
55781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
557943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
558060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
558143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
558243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the try block itself.
558360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBlock
558443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    = getDerived().TransformCompoundStmt(S->getTryBlock());
558543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (TryBlock.isInvalid())
5586f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
55871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
558843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the handlers.
558943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool HandlerChanged = false;
5590ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Handlers(SemaRef);
559143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
559260d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Handler
559343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      = getDerived().TransformCXXCatchStmt(S->getHandler(I));
559443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Handler.isInvalid())
5595f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
55961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
559743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
559843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Handlers.push_back(Handler.takeAs<Stmt>());
559943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
56001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
560143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
560243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      TryBlock.get() == S->getTryBlock() &&
560343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !HandlerChanged)
56043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
560543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
56069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
56071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        move_arg(Handlers));
560843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
56091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5610ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived>
5611ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult
5612ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5613ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5614ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Range.isInvalid())
5615ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5616ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5617ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5618ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (BeginEnd.isInvalid())
5619ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5620ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5621ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ExprResult Cond = getDerived().TransformExpr(S->getCond());
5622ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Cond.isInvalid())
5623ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5624ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5625ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ExprResult Inc = getDerived().TransformExpr(S->getInc());
5626ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Inc.isInvalid())
5627ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5628ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5629ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5630ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (LoopVar.isInvalid())
5631ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5632ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5633ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult NewStmt = S;
5634ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (getDerived().AlwaysRebuild() ||
5635ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Range.get() != S->getRangeStmt() ||
5636ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      BeginEnd.get() != S->getBeginEndStmt() ||
5637ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Cond.get() != S->getCond() ||
5638ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Inc.get() != S->getInc() ||
5639ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      LoopVar.get() != S->getLoopVarStmt())
5640ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5641ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getColonLoc(), Range.get(),
5642ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  BeginEnd.get(), Cond.get(),
5643ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  Inc.get(), LoopVar.get(),
5644ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getRParenLoc());
5645ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5646ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult Body = getDerived().TransformStmt(S->getBody());
5647ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Body.isInvalid())
5648ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5649ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5650ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // Body has changed but we didn't rebuild the for-range statement. Rebuild
5651ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // it now so we have a new statement to attach the body to.
5652ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Body.get() != S->getBody() && NewStmt.get() == S)
5653ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5654ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getColonLoc(), Range.get(),
5655ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  BeginEnd.get(), Cond.get(),
5656ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  Inc.get(), LoopVar.get(),
5657ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getRParenLoc());
5658ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5659ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (NewStmt.get() == S)
5660ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return SemaRef.Owned(S);
5661ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5662ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5663ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
5664ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
566528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
566628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
566728bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
566828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult TryBlock; //  = getDerived().TransformCompoundStmt(S->getTryBlock());
566928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(TryBlock.isInvalid()) return StmtError();
567028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
567128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
567228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(!getDerived().AlwaysRebuild() &&
567328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley     TryBlock.get() == S->getTryBlock() &&
567428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley     Handler.get() == S->getHandler())
567528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SemaRef.Owned(S);
567628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
567728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
567828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        S->getTryLoc(),
567928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        TryBlock.take(),
568028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        Handler.take());
568128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
568228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
568328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
568428bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
568528bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
568628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
568728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(Block.isInvalid()) return StmtError();
568828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
568928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
569028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                            Block.take());
569128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
569228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
569328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
569428bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
569528bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
569628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
569728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(FilterExpr.isInvalid()) return StmtError();
569828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
569928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
570028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(Block.isInvalid()) return StmtError();
570128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
570228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
570328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                           FilterExpr.take(),
570428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                           Block.take());
570528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
570628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
570728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
570828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
570928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
571028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(isa<SEHFinallyStmt>(Handler))
571128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
571228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  else
571328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
571428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
571528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
571643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
5717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation
5718577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
57191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
572060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5721454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
57223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
57231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
57241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
572660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5727454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
572840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
572940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  if (E->getQualifierLoc()) {
573040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    QualifierLoc
573140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
573240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!QualifierLoc)
5733f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5734a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5735dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5736dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *ND
57377c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
57387c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getDecl()));
5739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!ND)
5740f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5742ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  DeclarationNameInfo NameInfo = E->getNameInfo();
5743ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  if (NameInfo.getName()) {
5744ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5745ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    if (!NameInfo.getName())
5746f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5747ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  }
57482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
57492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!getDerived().AlwaysRebuild() &&
575040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      QualifierLoc == E->getQualifierLoc() &&
5751a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ND == E->getDecl() &&
57522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NameInfo.getName() == E->getDecl()->getDeclName() &&
5753096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
57541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5755dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // Mark it referenced in the new context regardless.
5756dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: this is a bit instantiation-specific.
5757dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5758a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
57593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5760a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5761dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5762dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
5763096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
5764dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TemplateArgs = &TransArgs;
5765dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
5766dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
5767fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5768fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
5769fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
5770fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
5771dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
5772dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
577340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
577440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                                         TemplateArgs);
5775577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
57761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
577860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5779454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
57803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5781577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
57821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
578460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5785454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
57863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
579060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5791454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
57923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
579660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5797454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
57983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
580260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5803454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
58043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
580860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5809f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5810f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult ControllingExpr =
5811f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    getDerived().TransformExpr(E->getControllingExpr());
5812f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  if (ControllingExpr.isInvalid())
5813f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return ExprError();
5814f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5815f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  llvm::SmallVector<Expr *, 4> AssocExprs;
5816f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5817f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5818f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5819f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (TS) {
5820f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5821f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      if (!AssocType)
5822f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne        return ExprError();
5823f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      AssocTypes.push_back(AssocType);
5824f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    } else {
5825f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      AssocTypes.push_back(0);
5826f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    }
5827f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5828f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5829f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (AssocExpr.isInvalid())
5830f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      return ExprError();
5831f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    AssocExprs.push_back(AssocExpr.release());
5832f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
5833f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5834f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5835f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getDefaultLoc(),
5836f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getRParenLoc(),
5837f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  ControllingExpr.release(),
5838f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  AssocTypes.data(),
5839f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  AssocExprs.data(),
5840f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getNumAssocs());
5841f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}
5842f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5843f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived>
5844f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult
5845454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
584660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5848f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
58513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
5854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       E->getRParen());
5855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
58571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
585860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5859454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
586060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5862f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
58653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getOpcode(),
58699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get());
5870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
587360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
58748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
58758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform the type.
58768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
58778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!Type)
5878f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5879c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
58808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform all of the components into components similar to what the
58818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // parser uses.
5882c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // FIXME: It would be slightly more efficient in the non-dependent case to
5883c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // just map FieldDecls, rather than requiring the rebuilder to look for
5884c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // the fields again. However, __builtin_offsetof is rare enough in
58858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // template code that we don't care.
58868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool ExprChanged = false;
5887f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::OffsetOfComponent Component;
58888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef OffsetOfExpr::OffsetOfNode Node;
58898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  llvm::SmallVector<Component, 4> Components;
58908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
58918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const Node &ON = E->getComponent(I);
58928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Component Comp;
589372be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor    Comp.isBrackets = true;
589406dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara    Comp.LocStart = ON.getSourceRange().getBegin();
589506dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara    Comp.LocEnd = ON.getSourceRange().getEnd();
58968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    switch (ON.getKind()) {
58978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Array: {
58988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
589960d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(FromIndex);
59008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (Index.isInvalid())
5901f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
5902c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      ExprChanged = ExprChanged || Index.get() != FromIndex;
59048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = true;
59059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Comp.U.E = Index.get();
59068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
59078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5908c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Field:
59108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Identifier:
59118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = false;
59128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.U.IdentInfo = ON.getFieldName();
591329d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor      if (!Comp.U.IdentInfo)
591429d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor        continue;
5915c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
5917c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5918cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    case Node::Base:
5919cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      // Will be recomputed during the rebuild.
5920cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      continue;
59218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5922c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Components.push_back(Comp);
59248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
5925c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // If nothing changed, retain the existing expression.
59278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
59288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Type == E->getTypeSourceInfo() &&
59298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      !ExprChanged)
59303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5931c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Build a new offsetof expression.
59338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
59348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          Components.data(), Components.size(),
59358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          E->getRParenLoc());
59367cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}
59377cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
59387cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived>
59397cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult
59407cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
59417cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  assert(getDerived().AlreadyTransformed(E->getType()) &&
59427cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall         "opaque value expression requires transformation");
59437cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  return SemaRef.Owned(E);
59448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
59458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
59468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived>
594760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5948f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5949f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                UnaryExprOrTypeTraitExpr *E) {
5950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isArgumentType()) {
5951a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *OldT = E->getArgumentTypeInfo();
59525557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor
5953a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *NewT = getDerived().TransformType(OldT);
59545ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!NewT)
5955f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
59561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59575ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!getDerived().AlwaysRebuild() && OldT == NewT)
59583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
59591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5960f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5961f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                    E->getKind(),
5962f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                    E->getSourceRange());
5963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
59641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
596560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr;
59661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  {
5967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // C++0x [expr.sizeof]p1:
5968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   The operand is either an expression, which is an unevaluated operand
5969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   [...]
5970f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
59711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
5974f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
59751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
59773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
5978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
59791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5980f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5981f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getOperatorLoc(),
5982f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getKind(),
5983f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getSourceRange());
5984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
598760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5988454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
598960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5990b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5991f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
599360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5995f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
60013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
6004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           /*FIXME:*/E->getLHS()->getLocStart(),
60059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                RHS.get(),
6006b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getRBracketLoc());
6007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
601060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6011454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the callee.
601360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
6015f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6017b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform arguments.
6018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgChanged = false;
6019ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6020aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6021aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
6022aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6023aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
6026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgChanged)
60273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Wrong source location information for the '('.
60301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLParenLoc
6031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = ((Expr *)Callee.get())->getSourceRange().getBegin();
60329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6033b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      move_arg(Args),
6034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
6035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
603860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6039454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
604060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
6042f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
604440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
604583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (E->hasQualifier()) {
604640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    QualifierLoc
604740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
604840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor
604940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!QualifierLoc)
6050f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
605183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
60521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6053f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *Member
60547c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
60557c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getMemberDecl()));
6056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Member)
6057f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60596bb8017bb9e828d118e15e59d71c66bba323c364John McCall  NamedDecl *FoundDecl = E->getFoundDecl();
60606bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (FoundDecl == E->getMemberDecl()) {
60616bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = Member;
60626bb8017bb9e828d118e15e59d71c66bba323c364John McCall  } else {
60636bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = cast_or_null<NamedDecl>(
60646bb8017bb9e828d118e15e59d71c66bba323c364John McCall                   getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
60656bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!FoundDecl)
6066f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
60676bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
60686bb8017bb9e828d118e15e59d71c66bba323c364John McCall
6069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase() &&
607140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      QualifierLoc == E->getQualifierLoc() &&
60728a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor      Member == E->getMemberDecl() &&
60736bb8017bb9e828d118e15e59d71c66bba323c364John McCall      FoundDecl == E->getFoundDecl() &&
6074096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
6075c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
60761f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // Mark it referenced in the new context regardless.
60771f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // FIXME: this is a bit instantiation-specific.
60781f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
60793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60801f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson  }
6081b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6082d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs;
6083096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
6084d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
6085d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
6086fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6087fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
6088fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
6089fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
60908a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor  }
6091c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bogus source location for the operator
6093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeOperatorLoc
6094b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6096c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
6097c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
6098c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
6099c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
6100c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
6101c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
61029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isArrow(),
610440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                                        QualifierLoc,
61052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                        E->getMemberNameInfo(),
61068a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor                                        Member,
61076bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        FoundDecl,
6108096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                        (E->hasExplicitTemplateArgs()
6109d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                           ? &TransArgs : 0),
6110c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                        FirstQualifierInScope);
6111b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6113b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
611460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6115454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
611660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6117b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6118f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
612060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6122f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
61273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6129b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
61309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            LHS.get(), RHS.get());
6131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
61331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
613460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator(
6136454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CompoundAssignOperator *E) {
6137454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformBinaryOperator(E);
6138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
614156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>::
614256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
614356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // Just rebuild the common and RHS expressions and see whether we
614456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // get any changes.
614556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
614656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
614756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (commonExpr.isInvalid())
614856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
614956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
615056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
615156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (rhs.isInvalid())
615256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
615356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
615456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (!getDerived().AlwaysRebuild() &&
615556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      commonExpr.get() == e->getCommon() &&
615656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      rhs.get() == e->getFalseExpr())
615756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return SemaRef.Owned(e);
615856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
615956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  return getDerived().RebuildConditionalOperator(commonExpr.take(),
616056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getQuestionLoc(),
616156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 0,
616256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getColonLoc(),
616356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 rhs.get());
616456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}
616556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
616656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived>
616760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6168454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
616960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
6170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
6171f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
617360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6175f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
617760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6179f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
6183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
61853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildConditionalOperator(Cond.get(),
618847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getQuestionLoc(),
61899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 LHS.get(),
619047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getColonLoc(),
61919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 RHS.get());
6192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
619560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6196454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6197a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // Implicit casts are eliminated during transformation, since they
6198a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // will be recomputed by semantic analysis after transformation.
61996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return getDerived().TransformExpr(E->getSubExprAsWritten());
6200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
620360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6204454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6205ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6206ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6207ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
6208ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
620960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
62106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6215ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
62173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62199d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6220ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                            Type,
6221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc(),
62229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            SubExpr.get());
6223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
622660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6227454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
622842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *OldT = E->getTypeSourceInfo();
622942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
623042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  if (!NewT)
6231f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
623360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
6235f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6237b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
623842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      OldT == NewT &&
6239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInitializer())
62403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6241b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62421d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // Note: the expression type doesn't necessarily match the
62431d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // type-as-written, but that's okay, because it should always be
62441d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // derivable from the initializer.
62451d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
624642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   /*FIXME:*/E->getInitializer()->getLocEnd(),
62489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Init.get());
6249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6251b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
625260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6253454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
625460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6255b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
6256f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase())
62603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bad source location
62631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeOperatorLoc
6264b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
62659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessorLoc(),
6267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessor());
6268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6270b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
627160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6272454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool InitChanged = false;
62741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6275ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
6276aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6277aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  Inits, &InitChanged))
6278aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6279aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && !InitChanged)
62813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
6284e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                      E->getRBraceLoc(), E->getType());
6285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
628860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6289454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
6290b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Designation Desig;
62911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
629243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the initializer value
629360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInit());
6294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
6295f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
629743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the designators.
6298ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
6299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ExprChanged = false;
6300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             DEnd = E->designators_end();
6302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       D != DEnd; ++D) {
6303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isFieldDesignator()) {
6304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Desig.AddDesignator(Designator::getField(D->getFieldName(),
6305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getDotLoc(),
6306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getFieldLoc()));
6307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
6308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
63091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isArrayDesignator()) {
631160d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
6312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Index.isInvalid())
6313f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
63141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Desig.AddDesignator(Designator::getArray(Index.get(),
6316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getLBracketLoc()));
63171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArrayExprs.push_back(Index.release());
6320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
6321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
63221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(D->isArrayRangeDesignator() && "New kind of designator?");
632460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Start
6325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Start.isInvalid())
6327f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
632960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
6330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (End.isInvalid())
6331f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Desig.AddDesignator(Designator::getArrayRange(Start.get(),
6334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  End.get(),
6335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getLBracketLoc(),
6336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getEllipsisLoc()));
63371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      End.get() != E->getArrayRangeEnd(*D);
63401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(Start.release());
6342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(End.release());
6343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
63441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInit() &&
6347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ExprChanged)
63483fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getEqualOrColonLoc(),
63529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                E->usesGNUSyntax(), Init.get());
6353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
635660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr(
6358454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     ImplicitValueInitExpr *E) {
63595557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
6360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
63615557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // FIXME: Will we ever have proper type location here? Will we actually
63625557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // need to transform the type?
6363b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
6364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
6365f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType())
63693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildImplicitValueInitExpr(T);
6372b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
637560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6376454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
63779bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
63789bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo)
6379f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
638160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6383f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
63862cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      TInfo == E->getWrittenTypeInfo() &&
6387b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
63883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
63912cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                       TInfo, E->getRParenLoc());
6392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6394b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
639560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6396454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
6397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6398ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
6399aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6400aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
6401aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6402aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           move_arg(Inits),
6405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getRParenLoc());
6406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression.
6409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
6410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always
6411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to
6412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis.
6413b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
641460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6415454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
641657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
641757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        E->getLabel());
641857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
641957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return ExprError();
642057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
6421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
642257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                           cast<LabelDecl>(LD));
6423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
642660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6427454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
642860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt
6429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubStmt.isInvalid())
6431f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubStmt.get() == E->getSubStmt())
64353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
64389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      SubStmt.get(),
6439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
6440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
644360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6444454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
644560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
6446b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
6447f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
644960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6451f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
645360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6455f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
6459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
64613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
64649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Cond.get(), LHS.get(), RHS.get(),
6465b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->getRParenLoc());
6466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
646960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6470454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
64713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
647560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6476454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
6477668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  switch (E->getOperator()) {
6478668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_New:
6479668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Delete:
6480668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_New:
6481668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_Delete:
6482668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
6483f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6484c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6485668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Call: {
6486668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // This is a call to an object's operator().
6487668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6488668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6489668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the object itself.
649060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Object = getDerived().TransformExpr(E->getArg(0));
6491668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    if (Object.isInvalid())
6492f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6493668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6494668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // FIXME: Poor location information
6495668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    SourceLocation FakeLParenLoc
6496668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      = SemaRef.PP.getLocForEndOfToken(
6497668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                              static_cast<Expr *>(Object.get())->getLocEnd());
6498668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6499668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the call arguments.
6500ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> Args(SemaRef);
6501aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6502aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                    Args))
6503aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return ExprError();
6504668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
65059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
6506668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        move_arg(Args),
6507668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        E->getLocEnd());
6508668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
6509668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6510668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6511668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_##Name:
6512668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6513668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def"
6514668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Subscript:
6515668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Handled below.
6516668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    break;
6517668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6518668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Conditional:
6519668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("conditional operator is not actually overloadable");
6520f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6521668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6522668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_None:
6523668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case NUM_OVERLOADED_OPERATORS:
6524668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("not an overloaded operator?");
6525f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6526668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
6527668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
652860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
6530f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
653260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult First = getDerived().TransformExpr(E->getArg(0));
6533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (First.isInvalid())
6534f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
653660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Second;
6537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->getNumArgs() == 2) {
6538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Second = getDerived().TransformExpr(E->getArg(1));
6539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Second.isInvalid())
6540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
65421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
6545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      First.get() == E->getArg(0) &&
65461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
65473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
65481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 E->getOperatorLoc(),
65519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Callee.get(),
65529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 First.get(),
65539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Second.get());
6554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
655760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6558454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6559454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCallExpr(E);
6560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
6563e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult
6564e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6565e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform the callee.
6566e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6567e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (Callee.isInvalid())
6568e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6569e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6570e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform exec config.
6571e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6572e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (EC.isInvalid())
6573e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6574e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6575e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform arguments.
6576e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  bool ArgChanged = false;
6577e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ASTOwningVector<Expr*> Args(SemaRef);
6578e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6579e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                  &ArgChanged))
6580e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6581e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6582e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (!getDerived().AlwaysRebuild() &&
6583e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      Callee.get() == E->getCallee() &&
6584e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      !ArgChanged)
6585e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return SemaRef.Owned(E);
6586e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6587e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // FIXME: Wrong source location information for the '('.
6588e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  SourceLocation FakeLParenLoc
6589e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    = ((Expr *)Callee.get())->getSourceRange().getBegin();
6590e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6591e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      move_arg(Args),
6592e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      E->getRParenLoc(), EC.get());
6593e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}
6594e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6595e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived>
659660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6597454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
6598ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6599ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6600ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
6601ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
660260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
66036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6605f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6608ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
66103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Poor source location information here.
66131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLAngleLoc
6614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRParenLoc
6617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(
6618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  E->getSubExpr()->getSourceRange().getEnd());
6619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
66201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              E->getStmtClass(),
6621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeLAngleLoc,
6622ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                              Type,
6623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
6624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
66259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              SubExpr.get(),
6626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRParenLoc);
6627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
663060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6631454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6632454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
663660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6637454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6638454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
664260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr(
6644454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CXXReinterpretCastExpr *E) {
6645454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
664960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6650454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6651454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
665560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr(
6657454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXFunctionalCastExpr *E) {
6658ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6659ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6660ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
66611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
666260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
66636eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6665f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6668ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
66703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6672ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  return getDerived().RebuildCXXFunctionalCastExpr(Type,
6673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      /*FIXME:*/E->getSubExpr()->getLocStart(),
66749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr.get(),
6675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   E->getRParenLoc());
6676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
667960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6680454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
6681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isTypeOperand()) {
668257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    TypeSourceInfo *TInfo
668357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      = getDerived().TransformType(E->getTypeOperandSourceInfo());
668457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    if (!TInfo)
6685f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
66861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
668857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        TInfo == E->getTypeOperandSourceInfo())
66893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
66901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
669157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return getDerived().RebuildCXXTypeidExpr(E->getType(),
669257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             E->getLocStart(),
669357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             TInfo,
6694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getLocEnd());
6695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
66961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // We don't know whether the expression is potentially evaluated until
6698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // after we perform semantic analysis, so the expression is potentially
6699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // potentially evaluated.
67001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  EnterExpressionEvaluationContext Unevaluated(SemaRef,
6701f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      Sema::PotentiallyPotentiallyEvaluated);
67021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
670360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6705f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getExprOperand())
67093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
671157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  return getDerived().RebuildCXXTypeidExpr(E->getType(),
671257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                           E->getLocStart(),
67139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get(),
6714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLocEnd());
6715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
671860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
671901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
672001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (E->isTypeOperand()) {
672101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    TypeSourceInfo *TInfo
672201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      = getDerived().TransformType(E->getTypeOperandSourceInfo());
672301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!TInfo)
672401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      return ExprError();
672501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
672601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!getDerived().AlwaysRebuild() &&
672701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet        TInfo == E->getTypeOperandSourceInfo())
67283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
672901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
67303c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor    return getDerived().RebuildCXXUuidofExpr(E->getType(),
673101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocStart(),
673201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             TInfo,
673301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocEnd());
673401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
673501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
673601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // We don't know whether the expression is potentially evaluated until
673701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // after we perform semantic analysis, so the expression is potentially
673801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // potentially evaluated.
673901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
674001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
674101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
674201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (SubExpr.isInvalid())
674301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return ExprError();
674401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
674501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (!getDerived().AlwaysRebuild() &&
674601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      SubExpr.get() == E->getExprOperand())
67473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
674801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
674901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  return getDerived().RebuildCXXUuidofExpr(E->getType(),
675001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocStart(),
675101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           SubExpr.get(),
675201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocEnd());
675301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}
675401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
675501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived>
675601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult
6757454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
67583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
676260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
6764454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXNullPtrLiteralExpr *E) {
67653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
676960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6770454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
6771ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  DeclContext *DC = getSema().getFunctionLevelDeclContext();
67727a614d8380297fcd2bc23986241905d97222948cRichard Smith  QualType T;
67737a614d8380297fcd2bc23986241905d97222948cRichard Smith  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
67747a614d8380297fcd2bc23986241905d97222948cRichard Smith    T = MD->getThisType(getSema().Context);
67757a614d8380297fcd2bc23986241905d97222948cRichard Smith  else
67767a614d8380297fcd2bc23986241905d97222948cRichard Smith    T = getSema().Context.getPointerType(
67777a614d8380297fcd2bc23986241905d97222948cRichard Smith      getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
67781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6779ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!getDerived().AlwaysRebuild() && T == E->getType())
67803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6782828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
6783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
678660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6787454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
678860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6790f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
67943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
67969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
6797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
680060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6801454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
68021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParmVarDecl *Param
68037c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
68047c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           E->getParam()));
6805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Param)
6806f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
680853cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth  if (!getDerived().AlwaysRebuild() &&
6809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Param == E->getParam())
68103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
68111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6812036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
6813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
68141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
681660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6817ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6818ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXScalarValueInitExpr *E) {
6819ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6820ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6821f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6822ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
6823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6824ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo())
68253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
68261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6827ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXScalarValueInitExpr(T,
6828ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
6829ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor                                                    E->getRParenLoc());
6830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
68311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
683360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6834454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
6835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the type that we're allocating
68361bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocTypeInfo
68371bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
68381bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  if (!AllocTypeInfo)
6839f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the size of the array we're allocating (if any).
684260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
6843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (ArraySize.isInvalid())
6844f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the placement arguments (if any).
6847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6848ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> PlacementArgs(SemaRef);
6849aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getPlacementArgs(),
6850aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  E->getNumPlacementArgs(), true,
6851aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  PlacementArgs, &ArgumentChanged))
6852aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
68531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
685443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the constructor arguments (if any).
6855ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
6856aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6857aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     ConstructorArgs, &ArgumentChanged))
6858aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
68591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68601af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform constructor, new operator, and delete operator.
68611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  CXXConstructorDecl *Constructor = 0;
68621af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getConstructor()) {
68631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    Constructor = cast_or_null<CXXConstructorDecl>(
68647c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
68657c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
68661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!Constructor)
6867f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68681af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
68691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
68701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorNew = 0;
68711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorNew()) {
68721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorNew = cast_or_null<FunctionDecl>(
68737c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(E->getLocStart(),
68747c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getOperatorNew()));
68751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorNew)
6876f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68771af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
68781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
68791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
68801af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
68811af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
68827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
68837c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
68841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6885f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6887c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
68891bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor      AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
6890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArraySize.get() == E->getArraySize() &&
68911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Constructor == E->getConstructor() &&
68921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorNew == E->getOperatorNew() &&
68931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete() &&
68941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      !ArgumentChanged) {
68951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
68961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
68971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (Constructor)
68981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
68991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorNew)
69001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
69011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
69021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
69033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
69041af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
69051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69061bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  QualType AllocType = AllocTypeInfo->getType();
69075b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  if (!ArraySize.get()) {
69085b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // If no array size was specified, but the new expression was
69095b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with an array type (e.g., "new T" where T is
69105b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with "int[4]"), extract the outer bound from the
69115b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // array type as our array size. We do this with constant and
69125b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // dependently-sized array types.
69135b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
69145b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    if (!ArrayT) {
69155b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      // Do nothing
69165b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const ConstantArrayType *ConsArrayT
69175b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                                     = dyn_cast<ConstantArrayType>(ArrayT)) {
6918c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      ArraySize
69199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
69209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               ConsArrayT->getSize(),
69219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               SemaRef.Context.getSizeType(),
69229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               /*FIXME:*/E->getLocStart()));
69235b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      AllocType = ConsArrayT->getElementType();
69245b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const DependentSizedArrayType *DepArrayT
69255b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                              = dyn_cast<DependentSizedArrayType>(ArrayT)) {
69265b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      if (DepArrayT->getSizeExpr()) {
69273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall        ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
69285b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor        AllocType = DepArrayT->getElementType();
69295b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      }
69305b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    }
69315b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  }
69321bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
6933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isGlobalNew(),
6935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
6936b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(PlacementArgs),
6937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
69384bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                        E->getTypeIdParens(),
6939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        AllocType,
69401bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                        AllocTypeInfo,
69419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        ArraySize.get(),
6942d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                        /*FIXME:*/E->hasInitializer()
6943d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                          ? E->getLocStart()
6944d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                          : SourceLocation(),
6945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(ConstructorArgs),
6946d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                        /*FIXME:*/E->hasInitializer()
6947d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                          ? E->getLocEnd()
6948d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                          : SourceLocation());
6949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
695260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6953454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
695460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
6955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Operand.isInvalid())
6956f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
69571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform the delete operator, if known.
69591af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
69601af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
69611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
69627c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
69637c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
69641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6965f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
69661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6967c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
69691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Operand.get() == E->getArgument() &&
69701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete()) {
69711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
69721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
69731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
69741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
69755833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
69765833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    if (!E->getArgument()->isTypeDependent()) {
69775833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      QualType Destroyed = SemaRef.Context.getBaseElementType(
69785833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                                         E->getDestroyedType());
69795833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
69805833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
69815833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        SemaRef.MarkDeclarationReferenced(E->getLocStart(),
69825833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                          SemaRef.LookupDestructor(Record));
69835833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      }
69845833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    }
69855833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
69863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
69871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
69881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6989b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6990b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isGlobalDelete(),
6991b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isArrayForm(),
69929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Operand.get());
6993b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6995b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
699660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6997a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
6998454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXPseudoDestructorExpr *E) {
699960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7000a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  if (Base.isInvalid())
7001f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
70021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7003b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ObjectTypePtr;
7004a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  bool MayBePseudoDestructor = false;
70059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7006a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              E->getOperatorLoc(),
7007a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        E->isArrow()? tok::arrow : tok::period,
7008a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              ObjectTypePtr,
7009a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              MayBePseudoDestructor);
7010a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (Base.isInvalid())
7011f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7012c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7013b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  QualType ObjectType = ObjectTypePtr.get();
7014f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7015f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  if (QualifierLoc) {
7016f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    QualifierLoc
7017f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7018f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    if (!QualifierLoc)
701943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      return ExprError();
702043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
7021f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  CXXScopeSpec SS;
7022f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  SS.Adopt(QualifierLoc);
70231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7024a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage Destroyed;
7025a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (E->getDestroyedTypeInfo()) {
7026a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    TypeSourceInfo *DestroyedTypeInfo
702743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7028b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                ObjectType, 0, SS);
7029a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!DestroyedTypeInfo)
7030f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7031a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = DestroyedTypeInfo;
7032a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else if (ObjectType->isDependentType()) {
7033a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // We aren't likely to be able to resolve the identifier down to a type
7034a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // now anyway, so just retain the identifier.
7035a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7036a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                            E->getDestroyedTypeLoc());
7037a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else {
7038a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // Look for a destructor known with the given name.
7039b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7040a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              *E->getDestroyedTypeIdentifier(),
7041a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                E->getDestroyedTypeLoc(),
7042a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                /*Scope=*/0,
7043a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                SS, ObjectTypePtr,
7044a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                false);
7045a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!T)
7046f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7047c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7048a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed
7049a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7050a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                 E->getDestroyedTypeLoc());
7051a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
705226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
705326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *ScopeTypeInfo = 0;
705426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (E->getScopeTypeInfo()) {
705543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
705626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    if (!ScopeTypeInfo)
7057f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7058a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
7059c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
70609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7061a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->getOperatorLoc(),
7062a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->isArrow(),
7063f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                                     SS,
706426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     ScopeTypeInfo,
706526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getColonColonLoc(),
7066fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                     E->getTildeLoc(),
7067a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                     Destroyed);
7068a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}
70691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7070a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived>
707160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7072ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr(
7073454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  UnresolvedLookupExpr *Old) {
7074f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7075f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                 Sema::LookupOrdinaryName);
7076f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7077f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Transform all the decls.
7078f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7079f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall         E = Old->decls_end(); I != E; ++I) {
70807c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
70817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(Old->getNameLoc(),
70827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                            *I));
70839f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
70849f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
70859f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
70869f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
70879f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
70889f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
7089f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
70909f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
7091f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7092f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // Expand using declarations.
7093f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (isa<UsingDecl>(InstD)) {
7094f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
7095f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7096f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall             E = UD->shadow_end(); I != E; ++I)
7097f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        R.addDecl(*I);
7098f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      continue;
7099f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    }
7100f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7101f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    R.addDecl(InstD);
7102f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
7103f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7104f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Resolve a kind, but don't do any further analysis.  If it's
7105f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // ambiguous, the callee needs to deal with it.
7106f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  R.resolveKind();
7107f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7108f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Rebuild the nested-name qualifier, if present.
7109f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  CXXScopeSpec SS;
71104c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  if (Old->getQualifierLoc()) {
71114c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    NestedNameSpecifierLoc QualifierLoc
71124c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
71134c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (!QualifierLoc)
7114f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7115c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
71164c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    SS.Adopt(QualifierLoc);
7117c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
7118c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7119c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (Old->getNamingClass()) {
712066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    CXXRecordDecl *NamingClass
712166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
712266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                            Old->getNameLoc(),
712366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
712466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
7125f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7126c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
712766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
7128f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
7129f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7130f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have no template arguments, it's a normal declaration name.
7131f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!Old->hasExplicitTemplateArgs())
7132f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7133f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7134f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have template arguments, rebuild them, then rebuild the
7135f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // templateid expression.
7136f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
7137fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7138fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              Old->getNumTemplateArgs(),
7139fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7140fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
7141f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7142f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7143f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                            TransArgs);
7144b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
714760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7148454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
71493d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
71503d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  if (!T)
7151f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
71521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
71543d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      T == E->getQueriedTypeSourceInfo())
71553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
71561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocStart(),
7159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            T,
7160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocEnd());
7161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
716460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
71656ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
71666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
71676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!LhsT)
71686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
71696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
71716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!RhsT)
71726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
71736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!getDerived().AlwaysRebuild() &&
71756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
71766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SemaRef.Owned(E);
71776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
71796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocStart(),
71806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            LhsT, RhsT,
71816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocEnd());
71826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}
71836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived>
71856ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult
718621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
718721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
718821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  if (!T)
718921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return ExprError();
719021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
719121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  if (!getDerived().AlwaysRebuild() &&
719221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      T == E->getQueriedTypeSourceInfo())
719321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return SemaRef.Owned(E);
719421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
719521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult SubExpr;
719621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  {
719721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
719821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
719921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    if (SubExpr.isInvalid())
720021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      return ExprError();
720121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
720221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
720321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      return SemaRef.Owned(E);
720421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
720521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
720621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  return getDerived().RebuildArrayTypeTrait(E->getTrait(),
720721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            E->getLocStart(),
720821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            T,
720921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            SubExpr.get(),
721021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            E->getLocEnd());
721121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley}
721221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
721321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived>
721421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult
7215552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7216552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult SubExpr;
7217552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  {
7218552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7219552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7220552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    if (SubExpr.isInvalid())
7221552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      return ExprError();
7222552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7223552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7224552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      return SemaRef.Owned(E);
7225552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
7226552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7227552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  return getDerived().RebuildExpressionTrait(
7228552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7229552622067dc45013d240f73952fece703f5e63bdJohn Wiegley}
7230552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7231552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived>
7232552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult
7233865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
72342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                               DependentScopeDeclRefExpr *E) {
723500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc
723600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
723700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  if (!QualifierLoc)
7238f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
724043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
724143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
724243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
724343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
72442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
72452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
72462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
7247f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7249f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!E->hasExplicitTemplateArgs()) {
7250f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!getDerived().AlwaysRebuild() &&
725100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor        QualifierLoc == E->getQualifierLoc() &&
72522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // Note: it is sufficient to compare the Name component of NameInfo:
72532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // if name has not changed, DNLoc has not changed either.
72542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getDeclName())
72553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
72561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
725700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
72582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                         NameInfo,
7259f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         /*TemplateArgs*/ 0);
7260f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor  }
7261d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
7262d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7263fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7264fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
7265fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7266fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
7267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
726800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
72692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
7270f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       &TransArgs);
7271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
727460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7275454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
7276321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // CXXConstructExprs are always implicit, so when we have a
7277321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // 1-argument construction we just transform that argument.
7278321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  if (E->getNumArgs() == 1 ||
7279321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor      (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7280321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor    return getDerived().TransformExpr(E->getArg(0));
7281321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor
7282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7284b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
7285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
7286f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
7289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
72907c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(E->getLocStart(),
72917c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
7292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
7293f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7296ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7297aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7298aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
7299aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7300aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
7301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType() &&
7303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
7304c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor      !ArgumentChanged) {
73051af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark the constructor as referenced.
73061af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: Instantiation-specific
7307c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
73083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7309c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor  }
73101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73114411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
73124411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                              Constructor, E->isElidable(),
73138c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              move_arg(Args),
73148c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              E->requiresZeroInitialization(),
7315428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getConstructionKind(),
7316428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getParenRange());
7317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression.
7320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
73215132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
73225132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that.
7323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
732460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7325454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
73265132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
7327b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73294765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should
73304765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated.
7331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
73324765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we
73335132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that.
7334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
733560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
73364765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
73375132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
7338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
734160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
7343ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXTemporaryObjectExpr *E) {
7344ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7345ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
7346f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
7349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
7350c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                  getDerived().TransformDecl(E->getLocStart(),
73517c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
7352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
7353f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7356ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Args.reserve(E->getNumArgs());
7358aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7359aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
7360aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
73611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7363ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
7364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
736591be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      !ArgumentChanged) {
736691be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    // FIXME: Instantiation-specific
7367ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
73683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.MaybeBindToTemporary(E);
736991be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor  }
7370ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
7371ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXTemporaryObjectExpr(T,
7372ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
7373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    move_arg(Args),
7374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    E->getLocEnd());
7375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
737860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
7380454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  CXXUnresolvedConstructExpr *E) {
7381ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7382ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
7383f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7386ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7387aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->arg_size());
7388aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7389aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
7390aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7391aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
7392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7393ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
7394b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
73953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
73961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: we're faking the locations of the commas
7398ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
7399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getLParenLoc(),
7400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        move_arg(Args),
7401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getRParenLoc());
7402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
74031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
740560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7406865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
74072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                             CXXDependentScopeMemberExpr *E) {
7408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the base of the expression.
740960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
7410aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *OldBase;
7411aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
7412aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType ObjectType;
7413aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->isImplicitAccess()) {
7414aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = E->getBase();
7415aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(OldBase);
7416aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7417f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
74181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7419aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    // Start the member reference and compute the object's type.
7420b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ObjectTy;
7421d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor    bool MayBePseudoDestructor = false;
74229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7423aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                E->getOperatorLoc(),
7424a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                      E->isArrow()? tok::arrow : tok::period,
7425d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                ObjectTy,
7426d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                MayBePseudoDestructor);
7427aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7428f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7429aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
7430b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ObjectType = ObjectTy.get();
7431aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
7432aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
7433aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = 0;
7434aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(E->getBaseType());
7435aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7436aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
74371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74386cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // Transform the first part of the nested-name-specifier that qualifies
74396cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // the member name.
7440c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierInScope
74416cd219879ffce00920189ec1dcea927a42602961Douglas Gregor    = getDerived().TransformFirstQualifierInScope(
74427c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                            E->getFirstQualifierFoundInScope(),
74437c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                            E->getQualifierLoc().getBeginLoc());
74441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74457c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
7446a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  if (E->getQualifier()) {
74477c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    QualifierLoc
74487c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
74497c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     ObjectType,
74507c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     FirstQualifierInScope);
74517c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    if (!QualifierLoc)
7452f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7453a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  }
74541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
745543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
745643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
745743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
745843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
74592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
746043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
74612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
7462f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
74631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7464aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->hasExplicitTemplateArgs()) {
74653b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // This is a reference to a member without an explicitly-specified
74663b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // template argument list. Optimize for this common case.
74673b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
7468aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        Base.get() == OldBase &&
7469aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        BaseType == E->getBaseType() &&
74707c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor        QualifierLoc == E->getQualifierLoc() &&
74712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getMember() &&
74723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        FirstQualifierInScope == E->getFirstQualifierFoundInScope())
74733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
74741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
7476aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                       BaseType,
74773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->isArrow(),
74783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getOperatorLoc(),
74797c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                       QualifierLoc,
7480129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       FirstQualifierInScope,
74812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
7482129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       /*TemplateArgs*/ 0);
74833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
74843b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor
7485d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7486fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7487fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
7488fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7489fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
74901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
7492aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                     BaseType,
7493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->isArrow(),
7494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->getOperatorLoc(),
74957c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     QualifierLoc,
74963b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                     FirstQualifierInScope,
74972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                     NameInfo,
7498129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                     &TransArgs);
7499129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}
7500129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7501129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived>
750260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7503454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
7504129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform the base of the expression.
750560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
7506aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
7507aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!Old->isImplicitAccess()) {
7508aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(Old->getBase());
7509aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7510f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7511aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
7512aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
7513aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(Old->getBaseType());
7514aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
7515129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
75164c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
75174c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  if (Old->getQualifierLoc()) {
75184c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    QualifierLoc
75194c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
75204c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (!QualifierLoc)
7521f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7522129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7523129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
75242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  LookupResult R(SemaRef, Old->getMemberNameInfo(),
7525129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                 Sema::LookupOrdinaryName);
7526129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7527129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform all the decls.
7528129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7529129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         E = Old->decls_end(); I != E; ++I) {
75307c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
75317c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(Old->getMemberLoc(),
75327c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           *I));
75339f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
75349f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
75359f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
75369f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
75379f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
753834f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis      else {
753934f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis        R.clear();
7540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
754134f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis      }
75429f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
7543129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7544129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    // Expand using declarations.
7545129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (isa<UsingDecl>(InstD)) {
7546129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
7547129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7548129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall             E = UD->shadow_end(); I != E; ++I)
7549129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall        R.addDecl(*I);
7550129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      continue;
7551129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
7552129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7553129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    R.addDecl(InstD);
7554129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7555129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7556129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  R.resolveKind();
7557129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7558c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  // Determine the naming class.
7559042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth  if (Old->getNamingClass()) {
7560c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    CXXRecordDecl *NamingClass
7561c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
756266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                          Old->getMemberLoc(),
756366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
756466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
7565f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7566c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
756766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
7568c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  }
7569c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7570129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  TemplateArgumentListInfo TransArgs;
7571129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->hasExplicitTemplateArgs()) {
7572129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setLAngleLoc(Old->getLAngleLoc());
7573129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setRAngleLoc(Old->getRAngleLoc());
7574fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7575fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                Old->getNumTemplateArgs(),
7576fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
7577fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
7578129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7579c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
7580c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
7581c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
7582c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
7583c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
7584c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
7585c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
75869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
7587aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  BaseType,
7588129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getOperatorLoc(),
7589129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->isArrow(),
75904c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                                  QualifierLoc,
7591c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                                  FirstQualifierInScope,
7592129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  R,
7593129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              (Old->hasExplicitTemplateArgs()
7594129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  ? &TransArgs : 0));
7595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
759860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
75992e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7600eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
76012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
76022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (SubExpr.isInvalid())
76032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return ExprError();
76042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
76052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
76063fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
76072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
76082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
76092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}
76102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
76112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived>
76122e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult
7613be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
76144f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
76154f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (Pattern.isInvalid())
76164f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return ExprError();
76174f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
76184f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
76194f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return SemaRef.Owned(E);
76204f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
762167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
762267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                           E->getNumExpansions());
7623be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}
7624ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7625ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived>
7626ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult
7627ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7628ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // If E is not value-dependent, then nothing will change when we transform it.
7629ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: This is an instantiation-centric view.
7630ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (!E->isValueDependent())
7631ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
7632ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7633ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: None of the implementations of TryExpandParameterPacks can ever
7634ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // produce a diagnostic when given only a single unexpanded parameter pack,
7635ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // so
7636ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7637ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  bool ShouldExpand = false;
7638d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  bool RetainExpansion = false;
7639cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> NumExpansions;
7640ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7641ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                           &Unexpanded, 1,
7642d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           ShouldExpand, RetainExpansion,
7643d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           NumExpansions))
7644ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return ExprError();
7645ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7646d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  if (!ShouldExpand || RetainExpansion)
7647ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
7648be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
7649ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // We now know the length of the parameter pack, so build a new expression
7650ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // that stores that length.
7651ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7652ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                            E->getPackLoc(), E->getRParenLoc(),
7653cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                            *NumExpansions);
7654ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}
7655ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7656be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived>
7657be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult
7658c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7659c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                          SubstNonTypeTemplateParmPackExpr *E) {
7660c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Default behavior is to do nothing with this transformation.
7661c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  return SemaRef.Owned(E);
7662c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}
7663c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
7664c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived>
7665c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult
766603e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorTreeTransform<Derived>::TransformMaterializeTemporaryExpr(
766703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor                                                  MaterializeTemporaryExpr *E) {
766803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  return getDerived().TransformExpr(E->GetTemporaryExpr());
766903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor}
767003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor
767103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregortemplate<typename Derived>
767203e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorExprResult
7673454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
76743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
76771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
767860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7679454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
768081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  TypeSourceInfo *EncodedTypeInfo
768181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
768281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  if (!EncodedTypeInfo)
7683f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
76841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
768681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
76873fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
769081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                            EncodedTypeInfo,
7691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc());
7692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
76931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
7695f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>::
7696f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7697f85e193739c953358c865005855253af4f68a497John McCall  ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7698f85e193739c953358c865005855253af4f68a497John McCall  if (result.isInvalid()) return ExprError();
7699f85e193739c953358c865005855253af4f68a497John McCall  Expr *subExpr = result.take();
7700f85e193739c953358c865005855253af4f68a497John McCall
7701f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
7702f85e193739c953358c865005855253af4f68a497John McCall      subExpr == E->getSubExpr())
7703f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(E);
7704f85e193739c953358c865005855253af4f68a497John McCall
7705f85e193739c953358c865005855253af4f68a497John McCall  return SemaRef.Owned(new(SemaRef.Context)
7706f85e193739c953358c865005855253af4f68a497John McCall      ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7707f85e193739c953358c865005855253af4f68a497John McCall}
7708f85e193739c953358c865005855253af4f68a497John McCall
7709f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
7710f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>::
7711f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7712f85e193739c953358c865005855253af4f68a497John McCall  TypeSourceInfo *TSInfo
7713f85e193739c953358c865005855253af4f68a497John McCall    = getDerived().TransformType(E->getTypeInfoAsWritten());
7714f85e193739c953358c865005855253af4f68a497John McCall  if (!TSInfo)
7715f85e193739c953358c865005855253af4f68a497John McCall    return ExprError();
7716f85e193739c953358c865005855253af4f68a497John McCall
7717f85e193739c953358c865005855253af4f68a497John McCall  ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7718f85e193739c953358c865005855253af4f68a497John McCall  if (Result.isInvalid())
7719f85e193739c953358c865005855253af4f68a497John McCall    return ExprError();
7720f85e193739c953358c865005855253af4f68a497John McCall
7721f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
7722f85e193739c953358c865005855253af4f68a497John McCall      TSInfo == E->getTypeInfoAsWritten() &&
7723f85e193739c953358c865005855253af4f68a497John McCall      Result.get() == E->getSubExpr())
7724f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(E);
7725f85e193739c953358c865005855253af4f68a497John McCall
7726f85e193739c953358c865005855253af4f68a497John McCall  return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7727f85e193739c953358c865005855253af4f68a497John McCall                                      E->getBridgeKeywordLoc(), TSInfo,
7728f85e193739c953358c865005855253af4f68a497John McCall                                      Result.get());
7729f85e193739c953358c865005855253af4f68a497John McCall}
7730f85e193739c953358c865005855253af4f68a497John McCall
7731f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
773260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7733454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
773492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Transform arguments.
773592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  bool ArgChanged = false;
7736ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7737aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->getNumArgs());
7738aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7739aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
7740aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7741aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
774292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
774392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Class message: transform the receiver type.
774492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    TypeSourceInfo *ReceiverTypeInfo
774592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      = getDerived().TransformType(E->getClassReceiverTypeInfo());
774692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!ReceiverTypeInfo)
7747f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7748c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
774992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // If nothing changed, just retain the existing message send.
775092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
775192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor        ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
77523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
775392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
775492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Build a new class message send.
775592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
775692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getSelector(),
7757f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                               E->getSelectorLoc(),
775892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getMethodDecl(),
775992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getLeftLoc(),
776092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               move_arg(Args),
776192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getRightLoc());
776292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
776392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
776492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Instance message: transform the receiver
776592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
776692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         "Only class and instance messages may be instantiated");
776760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Receiver
776892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    = getDerived().TransformExpr(E->getInstanceReceiver());
776992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (Receiver.isInvalid())
7770f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
777192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
777292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // If nothing changed, just retain the existing message send.
777392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
777492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
77753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7776c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
777792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Build a new instance message send.
77789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
777992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getSelector(),
7780f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                             E->getSelectorLoc(),
778192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getMethodDecl(),
778292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getLeftLoc(),
778392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             move_arg(Args),
778492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getRightLoc());
7785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
77871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
778860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7789454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
77903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
77931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
779460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7795454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
77963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
77991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
780060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7801454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
7802f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
780360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7804f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7805f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7806f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor
7807f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // We don't need to transform the ivar; it will never change.
7808c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7809f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7810f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7811f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
78123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7813c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
78149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
7815f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->getLocation(),
7816f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->isArrow(), E->isFreeIvar());
7817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
782060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7821454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
782212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // 'super' and types never change. Property never changes. Just
782312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // retain the existing expression.
782412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (!E->isObjectReceiver())
78253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
78268ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian
7827e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // Transform the base expression.
782860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7829e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (Base.isInvalid())
7830f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7831c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7832e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // We don't need to transform the property; it will never change.
7833c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7834e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // If nothing changed, just retain the existing expression.
7835e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7836e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      Base.get() == E->getBase())
78373fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
783912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (E->isExplicitProperty())
784012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
784112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getExplicitProperty(),
784212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getLocation());
784312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall
784412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
784512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getType(),
784612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertyGetter(),
784712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertySetter(),
784812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getLocation());
7849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
785260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7853454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
7854f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
785560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7856f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7857f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7858c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7859f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7860f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7861f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
78623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7863c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
78649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
7865f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                         E->isArrow());
7866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
786960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7870454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
7871b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7872ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> SubExprs(SemaRef);
7873aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  SubExprs.reserve(E->getNumSubExprs());
7874aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7875aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  SubExprs, &ArgumentChanged))
7876aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
78771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7879b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
78803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
78811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move_arg(SubExprs),
7884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               E->getRParenLoc());
7885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
788860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7889454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
7890c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockDecl *oldBlock = E->getBlockDecl();
7891a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7892c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7893c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7894c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7895c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7896ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // We built a new blockScopeInfo in call to ActOnBlockStart
7897ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // in above, CapturesCXXThis need be set here from the block
7898ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // expression.
7899ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7900ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian
7901c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  llvm::SmallVector<ParmVarDecl*, 4> params;
7902c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  llvm::SmallVector<QualType, 4> paramTypes;
7903a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7904a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Parameter substitution.
7905c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7906c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_begin(),
7907c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_size(),
7908c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               0, paramTypes, &params))
7909a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return true;
7910c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7911c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  const FunctionType *exprFunctionType = E->getFunctionType();
7912c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType exprResultType = exprFunctionType->getResultType();
7913c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!exprResultType.isNull()) {
7914c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    if (!exprResultType->isDependentType())
7915c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      blockScope->ReturnType = exprResultType;
7916c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    else if (exprResultType != getSema().Context.DependentTy)
7917c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      blockScope->ReturnType = getDerived().TransformType(exprResultType);
7918a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7919a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7920a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type has not been determined yet, leave it as a dependent
7921a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // type; it'll get set when we process the body.
7922c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType.isNull())
7923c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->ReturnType = getSema().Context.DependentTy;
7924a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7925a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // Don't allow returning a objc interface by value.
7926c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType->isObjCObjectType()) {
7927c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    getSema().Diag(E->getCaretLocation(),
7928a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                   diag::err_object_cannot_be_passed_returned_by_value)
7929c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      << 0 << blockScope->ReturnType;
7930a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return ExprError();
7931a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  }
7932711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7933c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType functionType = getDerived().RebuildFunctionProtoType(
7934c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        blockScope->ReturnType,
7935c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.data(),
7936c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.size(),
7937c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        oldBlock->isVariadic(),
7938c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                        0, RQ_None,
7939c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               exprFunctionType->getExtInfo());
7940c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->FunctionType = functionType;
7941711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7942711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Set the parameters on the block decl.
7943c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!params.empty())
7944c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->TheDecl->setParams(params.data(), params.size());
7945a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7946a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type wasn't explicitly set, it will have been marked as a
7947a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // dependent type (DependentTy); clear out the return type setting so
7948a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // we will deduce the return type when type-checking the block's body.
7949c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType == getSema().Context.DependentTy)
7950c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->ReturnType = QualType();
7951a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7952711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Transform the body
7953c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  StmtResult body = getDerived().TransformStmt(E->getBody());
7954c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (body.isInvalid())
7955711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    return ExprError();
7956711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7957c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG
7958c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // In builds with assertions, make sure that we captured everything we
7959c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // captured before.
7960fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor  if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7961fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor    for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7962fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor           e = oldBlock->capture_end(); i != e; ++i) {
7963fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      VarDecl *oldCapture = i->getVariable();
7964fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor
7965fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      // Ignore parameter packs.
7966fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      if (isa<ParmVarDecl>(oldCapture) &&
7967fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor          cast<ParmVarDecl>(oldCapture)->isParameterPack())
7968fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor        continue;
7969c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7970fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      VarDecl *newCapture =
7971fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor        cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7972fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor                                                 oldCapture));
7973fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      assert(blockScope->CaptureMap.count(newCapture));
7974fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor    }
7975c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  }
7976c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif
7977c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7978c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7979c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                    /*Scope=*/0);
7980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
79821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
798360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7984454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
7985a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  ValueDecl *ND
7986a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7987a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                       E->getDecl()));
7988a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!ND)
7989f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
79902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
7991a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!getDerived().AlwaysRebuild() &&
7992a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      ND == E->getDecl()) {
7993a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // Mark it referenced in the new context regardless.
7994a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // FIXME: this is a bit instantiation-specific.
7995a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7996a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
79973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7998a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7999a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
80002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
800140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
80022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, 0);
8003b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
80041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
800561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnertemplate<typename Derived>
800661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerExprResult
800761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
800861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  assert(false && "Cannot transform asType expressions yet");
800961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  return SemaRef.Owned(E);
801061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}
801161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner
8012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
8013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction
8014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
8015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
801785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
801885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                    SourceLocation Star) {
80192865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildPointerType(PointeeType, Star,
8020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  getDerived().getBaseEntity());
8021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
802485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
802585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                         SourceLocation Star) {
80262865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildBlockPointerType(PointeeType, Star,
8027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       getDerived().getBaseEntity());
8028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
80311eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
803285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
803385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             bool WrittenAsLValue,
803485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             SourceLocation Sigil) {
80352865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
803685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    Sigil, getDerived().getBaseEntity());
8037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
80401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
804185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
804285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 QualType ClassType,
804385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceLocation Sigil) {
80442865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
804585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        Sigil, getDerived().getBaseEntity());
8046577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8047577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8048577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80491eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
8050577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8051577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         ArrayType::ArraySizeModifier SizeMod,
8052577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         const llvm::APInt *Size,
8053577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         Expr *SizeExpr,
8054577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         unsigned IndexTypeQuals,
8055577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         SourceRange BracketsRange) {
8056577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (SizeExpr || !Size)
8057577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8058577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  IndexTypeQuals, BracketsRange,
8059577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  getDerived().getBaseEntity());
80601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType Types[] = {
80621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
80631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
80641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
8065577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  };
8066577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8067577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType SizeType;
8068577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  for (unsigned I = 0; I != NumTypes; ++I)
8069577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8070577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      SizeType = Types[I];
8071577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      break;
8072577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    }
80731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
80759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                           /*FIXME*/BracketsRange.getBegin());
80761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
8077577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                IndexTypeQuals, BracketsRange,
80781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                getDerived().getBaseEntity());
8079577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
80801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8081577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80821eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
80831eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
8084577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 ArrayType::ArraySizeModifier SizeMod,
8085577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 const llvm::APInt &Size,
808685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
808785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceRange BracketsRange) {
80881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
808985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        IndexTypeQuals, BracketsRange);
8090577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8091577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8092577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80931eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
80941eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
8095577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
809685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
809785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   SourceRange BracketsRange) {
80981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
809985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                       IndexTypeQuals, BracketsRange);
8100577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8102577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81031eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81041eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
8105577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
81069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SizeExpr,
8107577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 unsigned IndexTypeQuals,
8108577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceRange BracketsRange) {
81091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
81109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
8111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
8112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81151eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81161eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
8117577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
81189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Expr *SizeExpr,
8119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                       unsigned IndexTypeQuals,
8120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                   SourceRange BracketsRange) {
81211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
81229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
8123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
8124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
8128e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               unsigned NumElements,
8129e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               VectorType::VectorKind VecKind) {
8130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  // FIXME: semantic checking!
8131e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
8132577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                      unsigned NumElements,
8137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceLocation AttributeLoc) {
8138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                          NumElements, true);
8140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  IntegerLiteral *VectorSize
81419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
81429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             AttributeLoc);
81439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
8144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81471eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81481eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
81499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                           Expr *SizeExpr,
8150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                  SourceLocation AttributeLoc) {
81519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
8152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8155577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
81561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          QualType *ParamTypes,
8157577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                        unsigned NumParamTypes,
81581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          bool Variadic,
8159fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                          unsigned Quals,
8160c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                  RefQualifierKind RefQualifier,
8161fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                            const FunctionType::ExtInfo &Info) {
81621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
8163c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                   Quals, RefQualifier,
8164577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   getDerived().getBaseLocation(),
8165fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   getDerived().getBaseEntity(),
8166fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   Info);
8167577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8169577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8170a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8171a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return SemaRef.Context.getFunctionNoProtoType(T);
8172a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
8173a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
8174a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
8175ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8176ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  assert(D && "no decl found");
8177ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (D->isInvalidDecl()) return QualType();
8178ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
817992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // FIXME: Doesn't account for ObjCInterfaceDecl!
8180ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeDecl *Ty;
8181ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (isa<UsingDecl>(D)) {
8182ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    UsingDecl *Using = cast<UsingDecl>(D);
8183ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(Using->isTypeName() &&
8184ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-typename using");
8185ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8186ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    // A valid resolved using typename decl points to exactly one type decl.
8187ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(++Using->shadow_begin() == Using->shadow_end());
8188ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
8189c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8190ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  } else {
8191ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8192ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-using decl");
8193ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<UnresolvedUsingTypenameDecl>(D);
8194ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
8195ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8196ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return SemaRef.Context.getTypeDeclType(Ty);
8197ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
8198ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8199ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived>
82002a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
82012a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                       SourceLocation Loc) {
82022a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildTypeofExprType(E, Loc);
8203577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8204577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8205577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8206577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8207577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  return SemaRef.Context.getTypeOfType(Underlying);
8208577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8209577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8210577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
82112a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
82122a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                     SourceLocation Loc) {
82132a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildDecltypeType(E, Loc);
8214577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8215577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8216577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8217ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8218ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                            UnaryTransformType::UTTKind UKind,
8219ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                            SourceLocation Loc) {
8220ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8221ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
8222ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
8223ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived>
8224577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
8225833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                      TemplateName Template,
8226833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateNameLoc,
822767714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                     TemplateArgumentListInfo &TemplateArgs) {
8228d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
8229577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
82301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8231dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
82321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
8233fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8234d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            bool TemplateKW,
8235d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            TemplateDecl *Template) {
8236fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
8237d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                                  Template);
8238d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
8239d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
8240d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
82411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
8242fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8243fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            const IdentifierInfo &Name,
8244fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SourceLocation NameLoc,
824543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            QualType ObjectType,
824643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            NamedDecl *FirstQualifierInScope) {
8247fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  UnqualifiedId TemplateName;
8248fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName.setIdentifier(&Name, NameLoc);
8249d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
8250d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
8251fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       /*FIXME:*/SourceLocation(),
8252d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
8253fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       TemplateName,
8254b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
8255d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
8256d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
825743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return Template.get();
8258d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
82591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
8261ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName
8262fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8263ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            OverloadedOperatorKind Operator,
8264fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SourceLocation NameLoc,
8265ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            QualType ObjectType) {
8266ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  UnqualifiedId Name;
8267fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  // FIXME: Bogus location information.
8268fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8269fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
8270d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
8271d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
8272fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       /*FIXME:*/SourceLocation(),
8273d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
8274d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
8275b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
8276d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
8277d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
8278d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  return Template.template getAsVal<TemplateName>();
8279ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor}
8280c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8281ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived>
828260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8284b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   SourceLocation OpLoc,
82859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *OrigCallee,
82869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *First,
82879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *Second) {
82889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Callee = OrigCallee->IgnoreParenCasts();
82899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
82901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Determine whether this should be a builtin operation.
8292f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript) {
82939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
82949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType())
82959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinArraySubscriptExpr(First,
82969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Callee->getLocStart(),
82979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Second, OpLoc);
82981a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman  } else if (Op == OO_Arrow) {
82991a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman    // -> is never a builtin operation.
83009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
83019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  } else if (Second == 0 || isPostIncDec) {
83029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType()) {
8303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // The argument is not of overloadable type, so try to create a
8304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // built-in unary operation.
83052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      UnaryOperatorKind Opc
8306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor        = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
83071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
8309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
8310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  } else {
83119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
83129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType()) {
8313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // Neither of the arguments is an overloadable type, so try to
8314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // create a built-in binary operation.
83152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
831660d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Result
83179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
8318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Result.isInvalid())
8319f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
83201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      return move(Result);
8322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
8323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
83241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Compute the transformed set of functions (and function templates) to be
8326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // used during overload resolution.
83276e26689f5d513e24ad7783a4493201930fdeccc0John McCall  UnresolvedSet<16> Functions;
83281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
8330ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    assert(ULE->requiresADL());
8331ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
8332ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // FIXME: Do we have to check
8333ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // IsAcceptableNonMemberOperatorCandidate for each of these?
83346e26689f5d513e24ad7783a4493201930fdeccc0John McCall    Functions.append(ULE->decls_begin(), ULE->decls_end());
8335ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  } else {
83369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
8337ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
83381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Add any functions found via argument-dependent lookup.
83409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Args[2] = { First, Second };
83419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  unsigned NumArgs = 1 + (Second != 0);
83421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for unary operators.
8344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (NumArgs == 1 || isPostIncDec) {
83452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    UnaryOperatorKind Opc
8346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
83479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
8348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
83491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8350f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript)
83519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
8352ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                                      OpLoc,
83539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      First,
83549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Second);
8355f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl
8356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for binary operators.
83572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
835860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result
8359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Result.isInvalid())
8361f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
83621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return move(Result);
8364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
83651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
836626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived>
836760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
83689ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
836926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceLocation OperatorLoc,
837026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       bool isArrow,
8371f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                                       CXXScopeSpec &SS,
837226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     TypeSourceInfo *ScopeType,
837326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       SourceLocation CCLoc,
8374fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                       SourceLocation TildeLoc,
8375a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed) {
83769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  QualType BaseType = Base->getType();
83779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
837826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      (!isArrow && !BaseType->getAs<RecordType>()) ||
8379c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      (isArrow && BaseType->getAs<PointerType>() &&
8380bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif       !BaseType->getAs<PointerType>()->getPointeeType()
8381bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif                                              ->template getAs<RecordType>())){
838226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    // This pseudo-destructor expression is still a pseudo-destructor.
83839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
838426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             isArrow? tok::arrow : tok::period,
8385fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                             SS, ScopeType, CCLoc, TildeLoc,
8386a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                             Destroyed,
838726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             /*FIXME?*/true);
838826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
83892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
8390a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
83912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
83922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
83932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
83942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  NameInfo.setNamedTypeInfo(DestroyedType);
83952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
839626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  // FIXME: the ScopeType should be tacked onto SS.
83972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
83989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getSema().BuildMemberReferenceExpr(Base, BaseType,
839926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            OperatorLoc, isArrow,
840026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            SS, /*FIXME: FirstQualifier*/ 0,
84012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            NameInfo,
840226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            /*TemplateArgs*/ 0);
840326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor}
840426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
8405577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang
8406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8407577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
8408