TreeTransform.h revision e559ca1672ecef59345a928af0a6809b09282d2c
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,
1550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Inits,
1551e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   SourceLocation RBraceLoc,
1552e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   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      }
2479dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2480dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // The transform has determined that we should perform an elementwise
2481dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // expansion of the pattern. Do so.
2482cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
2483dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2484dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().TransformExpr(Pattern);
2485dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2486dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2487dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
248877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.get()->containsUnexpandedParameterPack()) {
248967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor          Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
249067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                     OrigNumExpansions);
249177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.isInvalid())
249277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
249377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
249477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
2495dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (ArgChanged)
2496dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          *ArgChanged = true;
2497dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2498dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2499dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2500dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      continue;
2501dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    }
2502dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2503aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2504aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.isInvalid())
2505aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return true;
2506aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2507aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.get() != Inputs[I] && ArgChanged)
2508aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      *ArgChanged = true;
2509aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2510aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    Outputs.push_back(Result.get());
2511aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
2512aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2513aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  return false;
2514aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor}
2515aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2516aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived>
2517c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc
2518c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2519c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                    NestedNameSpecifierLoc NNS,
2520c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                     QualType ObjectType,
2521c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                             NamedDecl *FirstQualifierInScope) {
2522c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2523c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2524c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor       Qualifier = Qualifier.getPrefix())
2525c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Qualifiers.push_back(Qualifier);
2526c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2527c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  CXXScopeSpec SS;
2528c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  while (!Qualifiers.empty()) {
2529c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2530c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2531c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2532c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    switch (QNNS->getKind()) {
2533c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Identifier:
2534c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2535c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              *QNNS->getAsIdentifier(),
2536c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              Q.getLocalBeginLoc(),
2537c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              Q.getLocalEndLoc(),
2538c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              ObjectType, false, SS,
2539c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              FirstQualifierInScope, false))
2540c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        return NestedNameSpecifierLoc();
2541c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2542c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2543c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2544c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Namespace: {
2545c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      NamespaceDecl *NS
2546c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        = cast_or_null<NamespaceDecl>(
2547c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                    getDerived().TransformDecl(
2548c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                          Q.getLocalBeginLoc(),
2549c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                       QNNS->getAsNamespace()));
2550c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2551c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2552c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
2553c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2554c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::NamespaceAlias: {
2555c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      NamespaceAliasDecl *Alias
2556c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        = cast_or_null<NamespaceAliasDecl>(
2557c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                      getDerived().TransformDecl(Q.getLocalBeginLoc(),
2558c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                 QNNS->getAsNamespaceAlias()));
2559c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2560c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                Q.getLocalEndLoc());
2561c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2562c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
2563c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2564c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Global:
2565c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      // There is no meaningful transformation that one could perform on the
2566c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      // global scope.
2567c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2568c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2569c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2570c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::TypeSpecWithTemplate:
2571c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::TypeSpec: {
2572c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2573c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              FirstQualifierInScope, SS);
2574c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2575c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (!TL)
2576c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        return NestedNameSpecifierLoc();
2577c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2578c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2579c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor          (SemaRef.getLangOptions().CPlusPlus0x &&
2580c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor           TL.getType()->isEnumeralType())) {
2581c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        assert(!TL.getType().hasLocalQualifiers() &&
2582c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor               "Can't get cv-qualifiers here");
2583c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2584c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                  Q.getLocalEndLoc());
2585c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        break;
2586c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      }
258700c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      // If the nested-name-specifier is an invalid type def, don't emit an
258800c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      // error because a previous error should have already been emitted.
258900c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
259000c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
259100c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu        SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
259200c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu          << TL.getType() << SS.getRange();
259300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      }
2594c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      return NestedNameSpecifierLoc();
2595c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
25967c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    }
2597c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
25987c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    // The qualifier-in-scope and object type only apply to the leftmost entity.
2599c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    FirstQualifierInScope = 0;
26007c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    ObjectType = QualType();
2601c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  }
2602c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2603c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // Don't rebuild the nested-name-specifier if we don't have to.
2604c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2605c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      !getDerived().AlwaysRebuild())
2606c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    return NNS;
2607c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2608c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // If we can re-use the source-location data from the original
2609c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // nested-name-specifier, do so.
2610c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (SS.location_size() == NNS.getDataLength() &&
2611c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2612c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2613c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2614c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // Allocate new nested-name-specifier location information.
2615c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  return SS.getWithLocInContext(SemaRef.Context);
2616c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor}
2617c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2618c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived>
26192577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo
26202577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived>
262143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
26222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name = NameInfo.getName();
262381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  if (!Name)
26242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo();
262581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
262681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  switch (Name.getNameKind()) {
262781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::Identifier:
262881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCZeroArgSelector:
262981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCOneArgSelector:
263081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCMultiArgSelector:
263181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXOperatorName:
26323e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  case DeclarationName::CXXLiteralOperatorName:
263381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXUsingDirective:
26342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NameInfo;
26351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
263681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConstructorName:
263781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXDestructorName:
263881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConversionFunctionName: {
26392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *NewTInfo;
26402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CanQualType NewCanTy;
26412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
264243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewTInfo = getDerived().TransformType(OldTInfo);
264343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NewTInfo)
264443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall        return DeclarationNameInfo();
264543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
26462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
26472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    else {
26482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewTInfo = 0;
26492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
265043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      QualType NewT = getDerived().TransformType(Name.getCXXNameType());
26512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      if (NewT.isNull())
26522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        return DeclarationNameInfo();
26532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewCanTy = SemaRef.Context.getCanonicalType(NewT);
26542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
26551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationName NewName
26572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
26582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                           NewCanTy);
26592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NewNameInfo(NameInfo);
26602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setName(NewName);
26612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setNamedTypeInfo(NewTInfo);
26622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NewNameInfo;
266381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  }
26641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
26651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  assert(0 && "Unknown name kind.");
26672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return DeclarationNameInfo();
266881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor}
266981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
267081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived>
26711eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
2672fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2673fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              TemplateName Name,
2674fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              SourceLocation NameLoc,
2675fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              QualType ObjectType,
2676fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              NamedDecl *FirstQualifierInScope) {
2677fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2678fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *Template = QTN->getTemplateDecl();
2679fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    assert(Template && "qualified template name must refer to a template");
2680fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2681fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *TransTemplate
2682fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2683fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                                              Template));
2684fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransTemplate)
2685fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2686fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2687fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2688fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        SS.getScopeRep() == QTN->getQualifier() &&
2689fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransTemplate == Template)
2690fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2691fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2692fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2693fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            TransTemplate);
2694fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2695fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2696fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2697fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (SS.getScopeRep()) {
2698fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      // These apply to the scope specifier, not the template.
2699fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      ObjectType = QualType();
2700fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      FirstQualifierInScope = 0;
2701fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    }
2702fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2703fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2704fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        SS.getScopeRep() == DTN->getQualifier() &&
2705fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        ObjectType.isNull())
2706fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2707fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2708fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (DTN->isIdentifier()) {
2709fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return getDerived().RebuildTemplateName(SS,
2710fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              *DTN->getIdentifier(),
2711fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              NameLoc,
2712fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              ObjectType,
2713fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              FirstQualifierInScope);
2714fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    }
2715fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2716fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2717fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            ObjectType);
2718fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2719fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2720fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2721fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *TransTemplate
2722fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2723fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                                              Template));
2724fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransTemplate)
2725fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2726fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2727fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2728fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransTemplate == Template)
2729fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2730fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2731fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return TemplateName(TransTemplate);
2732fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2733fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2734fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (SubstTemplateTemplateParmPackStorage *SubstPack
2735fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = Name.getAsSubstTemplateTemplateParmPack()) {
2736fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateTemplateParmDecl *TransParam
2737fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    = cast_or_null<TemplateTemplateParmDecl>(
2738fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor            getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2739fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransParam)
2740fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2741fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2742fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2743fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransParam == SubstPack->getParameterPack())
2744fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2745fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2746fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(TransParam,
2747fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SubstPack->getArgumentPack());
2748fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2749fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2750fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  // These should be getting filtered out before they reach the AST.
2751fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  llvm_unreachable("overloaded function decl survived to here");
2752fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  return TemplateName();
2753fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor}
2754fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2755fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived>
2756833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc(
2757833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgument &Arg,
2758833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2759833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation Loc = getDerived().getBaseLocation();
2760670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  switch (Arg.getKind()) {
2761670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Null:
27629f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("null template argument in TreeTransform");
2763833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2764833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2765833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
2766833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg,
2767a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall               SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2768c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2769833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2770833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2771788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
2772b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor  case TemplateArgument::TemplateExpansion: {
2773b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    NestedNameSpecifierLocBuilder Builder;
2774b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    TemplateName Template = Arg.getAsTemplate();
2775b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2776b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2777b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2778b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2779b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
2780b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (Arg.getKind() == TemplateArgument::Template)
2781b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Output = TemplateArgumentLoc(Arg,
2782b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Builder.getWithLocInContext(SemaRef.Context),
2783b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Loc);
2784b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    else
2785b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Output = TemplateArgumentLoc(Arg,
2786b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Builder.getWithLocInContext(SemaRef.Context),
2787b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Loc, Loc);
2788b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
2789a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    break;
2790b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor  }
2791a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2792833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
2793833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2794833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2795833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2796833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
2797670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Integral:
2798833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
2799828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2800833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2801833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
2802833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
2803833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2804833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived>
2805833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument(
2806833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgumentLoc &Input,
2807833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2808833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgument &Arg = Input.getArgument();
2809833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
2810833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
2811833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
2812833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = Input;
2813833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
28141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2815670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Type: {
2816a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *DI = Input.getTypeSourceInfo();
2817833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (DI == NULL)
2818a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall      DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2819833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2820833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    DI = getDerived().TransformType(DI);
2821833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!DI) return true;
2822833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2823833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2824833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2825670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2827670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Declaration: {
2828833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // FIXME: we should never have to transform one of these.
2829972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    DeclarationName Name;
2830972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2831972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor      Name = ND->getDeclName();
2832788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemporaryBase Rebase(*this, Input.getLocation(), Name);
28337c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2834833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!D) return true;
2835833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2836828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Expr *SourceExpr = Input.getSourceDeclExpression();
2837828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    if (SourceExpr) {
2838828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      EnterExpressionEvaluationContext Unevaluated(getSema(),
2839f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Sema::Unevaluated);
284060d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(SourceExpr);
28419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      SourceExpr = (E.isInvalid() ? 0 : E.take());
2842828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    }
2843828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
2844828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2845833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2846670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2848788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template: {
2849b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2850b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (QualifierLoc) {
2851b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2852b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      if (!QualifierLoc)
2853b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor        return true;
2854b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    }
2855b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
28561d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    CXXScopeSpec SS;
28571d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    SS.Adopt(QualifierLoc);
2858788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemplateName Template
28591d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor      = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
28601d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor                                           Input.getTemplateNameLoc());
2861788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    if (Template.isNull())
2862788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      return true;
2863c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2864b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
2865788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateNameLoc());
2866788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return false;
2867788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  }
2868a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2869a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor  case TemplateArgument::TemplateExpansion:
2870a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    llvm_unreachable("Caller should expand pack expansions");
2871a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2872670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Expression: {
2873670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    // Template argument expressions are not potentially evaluated.
28741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EnterExpressionEvaluationContext Unevaluated(getSema(),
2875f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                 Sema::Unevaluated);
28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2877833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Expr *InputExpr = Input.getSourceExpression();
2878833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2879833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2880223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner    ExprResult E = getDerived().TransformExpr(InputExpr);
2881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (E.isInvalid()) return true;
28829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2883833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2884670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2886670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Pack: {
2887670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2888670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    TransformedArgs.reserve(Arg.pack_size());
28891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2890670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor                                      AEnd = Arg.pack_end();
2891670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor         A != AEnd; ++A) {
28921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2893833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // FIXME: preserve source information here when we start
2894833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // caring about parameter packs.
2895833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2896828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc InputArg;
2897828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc OutputArg;
2898828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      getDerived().InventTemplateArgumentLoc(*A, InputArg);
2899828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2900833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall        return true;
2901833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2902828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TransformedArgs.push_back(OutputArg.getArgument());
2903670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    }
2904910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
2905910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    TemplateArgument *TransformedArgsPtr
2906910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2907910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2908910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor              TransformedArgsPtr);
2909910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2910910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                                  TransformedArgs.size()),
2911910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                 Input.getLocInfo());
2912833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2913670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
2914670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
29151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2916670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Work around bogus GCC warning
2917833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return true;
2918670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor}
2919670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
29207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information
29217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator.
29227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator>
29237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator {
29247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TreeTransform<Derived> &Self;
29257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  InputIterator Iter;
29267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic:
29287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc value_type;
29297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc reference;
29307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef typename std::iterator_traits<InputIterator>::difference_type
29317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    difference_type;
29327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef std::input_iterator_tag iterator_category;
29337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class pointer {
29357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Arg;
2936fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
29387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
29397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    const TemplateArgumentLoc *operator->() const { return &Arg; }
29417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
29427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator() { }
29447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
29467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                             InputIterator Iter)
29477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    : Self(Self), Iter(Iter) { }
29487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator &operator++() {
29507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++Iter;
29517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return *this;
2952fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  }
2953fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator operator++(int) {
29557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocInventIterator Old(*this);
29567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++(*this);
29577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Old;
29587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  reference operator*() const {
29617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Result;
29627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    Self.InventTemplateArgumentLoc(*Iter, Result);
29637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Result;
29647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  pointer operator->() const { return pointer(**this); }
29677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator==(const TemplateArgumentLocInventIterator &X,
29697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
29707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter == Y.Iter;
29717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
2972fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator!=(const TemplateArgumentLocInventIterator &X,
29747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
29757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter != Y.Iter;
29767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor};
29787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29797f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived>
29807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator>
29817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
29827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                        InputIterator Last,
29837f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor                                            TemplateArgumentListInfo &Outputs) {
29847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  for (; First != Last; ++First) {
29857f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    TemplateArgumentLoc Out;
29867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc In = *First;
29878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().getKind() == TemplateArgument::Pack) {
29898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Unpack argument packs, which we translate them into separate
29908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // arguments.
29917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // FIXME: We could do much better if we could guarantee that the
29927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // TemplateArgumentLocInfo for the pack expansion would be usable for
29937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // all of the template arguments in the argument pack.
29947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      typedef TemplateArgumentLocInventIterator<Derived,
29957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                TemplateArgument::pack_iterator>
29967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        PackLocIterator;
29977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      if (TransformTemplateArguments(PackLocIterator(*this,
29987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                 In.getArgument().pack_begin()),
29997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     PackLocIterator(*this,
30007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                   In.getArgument().pack_end()),
30017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     Outputs))
30027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return true;
30038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
30058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
30068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().isPackExpansion()) {
30088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // We have a pack expansion, for which we will be substituting into
30098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // the pattern.
30108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      SourceLocation Ellipsis;
3011cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> OrigNumExpansions;
30128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      TemplateArgumentLoc Pattern
3013cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3014cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                     getSema().Context);
30158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
30178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
30188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
30198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
30218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // be expanded.
30228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      bool Expand = true;
3023d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3024cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
30258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (getDerived().TryExpandParameterPacks(Ellipsis,
30268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Pattern.getSourceRange(),
30278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.data(),
30288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.size(),
3029d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand,
3030d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3031d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
30328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return true;
30338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (!Expand) {
30358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // The transform has determined that we should perform a simple
30368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // transformation on the pack expansion, producing another pack
30378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // expansion.
30388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        TemplateArgumentLoc OutPattern;
30398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
30408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
30418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
3043cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3044cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                NumExpansions);
30458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (Out.getArgument().isNull())
30468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
30498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        continue;
30508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
30518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // The transform has determined that we should perform an elementwise
30538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // expansion of the pattern. Do so.
3054cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
30558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
30568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
30588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
306077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.getArgument().containsUnexpandedParameterPack()) {
3061cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3062cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                  OrigNumExpansions);
306377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.getArgument().isNull())
306477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
306577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
306677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
30678491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
30688491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
30698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30703cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
30713cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
30723cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
30733cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
30743cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
30753cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
30763cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
30773cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
3078cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3079cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                OrigNumExpansions);
30803cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (Out.getArgument().isNull())
30813cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
30823cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
30833cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        Outputs.addArgument(Out);
30843cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
3085d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
30868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
30878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
30888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    // The simple case:
30908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (getDerived().TransformTemplateArgument(In, Out))
30917f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor      return true;
30927f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
30937f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    Outputs.addArgument(Out);
30947f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  }
30957f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
30967f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  return false;
30977f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
30987f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor}
30997f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
3100577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
3101577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation
3102577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
3103577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3104577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
310543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) {
3106577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (getDerived().AlreadyTransformed(T))
3107577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T;
31081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3109a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Temporary workaround.  All of these transformations should
3110a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // eventually turn into transformations on TypeLocs.
3111c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3112c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor                                                getDerived().getBaseLocation());
3113c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
311443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
31151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3116a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (!NewDI)
3117a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
31181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3119a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return NewDI->getType();
3120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
312343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3124a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlreadyTransformed(DI->getType()))
3125a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return DI;
31261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLocBuilder TLB;
31281bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
3129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLoc TL = DI->getTypeLoc();
3130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TLB.reserve(TL.getFullDataSize());
31311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
313243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, TL);
3133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return 0;
31351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3136a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3140a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
314143fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  switch (T.getTypeLocClass()) {
3143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
3144a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \
3145a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  case TypeLoc::CLASS: \
314643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
3148a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
31509f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("unhandled type loc!");
3151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return QualType();
3152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types
3155a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers
3156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function
3157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but
3158a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients.
31591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
31601eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3161a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
316243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               QualifiedTypeLoc T) {
3163a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers Quals = T.getType().getLocalQualifiers();
3164a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
316543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3167577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
31681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3169a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Silently suppress qualifiers if the result type can't be qualified.
3170a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: this is the right thing for template instantiation, but
3171a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // probably not for other clients.
3172a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result->isFunctionType() || Result->isReferenceType())
3173a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return Result;
31741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3175f85e193739c953358c865005855253af4f68a497John McCall  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3176e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  // resulting type.
3177e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  if (Quals.hasObjCLifetime()) {
3178e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3179e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      Quals.removeObjCLifetime();
3180e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    else if (Result.getObjCLifetime() &&
3181e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor             Result.getObjCLifetime() != Quals.getObjCLifetime()) {
3182e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      // Objective-C ARC:
3183e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      //   A lifetime qualifier applied to a substituted template parameter
3184e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      //   overrides the lifetime qualifier from the template argument.
3185e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      if (const SubstTemplateTypeParmType *SubstTypeParam
3186e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3187e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        QualType Replacement = SubstTypeParam->getReplacementType();
3188e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Qualifiers Qs = Replacement.getQualifiers();
3189e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Qs.removeObjCLifetime();
3190e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Replacement
3191e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor          = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3192e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                             Qs);
3193e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Result = SemaRef.Context.getSubstTemplateTypeParmType(
3194e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                        SubstTypeParam->getReplacedParameter(),
3195e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                                              Replacement);
3196e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        TLB.TypeWasModifiedSafely(Result);
3197e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      } else {
3198e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        // Otherwise, drop the new qualifier.
3199e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        // FIXME: I don't recall the justification for this!
3200e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Quals.removeObjCLifetime();
3201e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      }
3202e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    }
3203e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  }
32042865474261a608c7873b87ba4af110d17907896dJohn McCall  if (!Quals.empty()) {
32052865474261a608c7873b87ba4af110d17907896dJohn McCall    Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
32062865474261a608c7873b87ba4af110d17907896dJohn McCall    TLB.push<QualifiedTypeLoc>(Result);
32072865474261a608c7873b87ba4af110d17907896dJohn McCall    // No location information to preserve.
32082865474261a608c7873b87ba4af110d17907896dJohn McCall  }
3209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3211a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
321343fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
3214b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc
3215b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
321643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
321743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
3218b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                   CXXScopeSpec &SS) {
3219b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  QualType T = TL.getType();
322043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
3221b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TL;
3222b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
322343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeLocBuilder TLB;
322443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result;
3225b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
322643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (isa<TemplateSpecializationType>(T)) {
3227b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateSpecializationTypeLoc SpecTL
3228b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = cast<TemplateSpecializationTypeLoc>(TL);
3229b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
323043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateName Template =
3231b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      getDerived().TransformTemplateName(SS,
3232b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getTypePtr()->getTemplateName(),
3233b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getTemplateNameLoc(),
323443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         ObjectType, UnqualLookup);
3235b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    if (Template.isNull())
3236b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return TypeLoc();
3237b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3238b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3239b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                              Template);
324043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else if (isa<DependentTemplateSpecializationType>(T)) {
3241b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
3242b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = cast<DependentTemplateSpecializationTypeLoc>(TL);
3243a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
3244b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateName Template
3245b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = getDerived().RebuildTemplateName(SS,
3246b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         *SpecTL.getTypePtr()->getIdentifier(),
3247b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getNameLoc(),
3248b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         ObjectType, UnqualLookup);
3249a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    if (Template.isNull())
3250b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return TypeLoc();
3251b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3252b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3253b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                                       SpecTL,
3254087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                     Template,
3255087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       SS);
325643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else {
325743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    // Nothing special needs to be done for these.
3258b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformType(TLB, TL);
325943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
3260b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3261b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  if (Result.isNull())
3262b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TypeLoc();
3263b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3264b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
326543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
326643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
3267c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived>
3268b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo *
3269b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3270c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   QualType ObjectType,
3271c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   NamedDecl *UnqualLookup,
3272c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   CXXScopeSpec &SS) {
3273c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // FIXME: Painfully copy-paste from the above!
3274c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3275b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  QualType T = TSInfo->getType();
3276c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (getDerived().AlreadyTransformed(T))
3277b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TSInfo;
3278c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3279c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  TypeLocBuilder TLB;
3280c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  QualType Result;
3281c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3282b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  TypeLoc TL = TSInfo->getTypeLoc();
3283c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (isa<TemplateSpecializationType>(T)) {
3284c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    TemplateSpecializationTypeLoc SpecTL
3285c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      = cast<TemplateSpecializationTypeLoc>(TL);
3286c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3287b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateName Template
3288b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    = getDerived().TransformTemplateName(SS,
3289fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getTypePtr()->getTemplateName(),
3290fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getTemplateNameLoc(),
3291c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                         ObjectType, UnqualLookup);
3292c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    if (Template.isNull())
3293b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return 0;
3294c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3295c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3296c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                              Template);
3297c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  } else if (isa<DependentTemplateSpecializationType>(T)) {
3298c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
3299c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      = cast<DependentTemplateSpecializationTypeLoc>(TL);
3300c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3301a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    TemplateName Template
3302fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = getDerived().RebuildTemplateName(SS,
33037c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                         *SpecTL.getTypePtr()->getIdentifier(),
3304fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getNameLoc(),
33057c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                         ObjectType, UnqualLookup);
3306a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    if (Template.isNull())
3307b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return 0;
3308a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
3309c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3310a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                                       SpecTL,
3311087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       Template,
3312087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       SS);
3313c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  } else {
3314c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    // Nothing special needs to be done for these.
3315c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformType(TLB, TL);
3316c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  }
3317c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3318c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (Result.isNull())
3319b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return 0;
3320c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3321b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3322c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor}
3323c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3324a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline
3325a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3326a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TyLoc NewT = TLB.push<TyLoc>(T.getType());
3327a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewT.setNameLoc(T.getNameLoc());
3328a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return T.getType();
3329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3330a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3332a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
333343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      BuiltinTypeLoc T) {
3334ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3335ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  NewT.setBuiltinLoc(T.getBuiltinLoc());
3336ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (T.needsExtraLocalData())
3337ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3338ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  return T.getType();
3339577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3340577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
33411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3342a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
334343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ComplexTypeLoc T) {
3344a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: recurse?
3345a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, T);
3346a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
33471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3348a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3349a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
335043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      PointerTypeLoc TL) {
3351c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType PointeeType
3352c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
335392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (PointeeType.isNull())
335492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return QualType();
335592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
335692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  QualType Result = TL.getType();
3357c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (PointeeType->getAs<ObjCObjectType>()) {
335892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // A dependent pointer type 'T *' has is being transformed such
335992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // that an Objective-C class type is being replaced for 'T'. The
336092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // resulting pointer type is an ObjCObjectPointerType, not a
336192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // PointerType.
3362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3363c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3364c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3365c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NewT.setStarLoc(TL.getStarLoc());
336692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return Result;
336792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
336843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
336992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (getDerived().AlwaysRebuild() ||
337092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      PointeeType != TL.getPointeeLoc().getType()) {
337192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
337292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Result.isNull())
337392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      return QualType();
337492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
3375f85e193739c953358c865005855253af4f68a497John McCall
3376f85e193739c953358c865005855253af4f68a497John McCall  // Objective-C ARC can add lifetime qualifiers to the type that we're
3377f85e193739c953358c865005855253af4f68a497John McCall  // pointing to.
3378f85e193739c953358c865005855253af4f68a497John McCall  TLB.TypeWasModifiedSafely(Result->getPointeeType());
3379f85e193739c953358c865005855253af4f68a497John McCall
338092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
338192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3382c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Result;
3383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3384577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
33851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
33861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3387a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
338843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  BlockPointerTypeLoc TL) {
3389db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  QualType PointeeType
3390c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
3391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (PointeeType.isNull())
3392c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return QualType();
3393c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3394c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType Result = TL.getType();
3395c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (getDerived().AlwaysRebuild() ||
3396c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      PointeeType != TL.getPointeeLoc().getType()) {
3397c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Result = getDerived().RebuildBlockPointerType(PointeeType,
3398db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor                                                  TL.getSigilLoc());
3399db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor    if (Result.isNull())
3400db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor      return QualType();
3401db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  }
3402db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor
340339968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3404db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3405db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  return Result;
3406a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
34071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
340885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type.  Note that somewhat paradoxically we
340985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value
341085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type;  we only care if the type was *written* as an l-value type
341185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type.
341285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived>
341385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType
341485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
341543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ReferenceTypeLoc TL) {
341685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  const ReferenceType *T = TL.getTypePtr();
341785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
341885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // Note that this works with the pointee-as-written.
341985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
342085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (PointeeType.isNull())
342185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return QualType();
342285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
342385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType Result = TL.getType();
342485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (getDerived().AlwaysRebuild() ||
342585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      PointeeType != T->getPointeeTypeAsWritten()) {
342685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildReferenceType(PointeeType,
342785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               T->isSpelledAsLValue(),
342885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               TL.getSigilLoc());
342985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    if (Result.isNull())
343085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      return QualType();
343185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
343285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3433f85e193739c953358c865005855253af4f68a497John McCall  // Objective-C ARC can add lifetime qualifiers to the type that we're
3434f85e193739c953358c865005855253af4f68a497John McCall  // referring to.
3435f85e193739c953358c865005855253af4f68a497John McCall  TLB.TypeWasModifiedSafely(
3436f85e193739c953358c865005855253af4f68a497John McCall                     Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3437f85e193739c953358c865005855253af4f68a497John McCall
343885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // r-value references can be rebuilt as l-value references.
343985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  ReferenceTypeLoc NewTL;
344085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (isa<LValueReferenceType>(Result))
344185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
344285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  else
344385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
344485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
344585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
344685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  return Result;
344785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall}
344885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3449a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3450a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3451a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
345243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 LValueReferenceTypeLoc TL) {
345343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3454a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
34551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3456a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3457a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3458a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
345943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 RValueReferenceTypeLoc TL) {
346043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3461577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3463577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
34641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3465a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
346643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   MemberPointerTypeLoc TL) {
3467a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3468577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (PointeeType.isNull())
3469577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3471b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3472b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo* NewClsTInfo = 0;
3473b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  if (OldClsTInfo) {
3474b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3475b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (!NewClsTInfo)
3476b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return QualType();
3477b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
3478b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
3479b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  const MemberPointerType *T = TL.getTypePtr();
3480b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  QualType OldClsType = QualType(T->getClass(), 0);
3481b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  QualType NewClsType;
3482b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  if (NewClsTInfo)
3483b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsType = NewClsTInfo->getType();
3484b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  else {
3485b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsType = getDerived().TransformType(OldClsType);
3486b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (NewClsType.isNull())
3487b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return QualType();
3488b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
34891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3491a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      PointeeType != T->getPointeeType() ||
3493b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      NewClsType != OldClsType) {
3494b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
349585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getStarLoc());
3496a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3497a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3498a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3499577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3500a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
3502b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  NewTL.setClassTInfo(NewClsTInfo);
3503a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3504a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3505577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3506577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
35071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
35081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3509a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
351043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ConstantArrayTypeLoc TL) {
3511f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ConstantArrayType *T = TL.getTypePtr();
3512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3513577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3514577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3516a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3517a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3519a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildConstantArrayType(ElementType,
3520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
3521a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSize(),
352285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             T->getIndexTypeCVRQualifiers(),
352385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3524a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3525a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3526a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3528a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3529a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3530a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
35311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3532a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = TL.getSizeExpr();
3533a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Size) {
3534f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3536a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3537a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
3538a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3539a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3540577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3542577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3543577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType(
3544a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                              TypeLocBuilder &TLB,
354543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              IncompleteArrayTypeLoc TL) {
3546f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const IncompleteArrayType *T = TL.getTypePtr();
3547a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3551a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3552a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3553a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3554a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildIncompleteArrayType(ElementType,
3555a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                     T->getSizeModifier(),
355685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                           T->getIndexTypeCVRQualifiers(),
355785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                     TL.getBracketsRange());
3558a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3559a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3560a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3561c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3562a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3563a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3564a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3565a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(0);
3566577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3568577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3571a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3572a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
357343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   VariableArrayTypeLoc TL) {
3574f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VariableArrayType *T = TL.getTypePtr();
3575a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3576577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3579670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3580f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3581670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
358260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
3583a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
3584a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
3585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Size = SizeResult.take();
3588a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3589a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3590a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3591a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
3592a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
3593a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildVariableArrayType(ElementType,
3594a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
35959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Size,
3596a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                             T->getIndexTypeCVRQualifiers(),
359785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3598a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3599a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3602a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3603a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3604a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3605a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
36061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3607a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
36091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3611a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3612a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
361343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             DependentSizedArrayTypeLoc TL) {
3614f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedArrayType *T = TL.getTypePtr();
3615a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3619670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3620f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
36211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // Prefer the expression from the TypeLoc;  the other may have been uniqued.
36233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *origSize = TL.getSizeExpr();
36243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!origSize) origSize = T->getSizeExpr();
36253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
36263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExprResult sizeResult
36273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    = getDerived().TransformExpr(origSize);
36283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (sizeResult.isInvalid())
3629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *size = sizeResult.get();
3632a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3633a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3634a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3635a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
36363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      size != origSize) {
3637a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3638a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                         T->getSizeModifier(),
36393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                                                         size,
3640a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                T->getIndexTypeCVRQualifiers(),
364185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                        TL.getBracketsRange());
3642a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3643a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
36451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3646a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // We might have any sort of array type now, but fortunately they
3647a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // all have the same location layout.
3648a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3649a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3650a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
36513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  NewTL.setSizeExpr(size);
3652a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3653a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
36551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                      TypeLocBuilder &TLB,
365943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentSizedExtVectorTypeLoc TL) {
3660f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedExtVectorType *T = TL.getTypePtr();
3661a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3662a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: ext vector locs should be nested
3663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3667670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Vector sizes are not potentially evaluated contexts
3668f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3669670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
367060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3671577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (Size.isInvalid())
3672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3675a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3676eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      ElementType != T->getElementType() ||
3677eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      Size.get() != T->getSizeExpr()) {
3678a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
36799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                             Size.take(),
3680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                         T->getAttributeLoc());
3681a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3682a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3683a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3684a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3685a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Result might be dependent or not.
3686a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (isa<DependentSizedExtVectorType>(Result)) {
3687a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    DependentSizedExtVectorTypeLoc NewTL
3688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  } else {
3691a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3692a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
36971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3699a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
370043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     VectorTypeLoc TL) {
3701f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3705577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
370982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3710e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                            T->getVectorKind());
3711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3714c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3715a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
37171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
37201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3722a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
372343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        ExtVectorTypeLoc TL) {
3724f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
37281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3729a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3730a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3731a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3732a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildExtVectorType(ElementType,
3733a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               T->getNumElements(),
3734a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               /*FIXME*/ SourceLocation());
3735a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3736a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3737a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3738c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3739a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3740a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
37411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3743577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3744577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
37451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
374621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl *
37476a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3748fb44de956f27875def889482b5393475060392afJohn McCall                                                   int indexAdjustment,
37496a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
375021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
37516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  TypeSourceInfo *NewDI = 0;
37526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
37546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    // If we're substituting into a pack expansion type and we know the
37556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc OldTL = OldDI->getTypeLoc();
37566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
37576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37586a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLocBuilder TLB;
37596a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc NewTL = OldDI->getTypeLoc();
37606a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TLB.reserve(NewTL.getFullDataSize());
37616a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37626a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    QualType Result = getDerived().TransformType(TLB,
37636a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                               OldExpansionTL.getPatternLoc());
37646a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
37656a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
37666a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37676a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    Result = RebuildPackExpansionType(Result,
37686a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                OldExpansionTL.getPatternLoc().getSourceRange(),
37696a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      OldExpansionTL.getEllipsisLoc(),
37706a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      NumExpansions);
37716a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
37726a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
37736a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37746a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc NewExpansionTL
37756a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      = TLB.push<PackExpansionTypeLoc>(Result);
37766a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
37776a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
37786a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  } else
37796a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = getDerived().TransformType(OldDI);
378021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (!NewDI)
378121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return 0;
378221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
3783fb44de956f27875def889482b5393475060392afJohn McCall  if (NewDI == OldDI && indexAdjustment == 0)
378421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return OldParm;
3785fb44de956f27875def889482b5393475060392afJohn McCall
3786fb44de956f27875def889482b5393475060392afJohn McCall  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3787fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getDeclContext(),
3788fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getInnerLocStart(),
3789fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getLocation(),
3790fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getIdentifier(),
3791fb44de956f27875def889482b5393475060392afJohn McCall                                             NewDI->getType(),
3792fb44de956f27875def889482b5393475060392afJohn McCall                                             NewDI,
3793fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getStorageClass(),
3794fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getStorageClassAsWritten(),
3795fb44de956f27875def889482b5393475060392afJohn McCall                                             /* DefArg */ NULL);
3796fb44de956f27875def889482b5393475060392afJohn McCall  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3797fb44de956f27875def889482b5393475060392afJohn McCall                        OldParm->getFunctionScopeIndex() + indexAdjustment);
3798fb44de956f27875def889482b5393475060392afJohn McCall  return newParm;
379921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
380021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
380121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
380221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>::
3803a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  TransformFunctionTypeParams(SourceLocation Loc,
3804a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              ParmVarDecl **Params, unsigned NumParams,
3805a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              const QualType *ParamTypes,
3806a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              llvm::SmallVectorImpl<QualType> &OutParamTypes,
3807a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3808fb44de956f27875def889482b5393475060392afJohn McCall  int indexAdjustment = 0;
3809fb44de956f27875def889482b5393475060392afJohn McCall
3810a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  for (unsigned i = 0; i != NumParams; ++i) {
3811a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (ParmVarDecl *OldParm = Params[i]) {
3812fb44de956f27875def889482b5393475060392afJohn McCall      assert(OldParm->getFunctionScopeIndex() == i);
3813fb44de956f27875def889482b5393475060392afJohn McCall
38146a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      llvm::Optional<unsigned> NumExpansions;
3815406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      ParmVarDecl *NewParm = 0;
3816603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (OldParm->isParameterPack()) {
3817603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We have a function parameter pack that may need to be expanded.
3818603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3819603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3820603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Find the parameter packs that could be expanded.
3821c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3822c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3823c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc Pattern = ExpansionTL.getPatternLoc();
3824c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3825406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3826406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor
3827603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Determine whether we should expand the parameter packs.
3828603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        bool ShouldExpand = false;
3829d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor        bool RetainExpansion = false;
38306a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        llvm::Optional<unsigned> OrigNumExpansions
38316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor          = ExpansionTL.getTypePtr()->getNumExpansions();
38326a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        NumExpansions = OrigNumExpansions;
3833c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3834c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor                                                 Pattern.getSourceRange(),
3835603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.data(),
3836603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.size(),
3837d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 ShouldExpand,
3838d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 RetainExpansion,
3839d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 NumExpansions)) {
3840603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          return true;
3841603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3842603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3843603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        if (ShouldExpand) {
3844603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // Expand the function parameter pack into multiple, separate
3845603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // parameters.
384612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor          getDerived().ExpandingFunctionParameterPack(OldParm);
3847cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          for (unsigned I = 0; I != *NumExpansions; ++I) {
3848603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3849603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            ParmVarDecl *NewParm
38506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
3851fb44de956f27875def889482b5393475060392afJohn McCall                                                        indexAdjustment++,
38526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3853603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            if (!NewParm)
3854603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor              return true;
3855603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3856a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            OutParamTypes.push_back(NewParm->getType());
3857a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            if (PVars)
3858a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor              PVars->push_back(NewParm);
3859603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          }
3860d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3861d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // If we're supposed to retain a pack expansion, do so by temporarily
3862d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // forgetting the partially-substituted parameter pack.
3863d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          if (RetainExpansion) {
3864d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3865d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ParmVarDecl *NewParm
38666a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
3867fb44de956f27875def889482b5393475060392afJohn McCall                                                        indexAdjustment++,
38686a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3869d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (!NewParm)
3870d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              return true;
3871d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3872d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            OutParamTypes.push_back(NewParm->getType());
3873d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (PVars)
3874d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              PVars->push_back(NewParm);
3875d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          }
3876d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3877fb44de956f27875def889482b5393475060392afJohn McCall          // The next parameter should have the same adjustment as the
3878fb44de956f27875def889482b5393475060392afJohn McCall          // last thing we pushed, but we post-incremented indexAdjustment
3879fb44de956f27875def889482b5393475060392afJohn McCall          // on every push.  Also, if we push nothing, the adjustment should
3880fb44de956f27875def889482b5393475060392afJohn McCall          // go down by one.
3881fb44de956f27875def889482b5393475060392afJohn McCall          indexAdjustment--;
3882fb44de956f27875def889482b5393475060392afJohn McCall
3883603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // We're done with the pack expansion.
3884603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          continue;
3885603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3886603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3887603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We'll substitute the parameter now without expanding the pack
3888603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // expansion.
3889406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3890406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3891fb44de956f27875def889482b5393475060392afJohn McCall                                                          indexAdjustment,
3892406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor                                                          NumExpansions);
3893406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      } else {
3894406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3895fb44de956f27875def889482b5393475060392afJohn McCall                                                          indexAdjustment,
3896406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor                                                  llvm::Optional<unsigned>());
3897603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3898406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor
389921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      if (!NewParm)
390021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3901603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3902a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      OutParamTypes.push_back(NewParm->getType());
3903a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (PVars)
3904a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor        PVars->push_back(NewParm);
3905603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      continue;
3906603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    }
3907a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3908a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // Deal with the possibility that we don't have a parameter
3909a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // declaration for this parameter.
3910a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    QualType OldType = ParamTypes[i];
3911603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    bool IsPackExpansion = false;
3912cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    llvm::Optional<unsigned> NumExpansions;
3913406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor    QualType NewType;
3914603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (const PackExpansionType *Expansion
3915603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                       = dyn_cast<PackExpansionType>(OldType)) {
3916603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We have a function parameter pack that may need to be expanded.
3917603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      QualType Pattern = Expansion->getPattern();
3918603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3919603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3920603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3921603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // Determine whether we should expand the parameter packs.
3922603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      bool ShouldExpand = false;
3923d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3924a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
3925603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.data(),
3926603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.size(),
3927d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               ShouldExpand,
3928d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3929d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions)) {
393021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3931603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3932603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3933603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (ShouldExpand) {
3934603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Expand the function parameter pack into multiple, separate
3935603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // parameters.
3936cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        for (unsigned I = 0; I != *NumExpansions; ++I) {
3937603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3938603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          QualType NewType = getDerived().TransformType(Pattern);
3939603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          if (NewType.isNull())
3940603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            return true;
3941603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3942a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          OutParamTypes.push_back(NewType);
3943a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          if (PVars)
3944a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            PVars->push_back(0);
3945603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3946603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3947603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We're done with the pack expansion.
3948603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        continue;
3949603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3950603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
39513cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
39523cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
39533cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
39543cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
39553cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        QualType NewType = getDerived().TransformType(Pattern);
39563cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (NewType.isNull())
39573cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
39583cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
39593cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        OutParamTypes.push_back(NewType);
39603cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (PVars)
39613cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          PVars->push_back(0);
39623cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
3963d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3964603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We'll substitute the parameter now without expanding the pack
3965603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // expansion.
3966603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      OldType = Expansion->getPattern();
3967603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      IsPackExpansion = true;
3968406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3969406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      NewType = getDerived().TransformType(OldType);
3970406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor    } else {
3971406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      NewType = getDerived().TransformType(OldType);
3972a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    }
3973603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3974603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (NewType.isNull())
3975603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      return true;
39761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3977603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (IsPackExpansion)
3978cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NewType = getSema().Context.getPackExpansionType(NewType,
3979cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                       NumExpansions);
3980603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3981a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    OutParamTypes.push_back(NewType);
3982a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (PVars)
3983a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      PVars->push_back(0);
3984577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
39851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3986fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG
3987fb44de956f27875def889482b5393475060392afJohn McCall  if (PVars) {
3988fb44de956f27875def889482b5393475060392afJohn McCall    for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3989fb44de956f27875def889482b5393475060392afJohn McCall      if (ParmVarDecl *parm = (*PVars)[i])
3990fb44de956f27875def889482b5393475060392afJohn McCall        assert(parm->getFunctionScopeIndex() == i);
3991603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor  }
3992fb44de956f27875def889482b5393475060392afJohn McCall#endif
3993fb44de956f27875def889482b5393475060392afJohn McCall
3994fb44de956f27875def889482b5393475060392afJohn McCall  return false;
3995fb44de956f27875def889482b5393475060392afJohn McCall}
399621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
399721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
399821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType
399921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
400043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   FunctionProtoTypeLoc TL) {
40017e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // Transform the parameters and return type.
40027e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
40037e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // We instantiate in source order, with the return type first followed by
40047e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // the parameters, because users tend to expect this (even if they shouldn't
40057e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // rely on it!).
40067e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
4007dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // When the function has a trailing return type, we instantiate the
4008dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // parameters before the return type,  since the return type can then refer
4009dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // to the parameters themselves (via decltype, sizeof, etc.).
4010dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
401121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<QualType, 4> ParamTypes;
401221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
4013f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionProtoType *T = TL.getTypePtr();
40147e010a04fef171049291d8cb3047f118566da090Douglas Gregor
4015dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  QualType ResultType;
4016dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4017dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  if (TL.getTrailingReturn()) {
4018a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4019a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
4020a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
4021a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
4022a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
4023dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4024dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4025dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4026dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
4027dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4028dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
4029dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  else {
4030dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4031dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
4032dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4033dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4034a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4035a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
4036a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
4037a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
4038a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
4039dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4040dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
4041dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4042a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4043a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4044a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType() ||
4045bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor      T->getNumArgs() != ParamTypes.size() ||
4046a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4047a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionProtoType(ResultType,
4048a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.data(),
4049a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.size(),
4050a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->isVariadic(),
4051fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getTypeQuals(),
4052c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                   T->getRefQualifier(),
4053fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getExtInfo());
4054a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4055a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4056a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
40571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4058a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4059796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4060796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4061dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(TL.getTrailingReturn());
4062a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4063a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setArg(i, ParamDecls[i]);
4064a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4065a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4066577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
40671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4068577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4069577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4070a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                 TypeLocBuilder &TLB,
407143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 FunctionNoProtoTypeLoc TL) {
4072f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionNoProtoType *T = TL.getTypePtr();
4073a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4074a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (ResultType.isNull())
4075a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4076a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4077a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4078a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4079a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType())
4080a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4081a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4082a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4083796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4084796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4085dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(false);
4086a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4087a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4088577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
40891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4090ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType
4091ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
409243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 UnresolvedUsingTypeLoc TL) {
4093f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const UnresolvedUsingType *T = TL.getTypePtr();
40947c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4095ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (!D)
4096ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return QualType();
4097ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4098ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType Result = TL.getType();
4099ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4100ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Result = getDerived().RebuildUnresolvedUsingType(D);
4101ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    if (Result.isNull())
4102ed97649e9574b9d854fa4d6109c9333ae0993554John McCall      return QualType();
4103ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
4104ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4105ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // We might get an arbitrary type spec type back.  We should at
4106ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // least always get a type spec type, though.
4107ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4108ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  NewTL.setNameLoc(TL.getNameLoc());
4109ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4110ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return Result;
4111ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
4112ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4114a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
411543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypedefTypeLoc TL) {
4116f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypedefType *T = TL.getTypePtr();
4117162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *Typedef
4118162e1c1b487352434552147967c3dd296ebee2f7Richard Smith    = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4119162e1c1b487352434552147967c3dd296ebee2f7Richard Smith                                                               T->getDecl()));
4120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Typedef)
4121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
41221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4123a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4124a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4125a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Typedef != T->getDecl()) {
4126a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildTypedefType(Typedef);
4127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4128a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
41331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
413943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypeOfExprTypeLoc TL) {
4140670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // typeof expressions are not potentially evaluated contexts
4141f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
41421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
414360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
4145577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
4146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4148a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4149cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      E.get() != TL.getUnderlyingExpr()) {
41502a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
41551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4157cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
4158cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
4159cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
4160a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4161a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4162577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4165a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
416643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     TypeOfTypeLoc TL) {
4167cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4168cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4169cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (!New_Under_TI)
4170577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
41711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4172a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4173cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4174cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4175a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4176a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4177a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
41781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4179a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4180cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
4181cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
4182cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
4183cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setUnderlyingTInfo(New_Under_TI);
4184a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4189a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
419043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                       DecltypeTypeLoc TL) {
4191f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DecltypeType *T = TL.getTypePtr();
4192a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4193670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // decltype expressions are not potentially evaluated contexts
4194f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
41951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
419660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4197577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
4198577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
41991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4200a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4201a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4202a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      E.get() != T->getUnderlyingExpr()) {
42032a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4206577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
4208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
42111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4213577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4214577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4215577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4216ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType(
4217ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                            TypeLocBuilder &TLB,
4218ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                     UnaryTransformTypeLoc TL) {
4219ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType Result = TL.getType();
4220ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  if (Result->isDependentType()) {
4221ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    const UnaryTransformType *T = TL.getTypePtr();
4222ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    QualType NewBase =
4223ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4224ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    Result = getDerived().RebuildUnaryTransformType(NewBase,
4225ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    T->getUTTKind(),
4226ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    TL.getKWLoc());
4227ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    if (Result.isNull())
4228ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      return QualType();
4229ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
4230ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
4231ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4232ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setKWLoc(TL.getKWLoc());
4233ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setParensRange(TL.getParensRange());
4234ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4235ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  return Result;
4236ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
4237ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
4238ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived>
423934b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
424034b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                   AutoTypeLoc TL) {
424134b41d939a1328f484511c6002ba2456db879a29Richard Smith  const AutoType *T = TL.getTypePtr();
424234b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType OldDeduced = T->getDeducedType();
424334b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType NewDeduced;
424434b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (!OldDeduced.isNull()) {
424534b41d939a1328f484511c6002ba2456db879a29Richard Smith    NewDeduced = getDerived().TransformType(OldDeduced);
424634b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (NewDeduced.isNull())
424734b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
424834b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
424934b41d939a1328f484511c6002ba2456db879a29Richard Smith
425034b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType Result = TL.getType();
425134b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
425234b41d939a1328f484511c6002ba2456db879a29Richard Smith    Result = getDerived().RebuildAutoType(NewDeduced);
425334b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (Result.isNull())
425434b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
425534b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
425634b41d939a1328f484511c6002ba2456db879a29Richard Smith
425734b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
425834b41d939a1328f484511c6002ba2456db879a29Richard Smith  NewTL.setNameLoc(TL.getNameLoc());
425934b41d939a1328f484511c6002ba2456db879a29Richard Smith
426034b41d939a1328f484511c6002ba2456db879a29Richard Smith  return Result;
426134b41d939a1328f484511c6002ba2456db879a29Richard Smith}
426234b41d939a1328f484511c6002ba2456db879a29Richard Smith
426334b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived>
4264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
426543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     RecordTypeLoc TL) {
4266f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const RecordType *T = TL.getTypePtr();
4267577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  RecordDecl *Record
42687c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
42697c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                          T->getDecl()));
4270577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Record)
4271577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
42721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4273a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4275a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Record != T->getDecl()) {
4276a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildRecordType(Record);
4277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
42801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
4283a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
42861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
428943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   EnumTypeLoc TL) {
4290f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const EnumType *T = TL.getTypePtr();
4291577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  EnumDecl *Enum
42927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
42937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                        T->getDecl()));
4294577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Enum)
4295577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
42961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Enum != T->getDecl()) {
4300a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildEnumType(Enum);
4301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4302a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4303a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4304a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4305a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4306a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
43071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4309577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43107da2431c23ef1ee8acb114e39692246e1801afc2John McCall
43113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived>
43123cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType(
43133cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         TypeLocBuilder &TLB,
431443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         InjectedClassNameTypeLoc TL) {
43153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
43163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                       TL.getTypePtr()->getDecl());
43173cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  if (!D) return QualType();
43183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
43193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
43203cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
43213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  return T;
43223cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
43233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
4324577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4325577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4326a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                TypeLocBuilder &TLB,
432743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TemplateTypeParmTypeLoc TL) {
4328a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
4329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4330577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
43311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
433249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4333a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                         TypeLocBuilder &TLB,
433443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         SubstTemplateTypeParmTypeLoc TL) {
43350b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  const SubstTemplateTypeParmType *T = TL.getTypePtr();
43360b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43370b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Substitute into the replacement type, which itself might involve something
43380b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // that needs to be transformed. This only tends to occur with default
43390b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // template arguments of template template parameters.
43400b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
43410b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  QualType Replacement = getDerived().TransformType(T->getReplacementType());
43420b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  if (Replacement.isNull())
43430b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    return QualType();
43440b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43450b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Always canonicalize the replacement type.
43460b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  Replacement = SemaRef.Context.getCanonicalType(Replacement);
43470b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  QualType Result
43480b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
43490b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor                                                   Replacement);
43500b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43510b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Propagate type-source information.
43520b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  SubstTemplateTypeParmTypeLoc NewTL
43530b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
43540b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  NewTL.setNameLoc(TL.getNameLoc());
43550b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  return Result;
43560b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
435749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
435849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
435949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived>
4360c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4361c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          TypeLocBuilder &TLB,
4362c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          SubstTemplateTypeParmPackTypeLoc TL) {
4363c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  return TransformTypeSpecType(TLB, TL);
4364c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}
4365c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
4366c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived>
4367833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
436843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        TypeLocBuilder &TLB,
436943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                           TemplateSpecializationTypeLoc TL) {
437043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
4371828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
43721d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  // The nested-name-specifier never matters in a TemplateSpecializationType,
43731d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  // because we can't have a dependent nested-name-specifier anyway.
43741d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  CXXScopeSpec SS;
437543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TemplateName Template
43761d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    = getDerived().TransformTemplateName(SS, T->getTemplateName(),
43771d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor                                         TL.getTemplateNameLoc());
437843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Template.isNull())
437943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4380833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
438143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4382dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor}
438343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
43847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace {
43857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \brief Simple iterator that traverses the template arguments in a
43867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// container that provides a \c getArgLoc() member function.
43877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
43887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// This iterator is intended to be used with the iterator form of
43897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \c TreeTransform<Derived>::TransformTemplateArguments().
43907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename ArgLocContainer>
43917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class TemplateArgumentLocContainerIterator {
43927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgLocContainer *Container;
43937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    unsigned Index;
43947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
43957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
43967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc value_type;
43977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc reference;
43987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef int difference_type;
43997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef std::input_iterator_tag iterator_category;
44007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    class pointer {
44027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLoc Arg;
44037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    public:
44057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
44067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      const TemplateArgumentLoc *operator->() const {
44087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return &Arg;
44097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      }
44107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    };
44117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator() {}
44147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
44167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                 unsigned Index)
44177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      : Container(&Container), Index(Index) { }
44187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator &operator++() {
44207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++Index;
44217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return *this;
44227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator operator++(int) {
44257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLocContainerIterator Old(*this);
44267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++(*this);
44277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Old;
44287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc operator*() const {
44317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Container->getArgLoc(Index);
44327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    pointer operator->() const {
44357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return pointer(Container->getArgLoc(Index));
44367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4439f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
44407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return X.Container == Y.Container && X.Index == Y.Index;
44417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4444f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
44457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return !(X == Y);
44467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
44487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}
44497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
445143fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived>
4452577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4453833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                        TypeLocBuilder &TLB,
4454833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                           TemplateSpecializationTypeLoc TL,
445543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TemplateName Template) {
4456d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo NewTemplateArgs;
4457d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4458d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
44597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
44607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgIterator;
44617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
44627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
44637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              NewTemplateArgs))
44647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    return QualType();
44651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4466833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  // FIXME: maybe don't rebuild if all the template arguments are the same.
4467833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
4468833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType Result =
4469833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getDerived().RebuildTemplateSpecializationType(Template,
4470833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                   TL.getTemplateNameLoc(),
4471d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NewTemplateArgs);
44721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4473833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  if (!Result.isNull()) {
44743e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // Specializations of template template parameters are represented as
44753e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // TemplateSpecializationTypes, and substitution of type alias templates
44763e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // within a dependent context can transform them into
44773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // DependentTemplateSpecializationTypes.
44783e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    if (isa<DependentTemplateSpecializationType>(Result)) {
44793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      DependentTemplateSpecializationTypeLoc NewTL
44803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
44813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setKeywordLoc(TL.getTemplateNameLoc());
44823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setQualifierLoc(NestedNameSpecifierLoc());
44833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setNameLoc(TL.getTemplateNameLoc());
44843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setLAngleLoc(TL.getLAngleLoc());
44853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setRAngleLoc(TL.getRAngleLoc());
44863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
44873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
44883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      return Result;
44893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    }
44903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
4491833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TemplateSpecializationTypeLoc NewTL
4492833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4493833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4494833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setLAngleLoc(TL.getLAngleLoc());
4495833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setRAngleLoc(TL.getRAngleLoc());
4496833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4497833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4498833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
44991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4500833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return Result;
4501577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
45021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4503a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived>
4504a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4505a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                     TypeLocBuilder &TLB,
4506a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                     DependentTemplateSpecializationTypeLoc TL,
4507087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                     TemplateName Template,
4508087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                     CXXScopeSpec &SS) {
4509a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  TemplateArgumentListInfo NewTemplateArgs;
4510a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4511a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4512a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  typedef TemplateArgumentLocContainerIterator<
4513a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor            DependentTemplateSpecializationTypeLoc> ArgIterator;
4514a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4515a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
4516a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                              NewTemplateArgs))
4517a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    return QualType();
4518a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4519a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  // FIXME: maybe don't rebuild if all the template arguments are the same.
4520a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4521a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4522a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    QualType Result
4523a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = getSema().Context.getDependentTemplateSpecializationType(
4524a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                TL.getTypePtr()->getKeyword(),
4525a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                         DTN->getQualifier(),
4526a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                         DTN->getIdentifier(),
4527a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                               NewTemplateArgs);
4528a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4529a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    DependentTemplateSpecializationTypeLoc NewTL
4530a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4531a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setKeywordLoc(TL.getKeywordLoc());
453294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
453394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
4534a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setNameLoc(TL.getNameLoc());
4535a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setLAngleLoc(TL.getLAngleLoc());
4536a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setRAngleLoc(TL.getRAngleLoc());
4537a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4538a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4539a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    return Result;
4540a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4541a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4542a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  QualType Result
4543a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    = getDerived().RebuildTemplateSpecializationType(Template,
4544a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                     TL.getNameLoc(),
4545a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                     NewTemplateArgs);
4546a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4547a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (!Result.isNull()) {
4548a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    /// FIXME: Wrap this in an elaborated-type-specifier?
4549a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    TemplateSpecializationTypeLoc NewTL
4550a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4551a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setTemplateNameLoc(TL.getNameLoc());
4552a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setLAngleLoc(TL.getLAngleLoc());
4553a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setRAngleLoc(TL.getRAngleLoc());
4554a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4555a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4556a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4557a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4558a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  return Result;
4559a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor}
4560a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
45611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4562a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4563465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
456443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ElaboratedTypeLoc TL) {
4565f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ElaboratedType *T = TL.getTypePtr();
4566465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
45679e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
4568465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // NOTE: the qualifier in an ElaboratedType is optional.
45699e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  if (TL.getQualifierLoc()) {
45709e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    QualifierLoc
45719e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
45729e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    if (!QualifierLoc)
4573465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      return QualType();
4574465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
45751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
457643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
457743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (NamedT.isNull())
457843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4579a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar
45803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  // C++0x [dcl.type.elab]p2:
45813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   If the identifier resolves to a typedef-name or the simple-template-id
45823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   resolves to an alias template specialization, the
45833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   elaborated-type-specifier is ill-formed.
45841804174e1591bf59118f317775b48edd0382c3f0Richard Smith  if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
45851804174e1591bf59118f317775b48edd0382c3f0Richard Smith    if (const TemplateSpecializationType *TST =
45861804174e1591bf59118f317775b48edd0382c3f0Richard Smith          NamedT->getAs<TemplateSpecializationType>()) {
45871804174e1591bf59118f317775b48edd0382c3f0Richard Smith      TemplateName Template = TST->getTemplateName();
45881804174e1591bf59118f317775b48edd0382c3f0Richard Smith      if (TypeAliasTemplateDecl *TAT =
45891804174e1591bf59118f317775b48edd0382c3f0Richard Smith          dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
45901804174e1591bf59118f317775b48edd0382c3f0Richard Smith        SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
45911804174e1591bf59118f317775b48edd0382c3f0Richard Smith                     diag::err_tag_reference_non_tag) << 4;
45921804174e1591bf59118f317775b48edd0382c3f0Richard Smith        SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
45931804174e1591bf59118f317775b48edd0382c3f0Richard Smith      }
45943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    }
45953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  }
45963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
4597a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4598a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
45999e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      QualifierLoc != TL.getQualifierLoc() ||
4600e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      NamedT != T->getNamedType()) {
460121e413fe6305a198564d436ac515497716c47844John McCall    Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
46029e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                                T->getKeyword(),
46039e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                                QualifierLoc, NamedT);
4604a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4605a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4606a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4608465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4609e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setKeywordLoc(TL.getKeywordLoc());
46109e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NewTL.setQualifierLoc(QualifierLoc);
4611a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
46131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
46159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType(
46169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                TypeLocBuilder &TLB,
46179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                AttributedTypeLoc TL) {
46189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  const AttributedType *oldType = TL.getTypePtr();
46199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
46209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (modifiedType.isNull())
46219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return QualType();
46229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType result = TL.getType();
46249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // FIXME: dependent operand expressions?
46269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (getDerived().AlwaysRebuild() ||
46279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      modifiedType != oldType->getModifiedType()) {
46289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // TODO: this is really lame; we should really be rebuilding the
46299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // equivalent type from first principles.
46309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    QualType equivalentType
46319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      = getDerived().TransformType(oldType->getEquivalentType());
46329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (equivalentType.isNull())
46339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      return QualType();
46349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
46359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               modifiedType,
46369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               equivalentType);
46379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
46389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
46409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  newTL.setAttrNameLoc(TL.getAttrNameLoc());
46419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrOperand())
46429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
46439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrExprOperand())
46449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrExprOperand(TL.getAttrExprOperand());
46459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  else if (TL.hasAttrEnumOperand())
46469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
46479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  return result;
46499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
46509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived>
4652075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType
4653075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4654075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                                           ParenTypeLoc TL) {
4655075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4656075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (Inner.isNull())
4657075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType();
4658075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4659075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Result = TL.getType();
4660075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (getDerived().AlwaysRebuild() ||
4661075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      Inner != TL.getInnerLoc().getType()) {
4662075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Result = getDerived().RebuildParenType(Inner);
4663075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    if (Result.isNull())
4664075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      return QualType();
4665075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
4666075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4667075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4668075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setLParenLoc(TL.getLParenLoc());
4669075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setRParenLoc(TL.getRParenLoc());
4670075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  return Result;
4671075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
4672075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4673075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived>
46744714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
467543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      DependentNameTypeLoc TL) {
4676f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentNameType *T = TL.getTypePtr();
4677833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
46782494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  NestedNameSpecifierLoc QualifierLoc
46792494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
46802494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  if (!QualifierLoc)
4681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
46821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
468333500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType Result
46842494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    = getDerived().RebuildDependentNameType(T->getKeyword(),
468533500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getKeywordLoc(),
46862494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            QualifierLoc,
46872494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            T->getIdentifier(),
468833500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getNameLoc());
4689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
4690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4691a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4692e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4693e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    QualType NamedT = ElabT->getNamedType();
469433500955d731c73717af52088b7fc0e7a85681e7John McCall    TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
469533500955d731c73717af52088b7fc0e7a85681e7John McCall
4696e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4697e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
46989e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
469933500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
4700e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4701e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
47022494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
4703e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setNameLoc(TL.getNameLoc());
4704e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
4705a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4706577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
47071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4708577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
470933500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>::
471033500955d731c73717af52088b7fc0e7a85681e7John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
471143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL) {
471294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
471394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (TL.getQualifierLoc()) {
471494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualifierLoc
471594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
471694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (!QualifierLoc)
4717a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      return QualType();
4718a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4719a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
472043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived()
472194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor           .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
472243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
472343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
472443fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
472543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::
472694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
472794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                   DependentTemplateSpecializationTypeLoc TL,
472894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                       NestedNameSpecifierLoc QualifierLoc) {
472994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  const DependentTemplateSpecializationType *T = TL.getTypePtr();
473094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
473194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  TemplateArgumentListInfo NewTemplateArgs;
473294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
473394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
473494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
473594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  typedef TemplateArgumentLocContainerIterator<
473694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  DependentTemplateSpecializationTypeLoc> ArgIterator;
473794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
473894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
473994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                              NewTemplateArgs))
474094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return QualType();
474194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
474294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  QualType Result
474394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
474494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                              QualifierLoc,
474594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            T->getIdentifier(),
474694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            TL.getNameLoc(),
474794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            NewTemplateArgs);
474894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (Result.isNull())
474994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return QualType();
475094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
475194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
475294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualType NamedT = ElabT->getNamedType();
475394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
475494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Copy information relevant to the template specialization.
475594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    TemplateSpecializationTypeLoc NamedTL
47560a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4757a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    NamedTL.setTemplateNameLoc(TL.getNameLoc());
475894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NamedTL.setLAngleLoc(TL.getLAngleLoc());
475994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NamedTL.setRAngleLoc(TL.getRAngleLoc());
4760944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47610a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
476294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
476394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Copy information relevant to the elaborated type.
476494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
476594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setKeywordLoc(TL.getKeywordLoc());
476694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
47670a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor  } else if (isa<DependentTemplateSpecializationType>(Result)) {
47680a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
47690a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4770944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    SpecTL.setKeywordLoc(TL.getKeywordLoc());
47710a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setQualifierLoc(QualifierLoc);
4772a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    SpecTL.setNameLoc(TL.getNameLoc());
47730a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setLAngleLoc(TL.getLAngleLoc());
47740a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setRAngleLoc(TL.getRAngleLoc());
4775944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47760a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
477794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  } else {
47780a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    TemplateSpecializationTypeLoc SpecTL
47790a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4780a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    SpecTL.setTemplateNameLoc(TL.getNameLoc());
47810a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setLAngleLoc(TL.getLAngleLoc());
47820a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setRAngleLoc(TL.getRAngleLoc());
4783944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47840a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
478594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  }
478694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  return Result;
478794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor}
478894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
478994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived>
47907536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
47917536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor                                                      PackExpansionTypeLoc TL) {
47922fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Pattern
47932fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    = getDerived().TransformType(TLB, TL.getPatternLoc());
47942fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (Pattern.isNull())
47952fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    return QualType();
47962fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
47972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Result = TL.getType();
47982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (getDerived().AlwaysRebuild() ||
47992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      Pattern != TL.getPatternLoc().getType()) {
48002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    Result = getDerived().RebuildPackExpansionType(Pattern,
48012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                           TL.getPatternLoc().getSourceRange(),
4802cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                   TL.getEllipsisLoc(),
4803cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           TL.getTypePtr()->getNumExpansions());
48042fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    if (Result.isNull())
48052fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      return QualType();
48062fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
48072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
48082fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
48092fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  NewT.setEllipsisLoc(TL.getEllipsisLoc());
48102fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  return Result;
48117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}
48127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
48137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived>
4814a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4815a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
481643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ObjCInterfaceTypeLoc TL) {
4817ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCInterfaceType is never dependent.
4818c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4819c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return TL.getType();
4820c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4821c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4822c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived>
4823c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType
4824c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
482543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjCObjectTypeLoc TL) {
4826c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // ObjCObjectType is never dependent.
4827c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4828ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
4829577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
48301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4832a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4833a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
483443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ObjCObjectPointerTypeLoc TL) {
4835ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCObjectPointerType is never dependent.
4836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4837ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
483824fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}
483924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis
4840577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
484143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation
484243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
484343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
484460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48451eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
48463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
484743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
484843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
484943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
485060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
485143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
485243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().TransformCompoundStmt(S, false);
485343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
485443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
485543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
485660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48571eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
485843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              bool IsStmtExpr) {
48597114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  bool SubStmtInvalid = false;
486043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool SubStmtChanged = false;
4861ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Statements(getSema());
486243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
486343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       B != BEnd; ++B) {
486460d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Result = getDerived().TransformStmt(*B);
48657114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    if (Result.isInvalid()) {
48667114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Immediately fail if this was a DeclStmt, since it's very
48677114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // likely that this will cause problems for future statements.
48687114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      if (isa<DeclStmt>(*B))
48697114cbab7eb6e8b714eb22f014327daf2c741c08John McCall        return StmtError();
48707114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
48717114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Otherwise, just keep processing substatements and fail later.
48727114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      SubStmtInvalid = true;
48737114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      continue;
48747114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
48751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
487643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    SubStmtChanged = SubStmtChanged || Result.get() != *B;
487743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Statements.push_back(Result.takeAs<Stmt>());
487843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
48791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48807114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  if (SubStmtInvalid)
48817114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    return StmtError();
48827114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
488343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
488443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !SubStmtChanged)
48853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
488643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
488743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
488843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          move_arg(Statements),
488943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          S->getRBracLoc(),
489043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          IsStmtExpr);
489143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
48921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
489343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
489460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
489660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS, RHS;
4897264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  {
4898264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // The case value expressions are not potentially evaluated.
4899f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
49001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4901264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the left-hand case value.
4902264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    LHS = getDerived().TransformExpr(S->getLHS());
4903264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (LHS.isInvalid())
4904f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
49051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4906264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the right-hand case value (for the GNU case-range extension).
4907264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    RHS = getDerived().TransformExpr(S->getRHS());
4908264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (RHS.isInvalid())
4909f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4910264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  }
49111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
491243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Build the case statement.
491343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Case statements are always rebuilt so that they will attached to their
491443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transformed switch statement.
491560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
49169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       LHS.get(),
491743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getEllipsisLoc(),
49189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       RHS.get(),
491943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getColonLoc());
492043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Case.isInvalid())
4921f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
492343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the case
492460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
492543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4926f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
492843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Attach the body to the case statement
49299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
493043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
493143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
493243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
493360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49341eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
493543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the default case
493660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
493743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4938f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
494043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Default statements are always rebuilt
494143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
49429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubStmt.get());
494343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
494543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
494660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49471eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
494860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
494943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4950f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
495257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
495357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getDecl());
495457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
495557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
495657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
495757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
495843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // FIXME: Pass the real colon location in.
4959ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  return getDerived().RebuildLabelStmt(S->getIdentLoc(),
496057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       cast<LabelDecl>(LD), SourceLocation(),
496157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       SubStmt.get());
496243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
496560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
496743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
496860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
49698cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  VarDecl *ConditionVar = 0;
49708cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  if (S->getConditionVariable()) {
4971c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
49728cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor      = cast_or_null<VarDecl>(
4973aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4974aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4975aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
49768cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    if (!ConditionVar)
4977f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
497899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
49798cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4980c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
498199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4982f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4983eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
4984eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor    // Convert the condition to a boolean value.
4985afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
49868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
49878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
4988afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
4989f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4990eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
49919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
4992afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
499399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
4994c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
49969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
4997f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4998eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
499943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "then" branch.
500060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Then = getDerived().TransformStmt(S->getThen());
500143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Then.isInvalid())
5002f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
500443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "else" branch.
500560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Else = getDerived().TransformStmt(S->getElse());
500643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Else.isInvalid())
5007f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
500943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
50109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
501199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
501243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Then.get() == S->getThen() &&
501343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Else.get() == S->getElse())
50143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
50151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5016eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
501744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                    Then.get(),
50189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    S->getElseLoc(), Else.get());
501943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
502043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
502143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
502260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50231eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
502443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition.
502560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
5026d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  VarDecl *ConditionVar = 0;
5027d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  if (S->getConditionVariable()) {
5028c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
5029d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor      = cast_or_null<VarDecl>(
5030aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5031aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5032aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
5033d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    if (!ConditionVar)
5034f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
503599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
5036d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5037c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
503899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5039f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
504099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
50411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
504243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Rebuild the switch statement.
504360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Switch
50449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5045586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                          ConditionVar);
504643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Switch.isInvalid())
5047f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
504943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body of the switch statement.
505060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
505143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5052f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
505443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Complete the switch statement.
50559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
50569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Body.get());
505743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
50581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
505943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
506060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50611eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
506243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
506360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
50645656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  VarDecl *ConditionVar = 0;
50655656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  if (S->getConditionVariable()) {
5066c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
50675656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      = cast_or_null<VarDecl>(
5068aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5069aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5070aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
50715656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    if (!ConditionVar)
5072f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
507399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
50745656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5075c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
507699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5077f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5078afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
5079afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
5080afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
50818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
50828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5083afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5084f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
50859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE;
5086afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
508799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
50881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
50909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5091f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5092eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
509343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
509460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
509543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5096f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
509843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
50999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
510099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
510143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
51029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(S);
51031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5104eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
51059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       ConditionVar, Body.get());
510643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
510843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
510960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
511043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
511143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
511260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5114f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5116eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  // Transform the condition
511760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(S->getCond());
5118eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  if (Cond.isInvalid())
5119f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5120eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
512143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
512243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Cond.get() == S->getCond() &&
512343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
51243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
51251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
51279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    /*FIXME:*/S->getWhileLoc(), Cond.get(),
512843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    S->getRParenLoc());
512943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
513260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
51331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) {
513443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the initialization statement
513560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Init = getDerived().TransformStmt(S->getInit());
513643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Init.isInvalid())
5137f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
514060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
514199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  VarDecl *ConditionVar = 0;
514299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  if (S->getConditionVariable()) {
5143c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
514499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      = cast_or_null<VarDecl>(
5145aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5146aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5147aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
514899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (!ConditionVar)
5149f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
515099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
515199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5152c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
515399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5155afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
5156afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
5157afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
51588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
51598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5160afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5161f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5162afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
51639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
5164afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
516599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
51661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
51689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5169f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5170eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
517143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the increment
517260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Inc = getDerived().TransformExpr(S->getInc());
517343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Inc.isInvalid())
5174f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
51779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (S->getInc() && !FullInc.get())
5178f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5179eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
518043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
518160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
518243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5183f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
518543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
518643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Init.get() == S->getInit() &&
51879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
518843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Inc.get() == S->getInc() &&
518943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
51903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
51911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
519243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
51939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Init.get(), FullCond, ConditionVar,
51949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     FullInc, S->getRParenLoc(), Body.get());
519543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
519643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
519743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
519860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
51991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
520057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
520157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getLabel());
520257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
520357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
520457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
520543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Goto statements must always be rebuilt, to resolve the label.
52061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
520757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                      cast<LabelDecl>(LD));
520843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
520943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
521043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
521160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
521360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Target = getDerived().TransformExpr(S->getTarget());
521443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Target.isInvalid())
5215f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
52161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
521743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
521843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Target.get() == S->getTarget())
52193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
522043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
522143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
52229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Target.get());
522343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
522443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
522543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
522660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52271eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
52283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
522943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
523143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
523260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
52343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
523543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
523743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
523860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52391eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
524060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = getDerived().TransformExpr(S->getRetValue());
524143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Result.isInvalid())
5242f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
524343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
52441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: We always rebuild the return statement because there is no way
524543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // to tell whether the return type of the function has changed.
52469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
524743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
524943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
525060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52511eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
525243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool DeclChanged = false;
525343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  llvm::SmallVector<Decl *, 4> Decls;
525443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
525543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       D != DEnd; ++D) {
5256aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor    Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5257aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                         *D);
525843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (!Transformed)
5259f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
52601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
526143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Transformed != *D)
526243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      DeclChanged = true;
52631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
526443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Decls.push_back(Transformed);
526543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
52661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
526743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() && !DeclChanged)
52683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
52691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
527143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getStartLoc(), S->getEndLoc());
527243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
527443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
527560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
527643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
5277c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5278ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Constraints(getSema());
5279ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Exprs(getSema());
5280ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  llvm::SmallVector<IdentifierInfo *, 4> Names;
5281a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson
528260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AsmString;
5283ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Clobbers(getSema());
5284703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5285703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  bool ExprsChanged = false;
5286c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5287703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the outputs.
5288703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5289ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getOutputIdentifier(I));
5290c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5291703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
52923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getOutputConstraintLiteral(I));
5293c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5294703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the output expr.
5295703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *OutputExpr = S->getOutputExpr(I);
529660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(OutputExpr);
5297703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
5298f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5299c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5300703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != OutputExpr;
5301c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
5303703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
5304c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5305703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the inputs.
5306703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5307ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getInputIdentifier(I));
5308c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5309703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
53103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getInputConstraintLiteral(I));
5311c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5312703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the input expr.
5313703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *InputExpr = S->getInputExpr(I);
531460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(InputExpr);
5315703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
5316f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5317c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5318703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != InputExpr;
5319c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
5321703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
5322c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5323703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
53243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5325703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5326703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the clobbers.
5327703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
53283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Clobbers.push_back(S->getClobber(I));
5329703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5330703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // No need to transform the asm string literal.
5331703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  AsmString = SemaRef.Owned(S->getAsmString());
5332703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5333703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5334703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isSimple(),
5335703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isVolatile(),
5336703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumOutputs(),
5337703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumInputs(),
5338a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson                                     Names.data(),
5339703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Constraints),
5340703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Exprs),
53419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     AsmString.get(),
5342703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Clobbers),
5343703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getRParenLoc(),
5344703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isMSAsm());
534543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
534643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
534743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
534843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
534960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
53501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
53514dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body of the @try.
535260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
53534dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (TryBody.isInvalid())
5354f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5355c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53568f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  // Transform the @catch statements (if present).
53578f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  bool AnyCatchChanged = false;
5358ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> CatchStmts(SemaRef);
53598f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
536060d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
53614dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Catch.isInvalid())
5362f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
53638f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    if (Catch.get() != S->getCatchStmt(I))
53648f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      AnyCatchChanged = true;
53658f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    CatchStmts.push_back(Catch.release());
53664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
5367c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the @finally statement (if present).
536960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Finally;
53704dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (S->getFinallyStmt()) {
53714dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    Finally = getDerived().TransformStmt(S->getFinallyStmt());
53724dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Finally.isInvalid())
5373f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
53744dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
53754dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
53764dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
53774dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
53784dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      TryBody.get() == S->getTryBody() &&
53798f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      !AnyCatchChanged &&
53804dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Finally.get() == S->getFinallyStmt())
53813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5382c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53834dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
53849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
53859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           move_arg(CatchStmts), Finally.get());
538643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
53871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
538843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
538960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
53901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5391be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  // Transform the @catch parameter, if there is one.
5392be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *Var = 0;
5393be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (VarDecl *FromVar = S->getCatchParamDecl()) {
5394be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    TypeSourceInfo *TSInfo = 0;
5395be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (FromVar->getTypeSourceInfo()) {
5396be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5397be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (!TSInfo)
5398f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5399be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
5400c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5401be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    QualType T;
5402be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (TSInfo)
5403be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = TSInfo->getType();
5404be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    else {
5405be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = getDerived().TransformType(FromVar->getType());
5406be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (T.isNull())
5407f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5408be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
5409c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5410be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5411be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (!Var)
5412f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5413be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
5414c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
541560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5416be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (Body.isInvalid())
5417f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5418c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5419c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5420be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                             S->getRParenLoc(),
54219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Var, Body.get());
542243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
542443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
542560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54261eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
54274dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body.
542860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
54294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (Body.isInvalid())
5430f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5431c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
54334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
54344dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Body.get() == S->getFinallyBody())
54353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
54364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
54374dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
54384dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
54399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                               Body.get());
544043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
544243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
544360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
544560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand;
5446d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (S->getThrowExpr()) {
5447d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    Operand = getDerived().TransformExpr(S->getThrowExpr());
5448d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    if (Operand.isInvalid())
5449f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5450d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
5451c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5452d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5453d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor      Operand.get() == S->getThrowExpr())
54543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return getSema().Owned(S);
5455c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
545743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
545943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
546060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
546143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
54621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCAtSynchronizedStmt *S) {
54638fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the object we are locking.
546460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
54658fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Object.isInvalid())
5466f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5467c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54688fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the body.
546960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
54708fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Body.isInvalid())
5471f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54738fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // If nothing change, just retain the current statement.
54748fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
54758fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Object.get() == S->getSynchExpr() &&
54768fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Body.get() == S->getSynchBody())
54773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
54788fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor
54798fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Build a new statement.
54808fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
54819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    Object.get(), Body.get());
548243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
548343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
548443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
548560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
5486f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5487f85e193739c953358c865005855253af4f68a497John McCall                                              ObjCAutoreleasePoolStmt *S) {
5488f85e193739c953358c865005855253af4f68a497John McCall  // Transform the body.
5489f85e193739c953358c865005855253af4f68a497John McCall  StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5490f85e193739c953358c865005855253af4f68a497John McCall  if (Body.isInvalid())
5491f85e193739c953358c865005855253af4f68a497John McCall    return StmtError();
5492f85e193739c953358c865005855253af4f68a497John McCall
5493f85e193739c953358c865005855253af4f68a497John McCall  // If nothing changed, just retain this statement.
5494f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
5495f85e193739c953358c865005855253af4f68a497John McCall      Body.get() == S->getSubStmt())
5496f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(S);
5497f85e193739c953358c865005855253af4f68a497John McCall
5498f85e193739c953358c865005855253af4f68a497John McCall  // Build a new statement.
5499f85e193739c953358c865005855253af4f68a497John McCall  return getDerived().RebuildObjCAutoreleasePoolStmt(
5500f85e193739c953358c865005855253af4f68a497John McCall                        S->getAtLoc(), Body.get());
5501f85e193739c953358c865005855253af4f68a497John McCall}
5502f85e193739c953358c865005855253af4f68a497John McCall
5503f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
5504f85e193739c953358c865005855253af4f68a497John McCallStmtResult
550543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt(
55061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCForCollectionStmt *S) {
5507c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the element statement.
550860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Element = getDerived().TransformStmt(S->getElement());
5509c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Element.isInvalid())
5510f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5511c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5512c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the collection expression.
551360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5514c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Collection.isInvalid())
5515f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5516c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5517c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the body.
551860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
5519c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Body.isInvalid())
5520f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5521c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5522c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // If nothing changed, just retain this statement.
5523c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
5524c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Element.get() == S->getElement() &&
5525c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Collection.get() == S->getCollection() &&
5526c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Body.get() == S->getBody())
55273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5528c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5529c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Build a new statement.
5530c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5531c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   /*FIXME:*/S->getForLoc(),
55329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Element.get(),
55339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Collection.get(),
5534c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   S->getRParenLoc(),
55359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Body.get());
553643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
553743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
553843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
553943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
554060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
554143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
554243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the exception declaration, if any.
554343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  VarDecl *Var = 0;
554443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (S->getExceptionDecl()) {
554543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    VarDecl *ExceptionDecl = S->getExceptionDecl();
554683cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    TypeSourceInfo *T = getDerived().TransformType(
554783cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getTypeSourceInfo());
554883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    if (!T)
5549f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
55501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
555183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
5552ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getInnerLocStart(),
5553ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getLocation(),
5554ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getIdentifier());
5555ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor    if (!Var || Var->isInvalidDecl())
5556f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
555743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
55581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
555943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the actual exception handler.
556060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5561ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor  if (Handler.isInvalid())
5562f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
55631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
556443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
556543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !Var &&
556643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Handler.get() == S->getHandlerBlock())
55673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
556843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
556943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
557043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          Var,
55719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Handler.get());
557243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
55731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
557443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
557560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
557643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
557743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the try block itself.
557860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBlock
557943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    = getDerived().TransformCompoundStmt(S->getTryBlock());
558043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (TryBlock.isInvalid())
5581f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
55821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
558343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the handlers.
558443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool HandlerChanged = false;
5585ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Handlers(SemaRef);
558643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
558760d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Handler
558843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      = getDerived().TransformCXXCatchStmt(S->getHandler(I));
558943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Handler.isInvalid())
5590f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
55911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
559243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
559343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Handlers.push_back(Handler.takeAs<Stmt>());
559443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
55951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
559643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
559743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      TryBlock.get() == S->getTryBlock() &&
559843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !HandlerChanged)
55993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
560043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
56019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
56021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        move_arg(Handlers));
560343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
56041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5605ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived>
5606ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult
5607ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5608ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5609ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Range.isInvalid())
5610ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5611ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5612ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5613ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (BeginEnd.isInvalid())
5614ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5615ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5616ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ExprResult Cond = getDerived().TransformExpr(S->getCond());
5617ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Cond.isInvalid())
5618ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5619ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5620ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ExprResult Inc = getDerived().TransformExpr(S->getInc());
5621ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Inc.isInvalid())
5622ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5623ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5624ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5625ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (LoopVar.isInvalid())
5626ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5627ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5628ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult NewStmt = S;
5629ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (getDerived().AlwaysRebuild() ||
5630ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Range.get() != S->getRangeStmt() ||
5631ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      BeginEnd.get() != S->getBeginEndStmt() ||
5632ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Cond.get() != S->getCond() ||
5633ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Inc.get() != S->getInc() ||
5634ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      LoopVar.get() != S->getLoopVarStmt())
5635ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5636ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getColonLoc(), Range.get(),
5637ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  BeginEnd.get(), Cond.get(),
5638ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  Inc.get(), LoopVar.get(),
5639ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getRParenLoc());
5640ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5641ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult Body = getDerived().TransformStmt(S->getBody());
5642ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Body.isInvalid())
5643ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5644ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5645ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // Body has changed but we didn't rebuild the for-range statement. Rebuild
5646ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // it now so we have a new statement to attach the body to.
5647ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Body.get() != S->getBody() && NewStmt.get() == S)
5648ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5649ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getColonLoc(), Range.get(),
5650ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  BeginEnd.get(), Cond.get(),
5651ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  Inc.get(), LoopVar.get(),
5652ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getRParenLoc());
5653ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5654ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (NewStmt.get() == S)
5655ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return SemaRef.Owned(S);
5656ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5657ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5658ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
5659ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
566028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
566128bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
566228bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
566328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult TryBlock; //  = getDerived().TransformCompoundStmt(S->getTryBlock());
566428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(TryBlock.isInvalid()) return StmtError();
566528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
566628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
566728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(!getDerived().AlwaysRebuild() &&
566828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley     TryBlock.get() == S->getTryBlock() &&
566928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley     Handler.get() == S->getHandler())
567028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SemaRef.Owned(S);
567128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
567228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
567328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        S->getTryLoc(),
567428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        TryBlock.take(),
567528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        Handler.take());
567628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
567728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
567828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
567928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
568028bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
568128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
568228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(Block.isInvalid()) return StmtError();
568328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
568428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
568528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                            Block.take());
568628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
568728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
568828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
568928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
569028bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
569128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
569228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(FilterExpr.isInvalid()) return StmtError();
569328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
569428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
569528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(Block.isInvalid()) return StmtError();
569628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
569728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
569828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                           FilterExpr.take(),
569928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                           Block.take());
570028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
570128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
570228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
570328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
570428bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
570528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(isa<SEHFinallyStmt>(Handler))
570628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
570728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  else
570828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
570928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
571028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
571143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
5712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation
5713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
57141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
571560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5716454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
57173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
57181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
57191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
572160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5722454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
572340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
572440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  if (E->getQualifierLoc()) {
572540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    QualifierLoc
572640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
572740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!QualifierLoc)
5728f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5729a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5730dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5731dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *ND
57327c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
57337c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getDecl()));
5734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!ND)
5735f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5737ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  DeclarationNameInfo NameInfo = E->getNameInfo();
5738ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  if (NameInfo.getName()) {
5739ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5740ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    if (!NameInfo.getName())
5741f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5742ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  }
57432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
57442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!getDerived().AlwaysRebuild() &&
574540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      QualifierLoc == E->getQualifierLoc() &&
5746a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ND == E->getDecl() &&
57472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NameInfo.getName() == E->getDecl()->getDeclName() &&
5748096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
57491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5750dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // Mark it referenced in the new context regardless.
5751dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: this is a bit instantiation-specific.
5752dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5753a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
57543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5755a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5756dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5757dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
5758096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
5759dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TemplateArgs = &TransArgs;
5760dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
5761dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
5762fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5763fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
5764fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
5765fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
5766dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
5767dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
576840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
576940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                                         TemplateArgs);
5770577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
57711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
577360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5774454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
57753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5776577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
57771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
577960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5780454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
57813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
578560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5786454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
57873fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
579160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5792454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
57933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
579760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5798454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
57993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
580360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5804f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5805f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult ControllingExpr =
5806f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    getDerived().TransformExpr(E->getControllingExpr());
5807f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  if (ControllingExpr.isInvalid())
5808f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return ExprError();
5809f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5810f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  llvm::SmallVector<Expr *, 4> AssocExprs;
5811f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5812f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5813f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5814f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (TS) {
5815f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5816f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      if (!AssocType)
5817f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne        return ExprError();
5818f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      AssocTypes.push_back(AssocType);
5819f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    } else {
5820f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      AssocTypes.push_back(0);
5821f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    }
5822f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5823f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5824f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (AssocExpr.isInvalid())
5825f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      return ExprError();
5826f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    AssocExprs.push_back(AssocExpr.release());
5827f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
5828f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5829f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5830f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getDefaultLoc(),
5831f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getRParenLoc(),
5832f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  ControllingExpr.release(),
5833f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  AssocTypes.data(),
5834f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  AssocExprs.data(),
5835f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getNumAssocs());
5836f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}
5837f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5838f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived>
5839f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult
5840454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
584160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5843f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
58463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
5849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       E->getRParen());
5850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
58521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
585360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5854454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
585560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5857f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5859b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
58603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getOpcode(),
58649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get());
5865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
586860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
58698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
58708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform the type.
58718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
58728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!Type)
5873f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5874c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
58758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform all of the components into components similar to what the
58768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // parser uses.
5877c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // FIXME: It would be slightly more efficient in the non-dependent case to
5878c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // just map FieldDecls, rather than requiring the rebuilder to look for
5879c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // the fields again. However, __builtin_offsetof is rare enough in
58808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // template code that we don't care.
58818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool ExprChanged = false;
5882f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::OffsetOfComponent Component;
58838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef OffsetOfExpr::OffsetOfNode Node;
58848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  llvm::SmallVector<Component, 4> Components;
58858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
58868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const Node &ON = E->getComponent(I);
58878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Component Comp;
588872be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor    Comp.isBrackets = true;
588906dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara    Comp.LocStart = ON.getSourceRange().getBegin();
589006dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara    Comp.LocEnd = ON.getSourceRange().getEnd();
58918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    switch (ON.getKind()) {
58928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Array: {
58938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
589460d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(FromIndex);
58958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (Index.isInvalid())
5896f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
5897c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
58988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      ExprChanged = ExprChanged || Index.get() != FromIndex;
58998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = true;
59009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Comp.U.E = Index.get();
59018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
59028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5903c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Field:
59058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Identifier:
59068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = false;
59078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.U.IdentInfo = ON.getFieldName();
590829d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor      if (!Comp.U.IdentInfo)
590929d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor        continue;
5910c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
5912c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5913cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    case Node::Base:
5914cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      // Will be recomputed during the rebuild.
5915cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      continue;
59168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5917c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Components.push_back(Comp);
59198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
5920c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // If nothing changed, retain the existing expression.
59228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
59238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Type == E->getTypeSourceInfo() &&
59248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      !ExprChanged)
59253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5926c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Build a new offsetof expression.
59288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
59298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          Components.data(), Components.size(),
59308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          E->getRParenLoc());
59317cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}
59327cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
59337cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived>
59347cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult
59357cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
59367cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  assert(getDerived().AlreadyTransformed(E->getType()) &&
59377cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall         "opaque value expression requires transformation");
59387cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  return SemaRef.Owned(E);
59398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
59408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
59418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived>
594260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5943f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5944f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                UnaryExprOrTypeTraitExpr *E) {
5945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isArgumentType()) {
5946a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *OldT = E->getArgumentTypeInfo();
59475557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor
5948a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *NewT = getDerived().TransformType(OldT);
59495ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!NewT)
5950f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
59511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59525ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!getDerived().AlwaysRebuild() && OldT == NewT)
59533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
59541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5955f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5956f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                    E->getKind(),
5957f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                    E->getSourceRange());
5958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
59591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
596060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr;
59611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  {
5962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // C++0x [expr.sizeof]p1:
5963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   The operand is either an expression, which is an unevaluated operand
5964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   [...]
5965f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
59661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
5969f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
59701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
59723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
5973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
59741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5975f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5976f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getOperatorLoc(),
5977f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getKind(),
5978f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getSourceRange());
5979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
598260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5983454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
598460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5986f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
598860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5989b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5990f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5993b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5995b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
59963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
59971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
5999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           /*FIXME:*/E->getLHS()->getLocStart(),
60009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                RHS.get(),
6001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getRBracketLoc());
6002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
600560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6006454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the callee.
600860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
6010f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform arguments.
6013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgChanged = false;
6014ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6015aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6016aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
6017aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6018aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
6021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgChanged)
60223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Wrong source location information for the '('.
60251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLParenLoc
6026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = ((Expr *)Callee.get())->getSourceRange().getBegin();
60279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      move_arg(Args),
6029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
6030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
603360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6034454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
603560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
6037f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
603940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
604083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (E->hasQualifier()) {
604140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    QualifierLoc
604240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
604340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor
604440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!QualifierLoc)
6045f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
604683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
60471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6048f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *Member
60497c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
60507c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getMemberDecl()));
6051b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Member)
6052f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60546bb8017bb9e828d118e15e59d71c66bba323c364John McCall  NamedDecl *FoundDecl = E->getFoundDecl();
60556bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (FoundDecl == E->getMemberDecl()) {
60566bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = Member;
60576bb8017bb9e828d118e15e59d71c66bba323c364John McCall  } else {
60586bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = cast_or_null<NamedDecl>(
60596bb8017bb9e828d118e15e59d71c66bba323c364John McCall                   getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
60606bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!FoundDecl)
6061f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
60626bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
60636bb8017bb9e828d118e15e59d71c66bba323c364John McCall
6064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6065b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase() &&
606640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      QualifierLoc == E->getQualifierLoc() &&
60678a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor      Member == E->getMemberDecl() &&
60686bb8017bb9e828d118e15e59d71c66bba323c364John McCall      FoundDecl == E->getFoundDecl() &&
6069096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
6070c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
60711f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // Mark it referenced in the new context regardless.
60721f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // FIXME: this is a bit instantiation-specific.
60731f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
60743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60751f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson  }
6076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6077d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs;
6078096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
6079d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
6080d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
6081fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6082fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
6083fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
6084fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
60858a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor  }
6086c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bogus source location for the operator
6088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeOperatorLoc
6089b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6091c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
6092c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
6093c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
6094c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
6095c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
6096c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
60979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isArrow(),
609940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                                        QualifierLoc,
61002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                        E->getMemberNameInfo(),
61018a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor                                        Member,
61026bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        FoundDecl,
6103096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                        (E->hasExplicitTemplateArgs()
6104d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                           ? &TransArgs : 0),
6105c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                        FirstQualifierInScope);
6106b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
610960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6110454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
611160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6113f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
611560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6116b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6117f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6119b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
61223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
61259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            LHS.get(), RHS.get());
6126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
61281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
612960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator(
6131454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CompoundAssignOperator *E) {
6132454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformBinaryOperator(E);
6133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
613656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>::
613756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
613856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // Just rebuild the common and RHS expressions and see whether we
613956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // get any changes.
614056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
614156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
614256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (commonExpr.isInvalid())
614356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
614456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
614556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
614656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (rhs.isInvalid())
614756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
614856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
614956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (!getDerived().AlwaysRebuild() &&
615056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      commonExpr.get() == e->getCommon() &&
615156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      rhs.get() == e->getFalseExpr())
615256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return SemaRef.Owned(e);
615356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
615456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  return getDerived().RebuildConditionalOperator(commonExpr.take(),
615556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getQuestionLoc(),
615656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 0,
615756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getColonLoc(),
615856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 rhs.get());
615956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}
616056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
616156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived>
616260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6163454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
616460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
6165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
6166f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
616860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6170f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
617260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6174f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
6178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
61803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildConditionalOperator(Cond.get(),
618347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getQuestionLoc(),
61849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 LHS.get(),
618547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getColonLoc(),
61869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 RHS.get());
6187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
619060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6191454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6192a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // Implicit casts are eliminated during transformation, since they
6193a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // will be recomputed by semantic analysis after transformation.
61946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return getDerived().TransformExpr(E->getSubExprAsWritten());
6195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
619860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6199454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6200ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6201ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6202ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
6203ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
620460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
62056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6207f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6210ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
62123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62149d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6215ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                            Type,
6216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc(),
62179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            SubExpr.get());
6218b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
622160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6222454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
622342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *OldT = E->getTypeSourceInfo();
622442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
622542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  if (!NewT)
6226f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
622860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6229b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
6230f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
623342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      OldT == NewT &&
6234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInitializer())
62353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6236b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62371d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // Note: the expression type doesn't necessarily match the
62381d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // type-as-written, but that's okay, because it should always be
62391d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // derivable from the initializer.
62401d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
624142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6242b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   /*FIXME:*/E->getInitializer()->getLocEnd(),
62439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Init.get());
6244b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6246b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
624760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6248454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
624960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6250b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
6251f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6253b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase())
62553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6257b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bad source location
62581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeOperatorLoc
6259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
62609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessorLoc(),
6262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessor());
6263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
626660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6267454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool InitChanged = false;
62691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6270ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
6271aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6272aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  Inits, &InitChanged))
6273aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6274aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && !InitChanged)
62763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
6279e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                      E->getRBraceLoc(), E->getType());
6280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
628360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6284454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
6285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Designation Desig;
62861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
628743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the initializer value
628860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInit());
6289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
6290f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
629243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the designators.
6293ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
6294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ExprChanged = false;
6295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             DEnd = E->designators_end();
6297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       D != DEnd; ++D) {
6298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isFieldDesignator()) {
6299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Desig.AddDesignator(Designator::getField(D->getFieldName(),
6300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getDotLoc(),
6301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getFieldLoc()));
6302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
6303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
63041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isArrayDesignator()) {
630660d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
6307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Index.isInvalid())
6308f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
63091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Desig.AddDesignator(Designator::getArray(Index.get(),
6311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getLBracketLoc()));
63121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArrayExprs.push_back(Index.release());
6315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
6316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
63171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(D->isArrayRangeDesignator() && "New kind of designator?");
631960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Start
6320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Start.isInvalid())
6322f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
632460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
6325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (End.isInvalid())
6326f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Desig.AddDesignator(Designator::getArrayRange(Start.get(),
6329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  End.get(),
6330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getLBracketLoc(),
6331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getEllipsisLoc()));
63321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      End.get() != E->getArrayRangeEnd(*D);
63351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(Start.release());
6337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(End.release());
6338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
63391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInit() &&
6342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ExprChanged)
63433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getEqualOrColonLoc(),
63479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                E->usesGNUSyntax(), Init.get());
6348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
635160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr(
6353454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     ImplicitValueInitExpr *E) {
63545557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
6355c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
63565557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // FIXME: Will we ever have proper type location here? Will we actually
63575557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // need to transform the type?
6358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
6359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
6360f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6363b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType())
63643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildImplicitValueInitExpr(T);
6367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
637060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6371454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
63729bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
63739bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo)
6374f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
637660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6378f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
63812cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      TInfo == E->getWrittenTypeInfo() &&
6382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
63833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
63862cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                       TInfo, E->getRParenLoc());
6387b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6388b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6389b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
639060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6391454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
6392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6393ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
6394aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6395aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
6396aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6397aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6398b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           move_arg(Inits),
6400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getRParenLoc());
6401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression.
6404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
6405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always
6406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to
6407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis.
6408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
640960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6410454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
641157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
641257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        E->getLabel());
641357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
641457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return ExprError();
641557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
6416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
641757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                           cast<LabelDecl>(LD));
6418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
642160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6422454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
642360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt
6424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubStmt.isInvalid())
6426f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubStmt.get() == E->getSubStmt())
64303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
64339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      SubStmt.get(),
6434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
6435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
643860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6439454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
644060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
6441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
6442f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
644460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6446f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
644860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6450f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6452b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
6454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6455b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
64563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
64599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Cond.get(), LHS.get(), RHS.get(),
6460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->getRParenLoc());
6461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
646460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6465454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
64663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6467b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
647060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6471454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
6472668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  switch (E->getOperator()) {
6473668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_New:
6474668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Delete:
6475668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_New:
6476668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_Delete:
6477668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
6478f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6479c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6480668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Call: {
6481668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // This is a call to an object's operator().
6482668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6483668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6484668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the object itself.
648560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Object = getDerived().TransformExpr(E->getArg(0));
6486668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    if (Object.isInvalid())
6487f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6488668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6489668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // FIXME: Poor location information
6490668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    SourceLocation FakeLParenLoc
6491668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      = SemaRef.PP.getLocForEndOfToken(
6492668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                              static_cast<Expr *>(Object.get())->getLocEnd());
6493668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6494668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the call arguments.
6495ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> Args(SemaRef);
6496aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6497aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                    Args))
6498aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return ExprError();
6499668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
65009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
6501668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        move_arg(Args),
6502668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        E->getLocEnd());
6503668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
6504668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6505668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6506668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_##Name:
6507668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6508668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def"
6509668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Subscript:
6510668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Handled below.
6511668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    break;
6512668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6513668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Conditional:
6514668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("conditional operator is not actually overloadable");
6515f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6516668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6517668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_None:
6518668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case NUM_OVERLOADED_OPERATORS:
6519668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("not an overloaded operator?");
6520f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6521668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
6522668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
652360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
6525f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
652760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult First = getDerived().TransformExpr(E->getArg(0));
6528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (First.isInvalid())
6529f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
653160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Second;
6532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->getNumArgs() == 2) {
6533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Second = getDerived().TransformExpr(E->getArg(1));
6534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Second.isInvalid())
6535f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
65371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
6540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      First.get() == E->getArg(0) &&
65411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
65423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
65431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 E->getOperatorLoc(),
65469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Callee.get(),
65479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 First.get(),
65489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Second.get());
6549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
655260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6553454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6554454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCallExpr(E);
6555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
6558e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult
6559e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6560e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform the callee.
6561e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6562e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (Callee.isInvalid())
6563e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6564e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6565e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform exec config.
6566e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6567e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (EC.isInvalid())
6568e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6569e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6570e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform arguments.
6571e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  bool ArgChanged = false;
6572e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ASTOwningVector<Expr*> Args(SemaRef);
6573e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6574e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                  &ArgChanged))
6575e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6576e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6577e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (!getDerived().AlwaysRebuild() &&
6578e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      Callee.get() == E->getCallee() &&
6579e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      !ArgChanged)
6580e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return SemaRef.Owned(E);
6581e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6582e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // FIXME: Wrong source location information for the '('.
6583e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  SourceLocation FakeLParenLoc
6584e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    = ((Expr *)Callee.get())->getSourceRange().getBegin();
6585e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6586e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      move_arg(Args),
6587e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      E->getRParenLoc(), EC.get());
6588e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}
6589e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6590e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived>
659160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6592454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
6593ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6594ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6595ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
6596ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
659760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
65986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6600f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6603ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
66053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Poor source location information here.
66081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLAngleLoc
6609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRParenLoc
6612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(
6613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  E->getSubExpr()->getSourceRange().getEnd());
6614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
66151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              E->getStmtClass(),
6616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeLAngleLoc,
6617ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                              Type,
6618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
6619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
66209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              SubExpr.get(),
6621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRParenLoc);
6622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
662560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6626454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6627454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
663160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6632454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6633454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6636b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
663760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr(
6639454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CXXReinterpretCastExpr *E) {
6640454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
664460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6645454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6646454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
665060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr(
6652454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXFunctionalCastExpr *E) {
6653ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6654ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6655ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
66561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
665760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
66586eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6660f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6663ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
66653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6667ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  return getDerived().RebuildCXXFunctionalCastExpr(Type,
6668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      /*FIXME:*/E->getSubExpr()->getLocStart(),
66699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr.get(),
6670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   E->getRParenLoc());
6671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
667460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6675454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
6676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isTypeOperand()) {
667757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    TypeSourceInfo *TInfo
667857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      = getDerived().TransformType(E->getTypeOperandSourceInfo());
667957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    if (!TInfo)
6680f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
66811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
668357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        TInfo == E->getTypeOperandSourceInfo())
66843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
66851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
668657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return getDerived().RebuildCXXTypeidExpr(E->getType(),
668757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             E->getLocStart(),
668857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             TInfo,
6689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getLocEnd());
6690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
66911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // We don't know whether the expression is potentially evaluated until
6693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // after we perform semantic analysis, so the expression is potentially
6694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // potentially evaluated.
66951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  EnterExpressionEvaluationContext Unevaluated(SemaRef,
6696f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      Sema::PotentiallyPotentiallyEvaluated);
66971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
669860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6700f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getExprOperand())
67043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
670657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  return getDerived().RebuildCXXTypeidExpr(E->getType(),
670757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                           E->getLocStart(),
67089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get(),
6709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLocEnd());
6710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
671360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
671401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
671501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (E->isTypeOperand()) {
671601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    TypeSourceInfo *TInfo
671701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      = getDerived().TransformType(E->getTypeOperandSourceInfo());
671801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!TInfo)
671901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      return ExprError();
672001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
672101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!getDerived().AlwaysRebuild() &&
672201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet        TInfo == E->getTypeOperandSourceInfo())
67233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
672401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
67253c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor    return getDerived().RebuildCXXUuidofExpr(E->getType(),
672601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocStart(),
672701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             TInfo,
672801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocEnd());
672901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
673001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
673101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // We don't know whether the expression is potentially evaluated until
673201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // after we perform semantic analysis, so the expression is potentially
673301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // potentially evaluated.
673401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
673501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
673601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
673701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (SubExpr.isInvalid())
673801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return ExprError();
673901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
674001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (!getDerived().AlwaysRebuild() &&
674101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      SubExpr.get() == E->getExprOperand())
67423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
674301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
674401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  return getDerived().RebuildCXXUuidofExpr(E->getType(),
674501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocStart(),
674601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           SubExpr.get(),
674701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocEnd());
674801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}
674901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
675001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived>
675101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult
6752454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
67533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
675760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
6759454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXNullPtrLiteralExpr *E) {
67603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
676460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6765454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
6766ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  DeclContext *DC = getSema().getFunctionLevelDeclContext();
67677a614d8380297fcd2bc23986241905d97222948cRichard Smith  QualType T;
67687a614d8380297fcd2bc23986241905d97222948cRichard Smith  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
67697a614d8380297fcd2bc23986241905d97222948cRichard Smith    T = MD->getThisType(getSema().Context);
67707a614d8380297fcd2bc23986241905d97222948cRichard Smith  else
67717a614d8380297fcd2bc23986241905d97222948cRichard Smith    T = getSema().Context.getPointerType(
67727a614d8380297fcd2bc23986241905d97222948cRichard Smith      getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
67731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6774ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!getDerived().AlwaysRebuild() && T == E->getType())
67753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6777828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
6778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
678160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6782454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
678360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6785f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
67893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
67919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
6792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
679560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6796454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
67971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParmVarDecl *Param
67987c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
67997c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           E->getParam()));
6800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Param)
6801f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
680353cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth  if (!getDerived().AlwaysRebuild() &&
6804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Param == E->getParam())
68053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
68061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6807036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
6808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
68091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
681160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6812ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6813ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXScalarValueInitExpr *E) {
6814ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6815ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6816f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6817ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
6818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6819ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo())
68203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
68211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6822ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXScalarValueInitExpr(T,
6823ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
6824ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor                                                    E->getRParenLoc());
6825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
68261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
682860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6829454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
6830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the type that we're allocating
68311bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocTypeInfo
68321bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
68331bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  if (!AllocTypeInfo)
6834f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the size of the array we're allocating (if any).
683760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
6838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (ArraySize.isInvalid())
6839f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the placement arguments (if any).
6842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6843ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> PlacementArgs(SemaRef);
6844aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getPlacementArgs(),
6845aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  E->getNumPlacementArgs(), true,
6846aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  PlacementArgs, &ArgumentChanged))
6847aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
68481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
684943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the constructor arguments (if any).
6850ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
6851aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6852aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     ConstructorArgs, &ArgumentChanged))
6853aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
68541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform constructor, new operator, and delete operator.
68561af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  CXXConstructorDecl *Constructor = 0;
68571af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getConstructor()) {
68581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    Constructor = cast_or_null<CXXConstructorDecl>(
68597c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
68607c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
68611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!Constructor)
6862f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
68641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
68651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorNew = 0;
68661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorNew()) {
68671af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorNew = cast_or_null<FunctionDecl>(
68687c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(E->getLocStart(),
68697c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getOperatorNew()));
68701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorNew)
6871f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
68731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
68741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
68751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
68761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
68777c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
68787c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
68791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6880f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68811af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6882c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
68841bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor      AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
6885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArraySize.get() == E->getArraySize() &&
68861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Constructor == E->getConstructor() &&
68871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorNew == E->getOperatorNew() &&
68881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete() &&
68891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      !ArgumentChanged) {
68901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
68911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
68921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (Constructor)
68931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
68941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorNew)
68951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
68961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
68971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
68983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
68991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
69001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69011bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  QualType AllocType = AllocTypeInfo->getType();
69025b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  if (!ArraySize.get()) {
69035b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // If no array size was specified, but the new expression was
69045b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with an array type (e.g., "new T" where T is
69055b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with "int[4]"), extract the outer bound from the
69065b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // array type as our array size. We do this with constant and
69075b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // dependently-sized array types.
69085b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
69095b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    if (!ArrayT) {
69105b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      // Do nothing
69115b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const ConstantArrayType *ConsArrayT
69125b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                                     = dyn_cast<ConstantArrayType>(ArrayT)) {
6913c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      ArraySize
69149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
69159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               ConsArrayT->getSize(),
69169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               SemaRef.Context.getSizeType(),
69179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               /*FIXME:*/E->getLocStart()));
69185b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      AllocType = ConsArrayT->getElementType();
69195b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const DependentSizedArrayType *DepArrayT
69205b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                              = dyn_cast<DependentSizedArrayType>(ArrayT)) {
69215b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      if (DepArrayT->getSizeExpr()) {
69223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall        ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
69235b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor        AllocType = DepArrayT->getElementType();
69245b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      }
69255b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    }
69265b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  }
69271bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
6928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6929b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isGlobalNew(),
6930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
6931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(PlacementArgs),
6932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
69334bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                        E->getTypeIdParens(),
6934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        AllocType,
69351bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                        AllocTypeInfo,
69369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        ArraySize.get(),
6937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
6938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(ConstructorArgs),
69391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        E->getLocEnd());
6940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
694360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6944454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
694560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
6946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Operand.isInvalid())
6947f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
69481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69491af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform the delete operator, if known.
69501af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
69511af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
69521af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
69537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
69547c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
69551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6956f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
69571af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6958c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
69601af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Operand.get() == E->getArgument() &&
69611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete()) {
69621af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
69631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
69641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
69651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
69665833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
69675833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    if (!E->getArgument()->isTypeDependent()) {
69685833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      QualType Destroyed = SemaRef.Context.getBaseElementType(
69695833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                                         E->getDestroyedType());
69705833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
69715833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
69725833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        SemaRef.MarkDeclarationReferenced(E->getLocStart(),
69735833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                          SemaRef.LookupDestructor(Record));
69745833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      }
69755833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    }
69765833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
69773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
69781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
69791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isGlobalDelete(),
6982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isArrayForm(),
69839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Operand.get());
6984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
698760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6988a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
6989454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXPseudoDestructorExpr *E) {
699060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6991a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  if (Base.isInvalid())
6992f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
69931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6994b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ObjectTypePtr;
6995a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  bool MayBePseudoDestructor = false;
69969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
6997a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              E->getOperatorLoc(),
6998a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        E->isArrow()? tok::arrow : tok::period,
6999a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              ObjectTypePtr,
7000a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              MayBePseudoDestructor);
7001a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (Base.isInvalid())
7002f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7003c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7004b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  QualType ObjectType = ObjectTypePtr.get();
7005f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7006f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  if (QualifierLoc) {
7007f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    QualifierLoc
7008f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7009f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    if (!QualifierLoc)
701043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      return ExprError();
701143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
7012f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  CXXScopeSpec SS;
7013f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  SS.Adopt(QualifierLoc);
70141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7015a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage Destroyed;
7016a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (E->getDestroyedTypeInfo()) {
7017a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    TypeSourceInfo *DestroyedTypeInfo
701843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7019b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                ObjectType, 0, SS);
7020a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!DestroyedTypeInfo)
7021f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7022a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = DestroyedTypeInfo;
7023a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else if (ObjectType->isDependentType()) {
7024a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // We aren't likely to be able to resolve the identifier down to a type
7025a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // now anyway, so just retain the identifier.
7026a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7027a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                            E->getDestroyedTypeLoc());
7028a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else {
7029a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // Look for a destructor known with the given name.
7030b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7031a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              *E->getDestroyedTypeIdentifier(),
7032a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                E->getDestroyedTypeLoc(),
7033a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                /*Scope=*/0,
7034a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                SS, ObjectTypePtr,
7035a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                false);
7036a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!T)
7037f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7038c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7039a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed
7040a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7041a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                 E->getDestroyedTypeLoc());
7042a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
704326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
704426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *ScopeTypeInfo = 0;
704526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (E->getScopeTypeInfo()) {
704643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
704726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    if (!ScopeTypeInfo)
7048f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7049a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
7050c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
70519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7052a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->getOperatorLoc(),
7053a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->isArrow(),
7054f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                                     SS,
705526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     ScopeTypeInfo,
705626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getColonColonLoc(),
7057fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                     E->getTildeLoc(),
7058a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                     Destroyed);
7059a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}
70601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7061a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived>
706260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7063ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr(
7064454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  UnresolvedLookupExpr *Old) {
7065f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7066f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                 Sema::LookupOrdinaryName);
7067f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7068f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Transform all the decls.
7069f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7070f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall         E = Old->decls_end(); I != E; ++I) {
70717c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
70727c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(Old->getNameLoc(),
70737c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                            *I));
70749f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
70759f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
70769f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
70779f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
70789f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
70799f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
7080f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
70819f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
7082f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7083f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // Expand using declarations.
7084f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (isa<UsingDecl>(InstD)) {
7085f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
7086f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7087f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall             E = UD->shadow_end(); I != E; ++I)
7088f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        R.addDecl(*I);
7089f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      continue;
7090f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    }
7091f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7092f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    R.addDecl(InstD);
7093f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
7094f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7095f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Resolve a kind, but don't do any further analysis.  If it's
7096f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // ambiguous, the callee needs to deal with it.
7097f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  R.resolveKind();
7098f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7099f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Rebuild the nested-name qualifier, if present.
7100f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  CXXScopeSpec SS;
71014c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  if (Old->getQualifierLoc()) {
71024c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    NestedNameSpecifierLoc QualifierLoc
71034c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
71044c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (!QualifierLoc)
7105f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7106c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
71074c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    SS.Adopt(QualifierLoc);
7108c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
7109c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7110c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (Old->getNamingClass()) {
711166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    CXXRecordDecl *NamingClass
711266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
711366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                            Old->getNameLoc(),
711466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
711566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
7116f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7117c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
711866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
7119f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
7120f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7121f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have no template arguments, it's a normal declaration name.
7122f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!Old->hasExplicitTemplateArgs())
7123f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7124f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7125f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have template arguments, rebuild them, then rebuild the
7126f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // templateid expression.
7127f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
7128fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7129fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              Old->getNumTemplateArgs(),
7130fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7131fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
7132f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7133f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7134f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                            TransArgs);
7135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
713860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7139454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
71403d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
71413d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  if (!T)
7142f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
71431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7144b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
71453d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      T == E->getQueriedTypeSourceInfo())
71463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
71471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocStart(),
7150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            T,
7151b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocEnd());
7152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
715560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
71566ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
71576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
71586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!LhsT)
71596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
71606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
71626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!RhsT)
71636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
71646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!getDerived().AlwaysRebuild() &&
71666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
71676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SemaRef.Owned(E);
71686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
71706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocStart(),
71716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            LhsT, RhsT,
71726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocEnd());
71736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}
71746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived>
71766ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult
717721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
717821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
717921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  if (!T)
718021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return ExprError();
718121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
718221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  if (!getDerived().AlwaysRebuild() &&
718321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      T == E->getQueriedTypeSourceInfo())
718421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return SemaRef.Owned(E);
718521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
718621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult SubExpr;
718721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  {
718821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
718921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
719021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    if (SubExpr.isInvalid())
719121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      return ExprError();
719221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
719321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
719421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      return SemaRef.Owned(E);
719521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
719621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
719721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  return getDerived().RebuildArrayTypeTrait(E->getTrait(),
719821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            E->getLocStart(),
719921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            T,
720021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            SubExpr.get(),
720121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            E->getLocEnd());
720221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley}
720321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
720421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived>
720521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult
7206552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7207552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult SubExpr;
7208552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  {
7209552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7210552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7211552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    if (SubExpr.isInvalid())
7212552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      return ExprError();
7213552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7214552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7215552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      return SemaRef.Owned(E);
7216552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
7217552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7218552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  return getDerived().RebuildExpressionTrait(
7219552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7220552622067dc45013d240f73952fece703f5e63bdJohn Wiegley}
7221552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7222552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived>
7223552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult
7224865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
72252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                               DependentScopeDeclRefExpr *E) {
722600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc
722700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
722800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  if (!QualifierLoc)
7229f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
723143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
723243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
723343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
723443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
72352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
72362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
72372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
7238f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7240f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!E->hasExplicitTemplateArgs()) {
7241f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!getDerived().AlwaysRebuild() &&
724200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor        QualifierLoc == E->getQualifierLoc() &&
72432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // Note: it is sufficient to compare the Name component of NameInfo:
72442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // if name has not changed, DNLoc has not changed either.
72452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getDeclName())
72463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
72471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
724800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
72492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                         NameInfo,
7250f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         /*TemplateArgs*/ 0);
7251f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor  }
7252d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
7253d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7254fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7255fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
7256fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7257fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
7258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
725900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
72602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
7261f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       &TransArgs);
7262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7264b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
726560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7266454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
7267321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // CXXConstructExprs are always implicit, so when we have a
7268321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // 1-argument construction we just transform that argument.
7269321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  if (E->getNumArgs() == 1 ||
7270321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor      (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7271321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor    return getDerived().TransformExpr(E->getArg(0));
7272321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor
7273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7274b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
7276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
7277f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
7280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
72817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(E->getLocStart(),
72827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
7283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
7284f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7287ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7288aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7289aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
7290aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7291aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
7292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType() &&
7294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
7295c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor      !ArgumentChanged) {
72961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark the constructor as referenced.
72971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: Instantiation-specific
7298c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
72993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7300c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor  }
73011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73024411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
73034411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                              Constructor, E->isElidable(),
73048c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              move_arg(Args),
73058c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              E->requiresZeroInitialization(),
7306428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getConstructionKind(),
7307428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getParenRange());
7308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression.
7311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
73125132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
73135132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that.
7314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
731560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7316454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
73175132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
7318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73204765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should
73214765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated.
7322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
73234765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we
73245132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that.
7325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
732660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
73274765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
73285132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
7329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
733260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
7334ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXTemporaryObjectExpr *E) {
7335ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7336ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
7337f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
7340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
7341c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                  getDerived().TransformDecl(E->getLocStart(),
73427c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
7343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
7344f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7347ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Args.reserve(E->getNumArgs());
7349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7350aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
7351aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
73521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7354ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
7355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
735691be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      !ArgumentChanged) {
735791be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    // FIXME: Instantiation-specific
7358ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
73593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.MaybeBindToTemporary(E);
736091be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor  }
7361ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
7362ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXTemporaryObjectExpr(T,
7363ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
7364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    move_arg(Args),
7365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    E->getLocEnd());
7366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
736960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
7371454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  CXXUnresolvedConstructExpr *E) {
7372ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7373ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
7374f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7376b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7377ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7378aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->arg_size());
7379aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7380aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
7381aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7382aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
7383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7384ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
7385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
73863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
73871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7388b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: we're faking the locations of the commas
7389ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
7390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getLParenLoc(),
7391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        move_arg(Args),
7392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getRParenLoc());
7393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
739660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7397865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
73982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                             CXXDependentScopeMemberExpr *E) {
7399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the base of the expression.
740060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
7401aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *OldBase;
7402aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
7403aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType ObjectType;
7404aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->isImplicitAccess()) {
7405aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = E->getBase();
7406aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(OldBase);
7407aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7408f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
74091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7410aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    // Start the member reference and compute the object's type.
7411b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ObjectTy;
7412d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor    bool MayBePseudoDestructor = false;
74139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7414aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                E->getOperatorLoc(),
7415a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                      E->isArrow()? tok::arrow : tok::period,
7416d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                ObjectTy,
7417d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                MayBePseudoDestructor);
7418aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7419f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7420aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
7421b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ObjectType = ObjectTy.get();
7422aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
7423aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
7424aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = 0;
7425aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(E->getBaseType());
7426aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7427aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
74281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74296cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // Transform the first part of the nested-name-specifier that qualifies
74306cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // the member name.
7431c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierInScope
74326cd219879ffce00920189ec1dcea927a42602961Douglas Gregor    = getDerived().TransformFirstQualifierInScope(
74337c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                            E->getFirstQualifierFoundInScope(),
74347c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                            E->getQualifierLoc().getBeginLoc());
74351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74367c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
7437a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  if (E->getQualifier()) {
74387c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    QualifierLoc
74397c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
74407c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     ObjectType,
74417c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     FirstQualifierInScope);
74427c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    if (!QualifierLoc)
7443f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7444a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  }
74451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
744643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
744743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
744843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
744943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
74502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
745143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
74522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
7453f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
74541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7455aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->hasExplicitTemplateArgs()) {
74563b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // This is a reference to a member without an explicitly-specified
74573b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // template argument list. Optimize for this common case.
74583b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
7459aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        Base.get() == OldBase &&
7460aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        BaseType == E->getBaseType() &&
74617c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor        QualifierLoc == E->getQualifierLoc() &&
74622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getMember() &&
74633b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        FirstQualifierInScope == E->getFirstQualifierFoundInScope())
74643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
74651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
7467aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                       BaseType,
74683b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->isArrow(),
74693b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getOperatorLoc(),
74707c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                       QualifierLoc,
7471129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       FirstQualifierInScope,
74722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
7473129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       /*TemplateArgs*/ 0);
74743b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
74753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor
7476d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7477fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7478fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
7479fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7480fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
74811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
7483aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                     BaseType,
7484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->isArrow(),
7485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->getOperatorLoc(),
74867c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     QualifierLoc,
74873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                     FirstQualifierInScope,
74882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                     NameInfo,
7489129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                     &TransArgs);
7490129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}
7491129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7492129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived>
749360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7494454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
7495129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform the base of the expression.
749660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
7497aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
7498aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!Old->isImplicitAccess()) {
7499aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(Old->getBase());
7500aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7501f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7502aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
7503aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
7504aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(Old->getBaseType());
7505aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
7506129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
75074c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
75084c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  if (Old->getQualifierLoc()) {
75094c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    QualifierLoc
75104c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
75114c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (!QualifierLoc)
7512f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7513129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7514129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
75152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  LookupResult R(SemaRef, Old->getMemberNameInfo(),
7516129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                 Sema::LookupOrdinaryName);
7517129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7518129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform all the decls.
7519129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7520129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         E = Old->decls_end(); I != E; ++I) {
75217c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
75227c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(Old->getMemberLoc(),
75237c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           *I));
75249f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
75259f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
75269f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
75279f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
75289f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
752934f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis      else {
753034f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis        R.clear();
7531f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
753234f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis      }
75339f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
7534129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7535129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    // Expand using declarations.
7536129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (isa<UsingDecl>(InstD)) {
7537129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
7538129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7539129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall             E = UD->shadow_end(); I != E; ++I)
7540129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall        R.addDecl(*I);
7541129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      continue;
7542129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
7543129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7544129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    R.addDecl(InstD);
7545129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7546129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7547129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  R.resolveKind();
7548129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7549c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  // Determine the naming class.
7550042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth  if (Old->getNamingClass()) {
7551c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    CXXRecordDecl *NamingClass
7552c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
755366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                          Old->getMemberLoc(),
755466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
755566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
7556f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7557c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
755866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
7559c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  }
7560c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7561129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  TemplateArgumentListInfo TransArgs;
7562129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->hasExplicitTemplateArgs()) {
7563129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setLAngleLoc(Old->getLAngleLoc());
7564129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setRAngleLoc(Old->getRAngleLoc());
7565fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7566fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                Old->getNumTemplateArgs(),
7567fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
7568fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
7569129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7570c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
7571c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
7572c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
7573c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
7574c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
7575c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
7576c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
75779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
7578aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  BaseType,
7579129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getOperatorLoc(),
7580129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->isArrow(),
75814c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                                  QualifierLoc,
7582c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                                  FirstQualifierInScope,
7583129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  R,
7584129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              (Old->hasExplicitTemplateArgs()
7585129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  ? &TransArgs : 0));
7586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
758960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
75902e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7591eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
75922e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
75932e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (SubExpr.isInvalid())
75942e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return ExprError();
75952e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
75962e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
75973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
75982e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
75992e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
76002e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}
76012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
76022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived>
76032e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult
7604be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
76054f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
76064f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (Pattern.isInvalid())
76074f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return ExprError();
76084f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
76094f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
76104f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return SemaRef.Owned(E);
76114f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
761267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
761367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                           E->getNumExpansions());
7614be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}
7615ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7616ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived>
7617ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult
7618ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7619ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // If E is not value-dependent, then nothing will change when we transform it.
7620ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: This is an instantiation-centric view.
7621ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (!E->isValueDependent())
7622ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
7623ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7624ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: None of the implementations of TryExpandParameterPacks can ever
7625ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // produce a diagnostic when given only a single unexpanded parameter pack,
7626ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // so
7627ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7628ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  bool ShouldExpand = false;
7629d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  bool RetainExpansion = false;
7630cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> NumExpansions;
7631ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7632ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                           &Unexpanded, 1,
7633d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           ShouldExpand, RetainExpansion,
7634d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           NumExpansions))
7635ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return ExprError();
7636ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7637d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  if (!ShouldExpand || RetainExpansion)
7638ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
7639be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
7640ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // We now know the length of the parameter pack, so build a new expression
7641ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // that stores that length.
7642ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7643ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                            E->getPackLoc(), E->getRParenLoc(),
7644cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                            *NumExpansions);
7645ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}
7646ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7647be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived>
7648be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult
7649c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7650c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                          SubstNonTypeTemplateParmPackExpr *E) {
7651c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Default behavior is to do nothing with this transformation.
7652c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  return SemaRef.Owned(E);
7653c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}
7654c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
7655c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived>
7656c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult
7657454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
76583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
76611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
766260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7663454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
766481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  TypeSourceInfo *EncodedTypeInfo
766581d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
766681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  if (!EncodedTypeInfo)
7667f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
76681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
767081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
76713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
767481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                            EncodedTypeInfo,
7675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc());
7676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
76771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
7679f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>::
7680f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7681f85e193739c953358c865005855253af4f68a497John McCall  ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7682f85e193739c953358c865005855253af4f68a497John McCall  if (result.isInvalid()) return ExprError();
7683f85e193739c953358c865005855253af4f68a497John McCall  Expr *subExpr = result.take();
7684f85e193739c953358c865005855253af4f68a497John McCall
7685f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
7686f85e193739c953358c865005855253af4f68a497John McCall      subExpr == E->getSubExpr())
7687f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(E);
7688f85e193739c953358c865005855253af4f68a497John McCall
7689f85e193739c953358c865005855253af4f68a497John McCall  return SemaRef.Owned(new(SemaRef.Context)
7690f85e193739c953358c865005855253af4f68a497John McCall      ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7691f85e193739c953358c865005855253af4f68a497John McCall}
7692f85e193739c953358c865005855253af4f68a497John McCall
7693f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
7694f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>::
7695f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7696f85e193739c953358c865005855253af4f68a497John McCall  TypeSourceInfo *TSInfo
7697f85e193739c953358c865005855253af4f68a497John McCall    = getDerived().TransformType(E->getTypeInfoAsWritten());
7698f85e193739c953358c865005855253af4f68a497John McCall  if (!TSInfo)
7699f85e193739c953358c865005855253af4f68a497John McCall    return ExprError();
7700f85e193739c953358c865005855253af4f68a497John McCall
7701f85e193739c953358c865005855253af4f68a497John McCall  ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7702f85e193739c953358c865005855253af4f68a497John McCall  if (Result.isInvalid())
7703f85e193739c953358c865005855253af4f68a497John McCall    return ExprError();
7704f85e193739c953358c865005855253af4f68a497John McCall
7705f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
7706f85e193739c953358c865005855253af4f68a497John McCall      TSInfo == E->getTypeInfoAsWritten() &&
7707f85e193739c953358c865005855253af4f68a497John McCall      Result.get() == E->getSubExpr())
7708f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(E);
7709f85e193739c953358c865005855253af4f68a497John McCall
7710f85e193739c953358c865005855253af4f68a497John McCall  return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7711f85e193739c953358c865005855253af4f68a497John McCall                                      E->getBridgeKeywordLoc(), TSInfo,
7712f85e193739c953358c865005855253af4f68a497John McCall                                      Result.get());
7713f85e193739c953358c865005855253af4f68a497John McCall}
7714f85e193739c953358c865005855253af4f68a497John McCall
7715f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
771660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7717454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
771892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Transform arguments.
771992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  bool ArgChanged = false;
7720ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7721aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->getNumArgs());
7722aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7723aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
7724aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7725aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
772692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
772792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Class message: transform the receiver type.
772892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    TypeSourceInfo *ReceiverTypeInfo
772992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      = getDerived().TransformType(E->getClassReceiverTypeInfo());
773092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!ReceiverTypeInfo)
7731f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7732c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
773392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // If nothing changed, just retain the existing message send.
773492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
773592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor        ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
77363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
773792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
773892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Build a new class message send.
773992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
774092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getSelector(),
7741f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                               E->getSelectorLoc(),
774292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getMethodDecl(),
774392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getLeftLoc(),
774492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               move_arg(Args),
774592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getRightLoc());
774692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
774792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
774892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Instance message: transform the receiver
774992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
775092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         "Only class and instance messages may be instantiated");
775160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Receiver
775292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    = getDerived().TransformExpr(E->getInstanceReceiver());
775392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (Receiver.isInvalid())
7754f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
775592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
775692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // If nothing changed, just retain the existing message send.
775792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
775892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
77593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7760c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
776192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Build a new instance message send.
77629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
776392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getSelector(),
7764f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                             E->getSelectorLoc(),
776592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getMethodDecl(),
776692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getLeftLoc(),
776792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             move_arg(Args),
776892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getRightLoc());
7769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
77711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
777260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7773454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
77743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
77771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
777860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7779454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
77803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
77831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
778460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7785454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
7786f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
778760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7788f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7789f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7790f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor
7791f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // We don't need to transform the ivar; it will never change.
7792c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7793f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7794f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7795f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
77963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7797c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
77989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
7799f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->getLocation(),
7800f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->isArrow(), E->isFreeIvar());
7801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
780460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7805454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
780612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // 'super' and types never change. Property never changes. Just
780712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // retain the existing expression.
780812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (!E->isObjectReceiver())
78093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
78108ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian
7811e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // Transform the base expression.
781260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7813e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (Base.isInvalid())
7814f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7815c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7816e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // We don't need to transform the property; it will never change.
7817c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7818e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // If nothing changed, just retain the existing expression.
7819e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7820e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      Base.get() == E->getBase())
78213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
782312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (E->isExplicitProperty())
782412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
782512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getExplicitProperty(),
782612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getLocation());
782712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall
782812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
782912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getType(),
783012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertyGetter(),
783112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertySetter(),
783212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getLocation());
7833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
783660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7837454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
7838f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
783960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7840f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7841f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7842c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7843f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7844f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7845f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
78463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7847c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
78489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
7849f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                         E->isArrow());
7850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
785360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7854454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
7855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7856ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> SubExprs(SemaRef);
7857aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  SubExprs.reserve(E->getNumSubExprs());
7858aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7859aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  SubExprs, &ArgumentChanged))
7860aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
78611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
78643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
78651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move_arg(SubExprs),
7868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               E->getRParenLoc());
7869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
787260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7873454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
7874c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockDecl *oldBlock = E->getBlockDecl();
7875a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7876c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7877c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7878c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7879c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7880ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // We built a new blockScopeInfo in call to ActOnBlockStart
7881ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // in above, CapturesCXXThis need be set here from the block
7882ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // expression.
7883ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7884ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian
7885c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  llvm::SmallVector<ParmVarDecl*, 4> params;
7886c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  llvm::SmallVector<QualType, 4> paramTypes;
7887a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7888a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Parameter substitution.
7889c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7890c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_begin(),
7891c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_size(),
7892c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               0, paramTypes, &params))
7893a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return true;
7894c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7895c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  const FunctionType *exprFunctionType = E->getFunctionType();
7896c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType exprResultType = exprFunctionType->getResultType();
7897c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!exprResultType.isNull()) {
7898c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    if (!exprResultType->isDependentType())
7899c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      blockScope->ReturnType = exprResultType;
7900c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    else if (exprResultType != getSema().Context.DependentTy)
7901c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      blockScope->ReturnType = getDerived().TransformType(exprResultType);
7902a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7903a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7904a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type has not been determined yet, leave it as a dependent
7905a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // type; it'll get set when we process the body.
7906c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType.isNull())
7907c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->ReturnType = getSema().Context.DependentTy;
7908a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7909a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // Don't allow returning a objc interface by value.
7910c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType->isObjCObjectType()) {
7911c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    getSema().Diag(E->getCaretLocation(),
7912a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                   diag::err_object_cannot_be_passed_returned_by_value)
7913c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      << 0 << blockScope->ReturnType;
7914a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return ExprError();
7915a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  }
7916711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7917c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType functionType = getDerived().RebuildFunctionProtoType(
7918c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        blockScope->ReturnType,
7919c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.data(),
7920c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.size(),
7921c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        oldBlock->isVariadic(),
7922c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                        0, RQ_None,
7923c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               exprFunctionType->getExtInfo());
7924c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->FunctionType = functionType;
7925711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7926711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Set the parameters on the block decl.
7927c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!params.empty())
7928c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->TheDecl->setParams(params.data(), params.size());
7929a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7930a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type wasn't explicitly set, it will have been marked as a
7931a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // dependent type (DependentTy); clear out the return type setting so
7932a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // we will deduce the return type when type-checking the block's body.
7933c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType == getSema().Context.DependentTy)
7934c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->ReturnType = QualType();
7935a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7936711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Transform the body
7937c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  StmtResult body = getDerived().TransformStmt(E->getBody());
7938c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (body.isInvalid())
7939711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    return ExprError();
7940711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7941c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG
7942c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // In builds with assertions, make sure that we captured everything we
7943c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // captured before.
7944fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor  if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7945fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor    for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7946fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor           e = oldBlock->capture_end(); i != e; ++i) {
7947fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      VarDecl *oldCapture = i->getVariable();
7948fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor
7949fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      // Ignore parameter packs.
7950fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      if (isa<ParmVarDecl>(oldCapture) &&
7951fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor          cast<ParmVarDecl>(oldCapture)->isParameterPack())
7952fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor        continue;
7953c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7954fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      VarDecl *newCapture =
7955fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor        cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7956fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor                                                 oldCapture));
7957fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      assert(blockScope->CaptureMap.count(newCapture));
7958fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor    }
7959c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  }
7960c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif
7961c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7962c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7963c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                    /*Scope=*/0);
7964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
79661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
796760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7968454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
7969a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  ValueDecl *ND
7970a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7971a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                       E->getDecl()));
7972a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!ND)
7973f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
79742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
7975a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!getDerived().AlwaysRebuild() &&
7976a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      ND == E->getDecl()) {
7977a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // Mark it referenced in the new context regardless.
7978a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // FIXME: this is a bit instantiation-specific.
7979a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7980a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
79813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7982a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7983a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
79842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
798540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
79862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, 0);
7987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
79881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
798961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnertemplate<typename Derived>
799061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerExprResult
799161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
799261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  assert(false && "Cannot transform asType expressions yet");
799361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  return SemaRef.Owned(E);
799461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}
799561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner
7996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
7997b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction
7998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
7999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
800185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
800285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                    SourceLocation Star) {
80032865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildPointerType(PointeeType, Star,
8004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  getDerived().getBaseEntity());
8005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8006b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
800885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
800985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                         SourceLocation Star) {
80102865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildBlockPointerType(PointeeType, Star,
8011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       getDerived().getBaseEntity());
8012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
80151eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
801685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
801785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             bool WrittenAsLValue,
801885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             SourceLocation Sigil) {
80192865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
802085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    Sigil, getDerived().getBaseEntity());
8021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
80241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
802585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
802685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 QualType ClassType,
802785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceLocation Sigil) {
80282865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
802985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        Sigil, getDerived().getBaseEntity());
8030577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8031577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8032577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
8034577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8035577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         ArrayType::ArraySizeModifier SizeMod,
8036577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         const llvm::APInt *Size,
8037577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         Expr *SizeExpr,
8038577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         unsigned IndexTypeQuals,
8039577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         SourceRange BracketsRange) {
8040577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (SizeExpr || !Size)
8041577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8042577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  IndexTypeQuals, BracketsRange,
8043577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  getDerived().getBaseEntity());
80441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType Types[] = {
80461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
80471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
80481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
8049577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  };
8050577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8051577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType SizeType;
8052577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  for (unsigned I = 0; I != NumTypes; ++I)
8053577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8054577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      SizeType = Types[I];
8055577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      break;
8056577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    }
80571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
80599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                           /*FIXME*/BracketsRange.getBegin());
80601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
8061577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                IndexTypeQuals, BracketsRange,
80621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                getDerived().getBaseEntity());
8063577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
80641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8065577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
80671eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
8068577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 ArrayType::ArraySizeModifier SizeMod,
8069577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 const llvm::APInt &Size,
807085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
807185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceRange BracketsRange) {
80721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
807385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        IndexTypeQuals, BracketsRange);
8074577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8075577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8076577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
80781eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
8079577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
808085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
808185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   SourceRange BracketsRange) {
80821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
808385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                       IndexTypeQuals, BracketsRange);
8084577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
80851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8086577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
80881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
8089577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
80909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SizeExpr,
8091577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 unsigned IndexTypeQuals,
8092577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceRange BracketsRange) {
80931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
80949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
8095577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
8096577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8097577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8098577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81001eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
8101577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
81029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Expr *SizeExpr,
8103577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                       unsigned IndexTypeQuals,
8104577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                   SourceRange BracketsRange) {
81051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
81069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
8107577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
8108577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8109577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8110577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
8112e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               unsigned NumElements,
8113e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               VectorType::VectorKind VecKind) {
8114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  // FIXME: semantic checking!
8115e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
8116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                      unsigned NumElements,
8121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceLocation AttributeLoc) {
8122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                          NumElements, true);
8124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  IntegerLiteral *VectorSize
81259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
81269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             AttributeLoc);
81279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
8128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81311eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
81339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                           Expr *SizeExpr,
8134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                  SourceLocation AttributeLoc) {
81359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
8136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
81401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          QualType *ParamTypes,
8141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                        unsigned NumParamTypes,
81421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          bool Variadic,
8143fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                          unsigned Quals,
8144c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                  RefQualifierKind RefQualifier,
8145fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                            const FunctionType::ExtInfo &Info) {
81461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
8147c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                   Quals, RefQualifier,
8148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   getDerived().getBaseLocation(),
8149fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   getDerived().getBaseEntity(),
8150fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   Info);
8151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8155a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return SemaRef.Context.getFunctionNoProtoType(T);
8156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
8157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
8158a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
8159ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8160ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  assert(D && "no decl found");
8161ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (D->isInvalidDecl()) return QualType();
8162ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
816392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // FIXME: Doesn't account for ObjCInterfaceDecl!
8164ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeDecl *Ty;
8165ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (isa<UsingDecl>(D)) {
8166ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    UsingDecl *Using = cast<UsingDecl>(D);
8167ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(Using->isTypeName() &&
8168ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-typename using");
8169ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8170ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    // A valid resolved using typename decl points to exactly one type decl.
8171ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(++Using->shadow_begin() == Using->shadow_end());
8172ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
8173c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8174ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  } else {
8175ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8176ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-using decl");
8177ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<UnresolvedUsingTypenameDecl>(D);
8178ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
8179ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8180ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return SemaRef.Context.getTypeDeclType(Ty);
8181ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
8182ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8183ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived>
81842a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
81852a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                       SourceLocation Loc) {
81862a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildTypeofExprType(E, Loc);
8187577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8188577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  return SemaRef.Context.getTypeOfType(Underlying);
8192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8194577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81952a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
81962a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                     SourceLocation Loc) {
81972a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildDecltypeType(E, Loc);
8198577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8199577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8200577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8201ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8202ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                            UnaryTransformType::UTTKind UKind,
8203ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                            SourceLocation Loc) {
8204ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8205ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
8206ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
8207ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived>
8208577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
8209833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                      TemplateName Template,
8210833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateNameLoc,
821167714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                     TemplateArgumentListInfo &TemplateArgs) {
8212d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
8213577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
82141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8215dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
82161eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
8217fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8218d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            bool TemplateKW,
8219d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            TemplateDecl *Template) {
8220fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
8221d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                                  Template);
8222d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
8223d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
8224d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
82251eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
8226fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8227fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            const IdentifierInfo &Name,
8228fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SourceLocation NameLoc,
822943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            QualType ObjectType,
823043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            NamedDecl *FirstQualifierInScope) {
8231fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  UnqualifiedId TemplateName;
8232fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName.setIdentifier(&Name, NameLoc);
8233d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
8234d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
8235fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       /*FIXME:*/SourceLocation(),
8236d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
8237fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       TemplateName,
8238b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
8239d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
8240d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
824143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return Template.get();
8242d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
82431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8244b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
8245ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName
8246fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8247ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            OverloadedOperatorKind Operator,
8248fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SourceLocation NameLoc,
8249ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            QualType ObjectType) {
8250ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  UnqualifiedId Name;
8251fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  // FIXME: Bogus location information.
8252fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8253fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
8254d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
8255d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
8256fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       /*FIXME:*/SourceLocation(),
8257d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
8258d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
8259b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
8260d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
8261d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
8262d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  return Template.template getAsVal<TemplateName>();
8263ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor}
8264c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8265ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived>
826660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   SourceLocation OpLoc,
82699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *OrigCallee,
82709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *First,
82719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *Second) {
82729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Callee = OrigCallee->IgnoreParenCasts();
82739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
82741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Determine whether this should be a builtin operation.
8276f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript) {
82779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
82789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType())
82799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinArraySubscriptExpr(First,
82809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Callee->getLocStart(),
82819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Second, OpLoc);
82821a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman  } else if (Op == OO_Arrow) {
82831a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman    // -> is never a builtin operation.
82849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
82859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  } else if (Second == 0 || isPostIncDec) {
82869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType()) {
8287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // The argument is not of overloadable type, so try to create a
8288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // built-in unary operation.
82892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      UnaryOperatorKind Opc
8290b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor        = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
82911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
82929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
8293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
8294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  } else {
82959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
82969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType()) {
8297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // Neither of the arguments is an overloadable type, so try to
8298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // create a built-in binary operation.
82992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
830060d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Result
83019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
8302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Result.isInvalid())
8303f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
83041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      return move(Result);
8306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
8307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
83081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Compute the transformed set of functions (and function templates) to be
8310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // used during overload resolution.
83116e26689f5d513e24ad7783a4493201930fdeccc0John McCall  UnresolvedSet<16> Functions;
83121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
8314ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    assert(ULE->requiresADL());
8315ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
8316ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // FIXME: Do we have to check
8317ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // IsAcceptableNonMemberOperatorCandidate for each of these?
83186e26689f5d513e24ad7783a4493201930fdeccc0John McCall    Functions.append(ULE->decls_begin(), ULE->decls_end());
8319ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  } else {
83209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
8321ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
83221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Add any functions found via argument-dependent lookup.
83249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Args[2] = { First, Second };
83259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  unsigned NumArgs = 1 + (Second != 0);
83261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8327b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for unary operators.
8328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (NumArgs == 1 || isPostIncDec) {
83292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    UnaryOperatorKind Opc
8330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
83319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
8332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
83331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8334f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript)
83359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
8336ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                                      OpLoc,
83379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      First,
83389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Second);
8339f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl
8340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for binary operators.
83412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
834260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result
8343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Result.isInvalid())
8345f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
83461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return move(Result);
8348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
83491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
835026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived>
835160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
83529ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
835326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceLocation OperatorLoc,
835426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       bool isArrow,
8355f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                                       CXXScopeSpec &SS,
835626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     TypeSourceInfo *ScopeType,
835726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       SourceLocation CCLoc,
8358fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                       SourceLocation TildeLoc,
8359a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed) {
83609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  QualType BaseType = Base->getType();
83619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
836226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      (!isArrow && !BaseType->getAs<RecordType>()) ||
8363c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      (isArrow && BaseType->getAs<PointerType>() &&
8364bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif       !BaseType->getAs<PointerType>()->getPointeeType()
8365bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif                                              ->template getAs<RecordType>())){
836626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    // This pseudo-destructor expression is still a pseudo-destructor.
83679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
836826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             isArrow? tok::arrow : tok::period,
8369fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                             SS, ScopeType, CCLoc, TildeLoc,
8370a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                             Destroyed,
837126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             /*FIXME?*/true);
837226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
83732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
8374a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
83752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
83762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
83772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
83782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  NameInfo.setNamedTypeInfo(DestroyedType);
83792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
838026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  // FIXME: the ScopeType should be tacked onto SS.
83812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
83829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getSema().BuildMemberReferenceExpr(Base, BaseType,
838326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            OperatorLoc, isArrow,
838426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            SS, /*FIXME: FirstQualifier*/ 0,
83852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            NameInfo,
838626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            /*TemplateArgs*/ 0);
838726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor}
838826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
8389577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang
8390577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8391577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
8392