TreeTransform.h revision c938c1668b4fd12af154e965dd935a89e4801a70
1a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall//===------- 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.
7577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===/
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//
12577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===/
13577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
162d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h"
17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h"
188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor#include "clang/Sema/ParsedTemplate.h"
19dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h"
20781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h"
21c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h"
227cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h"
23657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h"
24b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h"
25b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h"
2643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h"
2743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h"
2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h"
2919510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h"
3019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h"
31b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h"
32a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h"
337e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h"
34577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm>
35577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
36577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang {
37781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema;
381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one
40577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another.
41577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of
431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide
441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template
45577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the
46577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the
47577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar
48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and
49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters.
50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow
521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can
53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an
54577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The
55577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual.
56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which
58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node
59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions,
60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST
61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation
62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g.,
63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes
64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create
65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node.
66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The
68670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(),
69577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
70577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely
71577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations.
72577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the
74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
7543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
76577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation
771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template
78577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX
79577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change.
80577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild
81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may
82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps.
83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one
851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation
86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
87577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the
88577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking
89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()).
90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform {
92d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief Private RAII object that helps us forget and then re-remember
93d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// the template argument corresponding to a partially-substituted parameter
94d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack.
95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  class ForgetPartiallySubstitutedPackRAII {
96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    Derived &Self;
97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    TemplateArgument Old;
98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  public:
100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
101d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Old = Self.ForgetPartiallySubstitutedPack();
102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ~ForgetPartiallySubstitutedPackRAII() {
105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Self.RememberPartiallySubstitutedPack(Old);
106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  };
108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
109577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected:
110577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &SemaRef;
1118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Initializes a new tree transformer.
114b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
117577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Derived &getDerived() { return static_cast<Derived&>(*this); }
118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Derived &getDerived() const {
1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return static_cast<const Derived&>(*this);
122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
12460d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline ExprResult Owned(Expr *E) { return E; }
12560d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline StmtResult Owned(Stmt *S) { return S; }
1269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall
127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the semantic analysis object used for
128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// this tree transform.
129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &getSema() const { return SemaRef; }
1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Whether the transformation should always rebuild AST nodes, even
132577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// if none of the children have changed.
133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this function to specify when the transformation
135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// should rebuild all AST nodes.
136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlwaysRebuild() { return false; }
1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the location of the entity being transformed, if that
139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
1411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, returns no source-location information. Subclasses can
142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// provide an alternative implementation that provides better location
143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information.
144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  SourceLocation getBaseLocation() { return SourceLocation(); }
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the name of the entity being transformed, if that
147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, returns an empty name. Subclasses can provide an alternative
150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// implementation with a more precise name.
151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  DeclarationName getBaseEntity() { return DeclarationName(); }
152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Sets the "base" location and entity when that
154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// information is known based on another transformation.
155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, the source location and entity are ignored. Subclasses can
157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// override this function to provide a customized implementation.
158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  void setBase(SourceLocation Loc, DeclarationName Entity) { }
1591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief RAII object that temporarily sets the base location and entity
161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// used for reporting diagnostics in types.
162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  class TemporaryBase {
163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TreeTransform &Self;
164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SourceLocation OldLocation;
165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclarationName OldEntity;
1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  public:
168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TemporaryBase(TreeTransform &Self, SourceLocation Location,
1691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  DeclarationName Entity) : Self(Self) {
170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldLocation = Self.getDerived().getBaseLocation();
171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldEntity = Self.getDerived().getBaseEntity();
172ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor
173ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor      if (Location.isValid())
174ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor        Self.getDerived().setBase(Location, Entity);
175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
1761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ~TemporaryBase() {
178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Self.getDerived().setBase(OldLocation, OldEntity);
179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  };
1811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determine whether the given type \p T has already been
183577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// transformed.
184577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
185577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses can provide an alternative implementation of this routine
1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// to short-circuit evaluation when it is known that a given type will
187577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// not change. For example, template instantiation need not traverse
188577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// non-dependent types.
189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlreadyTransformed(QualType T) {
190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T.isNull();
191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
1936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether the given call argument should be dropped, e.g.,
1946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// because it is a default argument.
1956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
1966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Subclasses can provide an alternative implementation of this routine to
1976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// determine which kinds of call arguments get dropped. By default,
1986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// CXXDefaultArgument nodes are dropped (prior to transformation).
1996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool DropCallArgument(Expr *E) {
2006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return E->isDefaultArgument();
2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
202c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Determine whether we should expand a pack expansion with the
2048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// given set of parameter packs into separate arguments by repeatedly
2058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// transforming the pattern.
2068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
207b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  /// By default, the transformer never tries to expand pack expansions.
2088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// Subclasses can override this routine to provide different behavior.
2098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param EllipsisLoc The location of the ellipsis that identifies the
2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pack expansion.
2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param PatternRange The source range that covers the entire pattern of
2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// the pack expansion.
2158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param Unexpanded The set of unexpanded parameter packs within the
2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pattern.
2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumUnexpanded The number of unexpanded parameter packs in
2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \p Unexpanded.
2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param ShouldExpand Will be set to \c true if the transformer should
2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// expand the corresponding pack expansions into separate arguments. When
2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// set, \c NumExpansions must also be set.
2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
226d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \param RetainExpansion Whether the caller should add an unexpanded
227d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack expansion after all of the expanded arguments. This is used
228d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when extending explicitly-specified template argument packs per
229d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// C++0x [temp.arg.explicit]p9.
230d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
2318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumExpansions The number of separate arguments that will be in
232cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// the expanded form of the corresponding pack expansion. This is both an
233cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// input and an output parameter, which can be set by the caller if the
234cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// number of expansions is known a priori (e.g., due to a prior substitution)
235cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// and will be set by the callee when the number of expansions is known.
236cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// The callee must set this value when \c ShouldExpand is \c true; it may
237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// set this value in other cases.
2388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \returns true if an error occurred (e.g., because the parameter packs
2408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// are to be instantiated with arguments of different lengths), false
2418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
2428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// must be set.
2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
2448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               SourceRange PatternRange,
2458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               const UnexpandedParameterPack *Unexpanded,
2468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               unsigned NumUnexpanded,
2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               bool &ShouldExpand,
248d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                               bool &RetainExpansion,
249cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                               llvm::Optional<unsigned> &NumExpansions) {
2508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    ShouldExpand = false;
2518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return false;
2528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
2538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
254d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Forget" about the partially-substituted pack template argument,
255d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when performing an instantiation that must preserve the parameter pack
256d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
257d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  TemplateArgument ForgetPartiallySubstitutedPack() {
260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    return TemplateArgument();
261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  }
262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Remember" the partially-substituted pack template argument
264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// after performing an instantiation that must preserve the parameter pack
265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
266d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
27012c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// \brief Note to the derived class when a function parameter pack is
27112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// being expanded.
27212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
27312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor
274577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transforms the given type into another type.
275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
276a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by creating a
277a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// TypeSourceInfo for it and delegating to the appropriate
278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// function.  This is expensive, but we don't mind, because
279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// this method is deprecated anyway;  all users should be
280a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// switched to storing TypeSourceInfos.
281577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
282577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \returns the transformed type.
28343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(QualType T);
2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
285a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transforms the given type-with-location into a new
286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type-with-location.
287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ///
288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by delegating to the
289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// appropriate TransformXXXType to build a new type.  Subclasses
290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// may override this function (to take over all type
291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// transformations) or some set of the TransformXXXType functions
292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// to alter the transformation.
29343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transform the given type-with-location into a new
296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type, collecting location information in the given builder
297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// as necessary.
298577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
29943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
301657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given statement.
302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
3031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this routine transforms a statement by delegating to the
30443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// appropriate TransformXXXStmt function to transform a specific kind of
30543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// statement or the TransformExpr() function to transform an expression.
30643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to transform statements using some
30743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// other mechanism.
30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \returns the transformed statement.
31060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformStmt(Stmt *S);
3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
312657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given expression.
313657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  ///
314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine transforms an expression by delegating to the
315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// appropriate TransformXXXExpr function to build a new expression.
316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this function to transform expressions using some
317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// other mechanism.
318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \returns the transformed expression.
32060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformExpr(Expr *E);
3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
322aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Transform the given list of expressions.
323aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// This routine transforms a list of expressions by invoking
325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \c TransformExpr() for each subexpression. However, it also provides
326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// support for variadic templates by expanding any pack expansions (if the
327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// derived class permits such expansion) along the way. When pack expansions
328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// are present, the number of outputs may not equal the number of inputs.
329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Inputs The set of expressions to be transformed.
331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param NumInputs The number of expressions in \c Inputs.
333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param IsCall If \c true, then this transform is being performed on
335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// function-call arguments, and any arguments that should be dropped, will
336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// be.
337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Outputs The transformed input expressions will be added to this
339aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// vector.
340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// due to transformation.
343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \returns true if an error occurred, false otherwise.
345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                      llvm::SmallVectorImpl<Expr *> &Outputs,
347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                      bool *ArgChanged = 0);
348aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
349577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given declaration, which is referenced from a type
350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// or expression.
351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
352dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, acts as the identity function on declarations. Subclasses
353dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// may override this function to provide alternate behavior.
3547c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
35543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
35643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Transform the definition of the given declaration.
35743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, invokes TransformDecl() to transform the declaration.
35943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
361c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().TransformDecl(Loc, D);
3627c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  }
3631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3646cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// \brief Transform the given declaration, which was the first part of a
3656cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// nested-name-specifier in a member access expression.
3666cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
367c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// This specific declaration transformation only applies to the first
3686cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// identifier in a nested-name-specifier of a member access expression, e.g.,
3696cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// the \c T in \c x->T::member
3706cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
3716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// By default, invokes TransformDecl() to transform the declaration.
3726cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// Subclasses may override this function to provide alternate behavior.
373c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
374c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
3756cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  }
376c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
377577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given nested-name-specifier.
378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, transforms all of the types and declarations within the
380dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this function to provide
381dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// alternate behavior.
382577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
383a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                    SourceRange Range,
384c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                              QualType ObjectType = QualType(),
385c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                          NamedDecl *FirstQualifierInScope = 0);
3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// \brief Transform the given declaration name.
38881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  ///
38981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// By default, transforms the types of conversion function, constructor,
39081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// and destructor names and then (if needed) rebuilds the declaration name.
39181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// Identifiers and selectors are returned unmodified. Sublcasses may
39281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// override this function to provide alternate behavior.
3932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo
39443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
3951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template name.
3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
398d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, transforms the template name by transforming the declarations
3991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// and nested-name-specifiers that occur within the template name.
400d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
4013b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  TemplateName TransformTemplateName(TemplateName Name,
40243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                     QualType ObjectType = QualType(),
40343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                     NamedDecl *FirstQualifierInScope = 0);
4041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
405577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template argument.
406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this operation transforms the type, expression, or
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// declaration stored within the template argument and constructs a
409670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// new template argument from the transformed result. Subclasses may
410670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// override this function to provide alternate behavior.
411833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  ///
412833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// Returns true if there was an error.
413833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
414833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &Output);
415833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
416fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \brief Transform the given set of template arguments.
417fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
418fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// By default, this operation transforms all of the template arguments
419fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
420fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// the transformed arguments to the output list.
421fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
4227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// Note that this overload of \c TransformTemplateArguments() is merely
4237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// a convenience function. Subclasses that wish to override this behavior
4247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// should override the iterator-based member template version.
4257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
426fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Inputs The set of template arguments to be transformed.
427fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
428fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param NumInputs The number of template arguments in \p Inputs.
429fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
430fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Outputs The set of transformed template arguments output by this
431fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// routine.
432fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
433fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// Returns true if an error occurred.
434fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
435fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                  unsigned NumInputs,
4367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs) {
4377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
4387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
4397f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
4407f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \brief Transform the given set of template arguments.
4417f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4427f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// By default, this operation transforms all of the template arguments
4437f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
4447f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// the transformed arguments to the output list.
4457f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param First An iterator to the first template argument.
4477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
4487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param Last An iterator one step past the last template argument.
4497f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4507f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \param Outputs The set of transformed template arguments output by this
4517f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// routine.
4527f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4537f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// Returns true if an error occurred.
4547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename InputIterator>
4557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  bool TransformTemplateArguments(InputIterator First,
4567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  InputIterator Last,
4577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs);
4587f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
459833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
460833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
461833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &ArgLoc);
462833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
463a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// \brief Fakes up a TypeSourceInfo for a type.
464a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *InventTypeSourceInfo(QualType T) {
465a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return SemaRef.Context.getTrivialTypeSourceInfo(T,
466833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                       getDerived().getBaseLocation());
467833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
469a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT)                                   \
47143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
472a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
473577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
47443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
47543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
47643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateSpecializationTypeLoc TL,
47743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateName Template);
47843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
47943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
48043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
48143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentTemplateSpecializationTypeLoc TL,
48243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               NestedNameSpecifier *Prefix);
48343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
48421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms the parameters of a function type into the
48521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// given vectors.
48621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
48721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// The result vectors should be kept in sync; null entries in the
48821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// variables vector are acceptable.
48921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
49021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// Return true on error.
491a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  bool TransformFunctionTypeParams(SourceLocation Loc,
492a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   ParmVarDecl **Params, unsigned NumParams,
493a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   const QualType *ParamTypes,
49421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                                   llvm::SmallVectorImpl<QualType> &PTypes,
495a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
49621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
49721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms a single function-type parameter.  Return null
49821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// on error.
4996a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
5006a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                        llvm::Optional<unsigned> NumExpansions);
50121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
50243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
503833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
50460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
50560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                        \
50860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Transform##Node(Node *S);
509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                        \
51060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Transform##Node(Node *E);
5117381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
5124bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
514577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new pointer type given its pointee type.
515577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the pointer type.
517577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
51885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
519577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
520577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new block pointer type given its pointee type.
521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
5221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis when building the block pointer
523577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
52485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
525577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
52685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \brief Build a new reference type given the type it references.
527577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
52885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// By default, performs semantic analysis when building the
52985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// reference type. Subclasses may override this routine to provide
53085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// different behavior.
531577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
53285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \param LValue whether the type was written with an lvalue sigil
53385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// or an rvalue sigil.
53485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildReferenceType(QualType ReferentType,
53585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                bool LValue,
53685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                SourceLocation Sigil);
5371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
538577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new member pointer type given the pointee type and the
539577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// class type it refers into.
540577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
541577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the member pointer
542577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
54385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
54485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceLocation Sigil);
5451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
546577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new array type given the element type, size
547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, size of the array (if known), size expression, and index type
548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// qualifiers.
549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
551577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Also by default, all of the other Rebuild*Array
553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildArrayType(QualType ElementType,
554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            ArrayType::ArraySizeModifier SizeMod,
555577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            const llvm::APInt *Size,
556577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            Expr *SizeExpr,
557577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            unsigned IndexTypeQuals,
558577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            SourceRange BracketsRange);
5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
560577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new constant array type given the element type, size
561577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, (known) size of the array, and index type qualifiers.
562577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
563577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildConstantArrayType(QualType ElementType,
566577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
567577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    const llvm::APInt &Size,
56885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    unsigned IndexTypeQuals,
56985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceRange BracketsRange);
570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new incomplete array type given the element type, size
572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, and index type qualifiers.
573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildIncompleteArrayType(QualType ElementType,
577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                      ArrayType::ArraySizeModifier SizeMod,
57885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      unsigned IndexTypeQuals,
57985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      SourceRange BracketsRange);
580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new variable-length array type given the element type,
582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildVariableArrayType(QualType ElementType,
587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
5889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SizeExpr,
589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned IndexTypeQuals,
590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    SourceRange BracketsRange);
591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new dependent-sized array type given the element type,
593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
596577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedArrayType(QualType ElementType,
598577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
5999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *SizeExpr,
600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          unsigned IndexTypeQuals,
601577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          SourceRange BracketsRange);
602577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
603577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new vector type given the element type and
604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
60882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
609e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                             VectorType::VectorKind VecKind);
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
611577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new extended vector type given the element type and
612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
614577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                SourceLocation AttributeLoc);
6181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new potentially dependently-sized extended vector type
620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// given the element type and number of elements.
621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
6259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *SizeExpr,
626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                              SourceLocation AttributeLoc);
6271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new function type.
629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the function type.
631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildFunctionProtoType(QualType T,
6331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    QualType *ParamTypes,
634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned NumParamTypes,
635fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    bool Variadic, unsigned Quals,
636c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                    RefQualifierKind RefQualifier,
637fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    const FunctionType::ExtInfo &Info);
6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
639a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Build a new unprototyped function type.
640a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType RebuildFunctionNoProtoType(QualType ResultType);
641a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
642ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// \brief Rebuild an unresolved typename type, given the decl that
643ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// the UnresolvedUsingTypenameDecl was transformed to.
644ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType RebuildUnresolvedUsingType(Decl *D);
645ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
646577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typedef type.
647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypedefType(TypedefDecl *Typedef) {
648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Typedef);
649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
651577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new class/struct/union type.
652577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildRecordType(RecordDecl *Record) {
653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Record);
654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new Enum type.
657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildEnumType(EnumDecl *Enum) {
658577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Enum);
659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
6607da2431c23ef1ee8acb114e39692246e1801afc2John McCall
6611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(expr) type.
662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typeof type.
664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6652a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
666577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(type) type.
668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, builds a new TypeOfType with the given underlying type.
670577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypeOfType(QualType Underlying);
671577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++0x decltype type.
673577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the decltype type.
675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6762a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
678577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new template specialization type.
679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the template
681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// specialization type. Subclasses may override this routine to provide
682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTemplateSpecializationType(TemplateName Template,
684833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateLoc,
685d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                       const TemplateArgumentListInfo &Args);
6861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
687075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// \brief Build a new parenthesized type.
688075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ///
689075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// By default, builds a new ParenType type from the inner type.
690075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
691075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType RebuildParenType(QualType InnerType) {
692075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return SemaRef.Context.getParenType(InnerType);
693075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
694075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
695577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new qualified name type.
696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
697465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// By default, builds a new ElaboratedType type from the keyword,
698465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// the nested-name-specifier and the named type.
699465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
70021e413fe6305a198564d436ac515497716c47844John McCall  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
70121e413fe6305a198564d436ac515497716c47844John McCall                                 ElaboratedTypeKeyword Keyword,
702465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                                 NestedNameSpecifier *NNS, QualType Named) {
703465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
705577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
706577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to a template-id.
707577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
708e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// By default, builds a new DependentNameType type from the
709e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// nested-name-specifier and the given type. Subclasses may override
710e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// this routine to provide different behavior.
71133500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType RebuildDependentTemplateSpecializationType(
71233500955d731c73717af52088b7fc0e7a85681e7John McCall                                    ElaboratedTypeKeyword Keyword,
7131efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                    NestedNameSpecifier *Qualifier,
7141efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                    SourceRange QualifierRange,
71533500955d731c73717af52088b7fc0e7a85681e7John McCall                                    const IdentifierInfo *Name,
71633500955d731c73717af52088b7fc0e7a85681e7John McCall                                    SourceLocation NameLoc,
71733500955d731c73717af52088b7fc0e7a85681e7John McCall                                    const TemplateArgumentListInfo &Args) {
71833500955d731c73717af52088b7fc0e7a85681e7John McCall    // Rebuild the template name.
71933500955d731c73717af52088b7fc0e7a85681e7John McCall    // TODO: avoid TemplateName abstraction
72033500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateName InstName =
7211efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
72243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                       QualType(), 0);
72333500955d731c73717af52088b7fc0e7a85681e7John McCall
72496fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor    if (InstName.isNull())
72596fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor      return QualType();
72696fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor
72733500955d731c73717af52088b7fc0e7a85681e7John McCall    // If it's still dependent, make a dependent specialization.
72833500955d731c73717af52088b7fc0e7a85681e7John McCall    if (InstName.getAsDependentTemplateName())
72933500955d731c73717af52088b7fc0e7a85681e7John McCall      return SemaRef.Context.getDependentTemplateSpecializationType(
7301efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                          Keyword, Qualifier, Name, Args);
73133500955d731c73717af52088b7fc0e7a85681e7John McCall
73233500955d731c73717af52088b7fc0e7a85681e7John McCall    // Otherwise, make an elaborated type wrapping a non-dependent
73333500955d731c73717af52088b7fc0e7a85681e7John McCall    // specialization.
73433500955d731c73717af52088b7fc0e7a85681e7John McCall    QualType T =
73533500955d731c73717af52088b7fc0e7a85681e7John McCall      getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
73633500955d731c73717af52088b7fc0e7a85681e7John McCall    if (T.isNull()) return QualType();
737465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
73822f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara    // NOTE: NNS is already recorded in template specialization type T.
73922f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
742577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to an identifier.
743577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
744577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typename type
745e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// (or elaborated type). Subclasses may override this routine to provide
746577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
747e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
7484a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                                    NestedNameSpecifier *NNS,
7494a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                                    const IdentifierInfo *Id,
750e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation KeywordLoc,
751e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceRange NNSRange,
752e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation IdLoc) {
7534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    CXXScopeSpec SS;
7544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SS.setScopeRep(NNS);
755e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    SS.setRange(NNSRange);
756e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
7574033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (NNS->isDependent()) {
7584033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      // If the name is still dependent, just build a new dependent name type.
7594033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      if (!SemaRef.computeDeclContext(SS))
7604033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
7614033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
7624033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
763465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (Keyword == ETK_None || Keyword == ETK_Typename)
764e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
765e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                       KeywordLoc, NNSRange, IdLoc);
766465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
767465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
768465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
769e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    // We had a dependent elaborated-type-specifier that has been transformed
7704033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // into a non-dependent elaborated-type-specifier. Find the tag we're
7714033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // referring to.
772e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
7734033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    DeclContext *DC = SemaRef.computeDeclContext(SS, false);
7744033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!DC)
7754033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
7764033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
7775613876991c80a684595fe8de1f039296a0657ffJohn McCall    if (SemaRef.RequireCompleteDeclContext(SS, DC))
7785613876991c80a684595fe8de1f039296a0657ffJohn McCall      return QualType();
7795613876991c80a684595fe8de1f039296a0657ffJohn McCall
7804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    TagDecl *Tag = 0;
7814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SemaRef.LookupQualifiedName(Result, DC);
7824033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    switch (Result.getResultKind()) {
7834033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFound:
7844033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFoundInCurrentInstantiation:
7854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
786c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Found:
7884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        Tag = Result.getAsSingle<TagDecl>();
7894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
790c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7914033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundOverloaded:
7924033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundUnresolvedValue:
7934033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        llvm_unreachable("Tag lookup cannot find non-tags");
7944033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
795c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7964033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Ambiguous:
7974033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        // Let the LookupResult structure handle ambiguities.
7984033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
7994033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8004033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8014033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!Tag) {
802446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // Check where the name exists but isn't a tag type and use that to emit
803446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // better diagnostics.
804446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
805446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      SemaRef.LookupQualifiedName(Result, DC);
806446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      switch (Result.getResultKind()) {
807446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::Found:
808446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundOverloaded:
809446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundUnresolvedValue: {
810446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky	  NamedDecl *SomeDecl = Result.getRepresentativeDecl();
811446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          unsigned Kind = 0;
812446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
813446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
814446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
815446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
816446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
817446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky	}
818446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        default:
819446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          // FIXME: Would be nice to highlight just the source range.
820446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
821446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky            << Kind << Id << DC;
822446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
823446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      }
8244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
826465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
827e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
828e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
8294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
8304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8314033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8324033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8334033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // Build the elaborated-type-specifier type.
8344033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    QualType T = SemaRef.Context.getTypeDeclType(Tag);
835465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
836dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8382fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// \brief Build a new pack expansion type.
8392fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  ///
8402fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// By default, builds a new PackExpansionType type from the given pattern.
8412fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
8422fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType RebuildPackExpansionType(QualType Pattern,
8432fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                    SourceRange PatternRange,
844cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    SourceLocation EllipsisLoc,
845cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    llvm::Optional<unsigned> NumExpansions) {
846cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
847cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                        NumExpansions);
8482fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
8492fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
850dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and an
851dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// identifier that names the next step in the nested-name-specifier.
852dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
853dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
854dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
855dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
856dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
857dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
858a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                  IdentifierInfo &II,
859c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                  QualType ObjectType,
860c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                              NamedDecl *FirstQualifierInScope);
861dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
862dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and the
863dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// namespace named in the next step in the nested-name-specifier.
864dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
865dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
866dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
867dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
868dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
869dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
870dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  NamespaceDecl *NS);
871dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
872dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and the
873dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// type named in the next step in the nested-name-specifier.
874dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
875dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
876dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
877dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
878dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
879dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
880dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  bool TemplateKW,
881edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  QualType T);
882d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
883d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier, a flag
884d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// indicating whether the "template" keyword was provided, and the template
885d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// that the template name refers to.
886d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
887d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, builds the new template name directly. Subclasses may override
888d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// this routine to provide different behavior.
889d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
890d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   bool TemplateKW,
891d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   TemplateDecl *Template);
892d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
893d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier and the
894d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// name that is referred to as a template.
895d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
896d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
897d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
898d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// template name. Subclasses may override this routine to provide different
899d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// behavior.
900d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
9011efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                   SourceRange QualifierRange,
9023b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                   const IdentifierInfo &II,
90343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   QualType ObjectType,
90443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   NamedDecl *FirstQualifierInScope);
9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
906ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// \brief Build a new template name given a nested name specifier and the
907ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// overloaded operator name that is referred to as a template.
908ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  ///
909ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// By default, performs semantic analysis to determine whether the name can
910ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
911ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// template name. Subclasses may override this routine to provide different
912ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// behavior.
913ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
914ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   OverloadedOperatorKind Operator,
915ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   QualType ObjectType);
9161aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
9171aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// \brief Build a new template name given a template template parameter pack
9181aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// and the
9191aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  ///
9201aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
9211aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
9221aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// template name. Subclasses may override this routine to provide different
9231aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// behavior.
9241aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
9251aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                   const TemplateArgument &ArgPack) {
9261aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
9271aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  }
9281aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
92943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new compound statement.
93043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
93143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
93243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
93360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
93443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       MultiStmtArg Statements,
93543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       SourceLocation RBraceLoc,
93643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       bool IsStmtExpr) {
9379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
93843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       IsStmtExpr);
93943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
94043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
94143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new case statement.
94243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
94343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
94443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
94560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
9469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *LHS,
94743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EllipsisLoc,
9489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *RHS,
94943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation ColonLoc) {
9509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
95143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   ColonLoc);
95243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
95443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to a new case statement.
95543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
95643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
95743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
95860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
9599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().ActOnCaseStmtBody(S, Body);
9609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return S;
96143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new default statement.
96443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
96543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
96643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
96760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
96843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      SourceLocation ColonLoc,
9699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      Stmt *SubStmt) {
9709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
97143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      /*CurScope=*/0);
97243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new label statement.
97543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
97643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
97743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
97860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
97943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    IdentifierInfo *Id,
98043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    SourceLocation ColonLoc,
9811a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                    Stmt *SubStmt, bool HasUnusedAttr) {
9821a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis    return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
9831a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                  HasUnusedAttr);
98443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new "if" statement.
98743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
98843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
98943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
99060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
99144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                 VarDecl *CondVar, Stmt *Then,
9929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 SourceLocation ElseLoc, Stmt *Else) {
99344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis    return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Start building a new switch statement.
99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
99943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
100060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
10019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Cond, VarDecl *CondVar) {
10029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1003d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                            CondVar);
100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to the switch statement.
100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
100843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
101060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
10119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Stmt *Switch, Stmt *Body) {
10129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
101343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
101443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
101543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new while statement.
101643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
101743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
101843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
101960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1020eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor                                    Sema::FullExprArg Cond,
102199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor                                    VarDecl *CondVar,
10229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Stmt *Body) {
10239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
102443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new do-while statement.
102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
102843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
102943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
103060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
103143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation WhileLoc,
103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation LParenLoc,
10339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Expr *Cond,
103443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation RParenLoc) {
10359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
10369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Cond, RParenLoc);
103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
103843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
103943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new for statement.
104043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
104143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
104243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
104360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildForStmt(SourceLocation ForLoc,
104443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                  SourceLocation LParenLoc,
10459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Stmt *Init, Sema::FullExprArg Cond,
104699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor                                  VarDecl *CondVar, Sema::FullExprArg Inc,
10479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  SourceLocation RParenLoc, Stmt *Body) {
10489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1049d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                  CondVar,
10509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Inc, RParenLoc, Body);
105143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
105343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new goto statement.
105443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
105543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
105643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
105760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
105843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation LabelLoc,
105943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   LabelStmt *Label) {
106043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
106143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
106243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
106343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new indirect goto statement.
106443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
106543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
106643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
106760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
106843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                           SourceLocation StarLoc,
10699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *Target) {
10709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
107143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new return statement.
107443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
107543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
107643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
107760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
10789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Result) {
10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnReturnStmt(ReturnLoc, Result);
108143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new declaration statement.
108443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
108543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
108643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
108760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   SourceLocation StartLoc,
108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EndLoc) {
109043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return getSema().Owned(
109143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor             new (getSema().Context) DeclStmt(
109243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                        DeclGroupRef::Create(getSema().Context,
109343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                             Decls, NumDecls),
109443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              StartLoc, EndLoc));
109543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1097703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// \brief Build a new inline asm statement.
1098703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  ///
1099703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// By default, performs semantic analysis to build the new statement.
1100703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// Subclasses may override this routine to provide different behavior.
110160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
1102703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsSimple,
1103703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsVolatile,
1104703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumOutputs,
1105703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumInputs,
1106ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                  IdentifierInfo **Names,
1107703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Constraints,
1108703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Exprs,
11099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Expr *AsmString,
1110703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Clobbers,
1111703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  SourceLocation RParenLoc,
1112703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool MSAsm) {
1113c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1114703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  NumInputs, Names, move(Constraints),
11159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Exprs, AsmString, Clobbers,
1116703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  RParenLoc, MSAsm);
1117703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
11184dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
11194dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @try statement.
11204dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11214dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11224dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
112360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
11249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *TryBody,
11258f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                        MultiStmtArg CatchStmts,
11269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *Finally) {
11279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
11289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Finally);
11294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
11304dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
1131be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Rebuild an Objective-C exception declaration.
1132be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1133be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new declaration.
1134be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1135be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1136be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                    TypeSourceInfo *TInfo, QualType T) {
1137c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildObjCExceptionDecl(TInfo, T,
1138c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                            ExceptionDecl->getIdentifier(),
1139be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                            ExceptionDecl->getLocation());
1140be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
1141c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1142be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Build a new Objective-C @catch statement.
1143be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1144be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1145be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
114660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1147be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          SourceLocation RParenLoc,
1148be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          VarDecl *Var,
11499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Stmt *Body) {
1150be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
11519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Var, Body);
1152be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
1153c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11544dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @finally statement.
11554dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11564dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11574dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
115860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
11599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Stmt *Body) {
11609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
11614dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
1162c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11638fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @throw statement.
1164d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  ///
1165d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
1166d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
116760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
11689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Operand) {
11699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1170d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
1171c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11728fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @synchronized statement.
11738fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  ///
11748fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
11758fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
117660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
11779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *Object,
11789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Stmt *Body) {
11799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
11809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Body);
11818fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  }
1182c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor
1183c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// \brief Build a new Objective-C fast enumeration statement.
1184c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  ///
1185c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1186c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
118760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1188f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation LParenLoc,
1189f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Element,
1190f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Expr *Collection,
1191f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation RParenLoc,
1192f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Body) {
1193c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor    return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
11949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Element,
11959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Collection,
1196c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                RParenLoc,
11979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Body);
1198c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  }
1199c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
120043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ exception declaration.
120143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
120243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new decaration.
120343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
120483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1205a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                                TypeSourceInfo *Declarator,
120643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                IdentifierInfo *Name,
120783cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                SourceLocation Loc) {
120883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
120943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
121043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
121143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ catch statement.
121243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
121343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
121443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
121560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1216f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 VarDecl *ExceptionDecl,
1217f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 Stmt *Handler) {
12189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
12199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Handler));
122043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
122243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ try statement.
122343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
122443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
122543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
122660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1227f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               Stmt *TryBlock,
1228f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               MultiStmtArg Handlers) {
12299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
123043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression that references a declaration.
1233b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
123660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1237f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        LookupResult &R,
1238f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        bool RequiresADL) {
1239f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1240f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1241f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1242f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1243f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Build a new expression that references a declaration.
1244f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  ///
1245f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// By default, performs semantic analysis to build the new expression.
1246f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Subclasses may override this routine to provide different behavior.
124760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1248f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                SourceRange QualifierRange,
1249f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                ValueDecl *VD,
1250f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                const DeclarationNameInfo &NameInfo,
1251f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                TemplateArgumentListInfo *TemplateArgs) {
1252a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    CXXScopeSpec SS;
1253a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    SS.setScopeRep(Qualifier);
1254a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    SS.setRange(QualifierRange);
1255dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
1256dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: loses template args.
12572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
12582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression in parentheses.
12621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1264b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
126560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                    SourceLocation RParen) {
12679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1269b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1270a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Build a new pseudo-destructor expression.
12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1272a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1273a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
127460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1275a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                  SourceLocation OperatorLoc,
1276a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                  bool isArrow,
1277a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                NestedNameSpecifier *Qualifier,
127826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  SourceRange QualifierRange,
127926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  TypeSourceInfo *ScopeType,
128026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  SourceLocation CCLoc,
1281fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                  SourceLocation TildeLoc,
1282a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed);
12831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1284b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary operator expression.
12851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
128860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
12892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                        UnaryOperatorKind Opc,
12909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *SubExpr) {
12919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build a new builtin offsetof expression.
12958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
12968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
12978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
129860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       TypeSourceInfo *Type,
1300f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                       Sema::OffsetOfComponent *Components,
13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       unsigned NumComponents,
13028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       SourceLocation RParenLoc) {
13038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
13048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          NumComponents, RParenLoc);
13058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1306c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new sizeof or alignof expression with a type argument.
13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
131160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
13125ab75172051a6d2ea71a80a79e81c65519fd3462John McCall                                        SourceLocation OpLoc,
1313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool isSizeOf, SourceRange R) {
1314a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
1315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
13171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new sizeof or alignof expression with an expression
1318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument.
13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
132260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
1323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool isSizeOf, SourceRange R) {
132460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
13259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
1326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1327f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new array subscript expression.
13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
133660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LBracketLoc,
13389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *RHS,
1339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RBracketLoc) {
13409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
13419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             LBracketLoc, RHS,
1342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             RBracketLoc);
1343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new call expression.
13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
134960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Args,
1351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
13529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1353a1a04786cea2445759026edacd096abd1fbf4a05Douglas Gregor                                   move(Args), RParenLoc);
1354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member access expression.
13571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
136060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1361f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               bool isArrow,
1362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NestedNameSpecifier *Qualifier,
1363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               SourceRange QualifierRange,
1364f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               const DeclarationNameInfo &MemberNameInfo,
1365f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               ValueDecl *Member,
1366f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FoundDecl,
1367d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                        const TemplateArgumentListInfo *ExplicitTemplateArgs,
1368f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FirstQualifierInScope) {
1369d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    if (!Member->getDeclName()) {
1370f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // We have a reference to an unnamed field.  This is always the
1371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // base of an anonymous struct/union member access, i.e. the
1372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // field is always of record type.
1373d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
1374f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      assert(Member->getType()->isRecordType() &&
1375f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             "unnamed member not of record type?");
13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      if (getSema().PerformObjectMemberConversion(Base, Qualifier,
13786bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                                  FoundDecl, Member))
1379f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
13808aa5f407d9e4787ff08bd66e1a2fe39be174fddcDouglas Gregor
1381f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      MemberExpr *ME =
13839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        new (getSema().Context) MemberExpr(Base, isArrow,
13842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           Member, MemberNameInfo,
1385f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           cast<FieldDecl>(Member)->getType(),
1386f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           VK, OK_Ordinary);
1387d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      return getSema().Owned(ME);
1388d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    }
13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
139083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    CXXScopeSpec SS;
139183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    if (Qualifier) {
139283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      SS.setRange(QualifierRange);
139383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      SS.setScopeRep(Qualifier);
139483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    }
139583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
13969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().DefaultFunctionArrayConversion(Base);
13979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    QualType BaseType = Base->getType();
1398aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
13996bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // FIXME: this involves duplicating earlier analysis in a lot of
14006bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // cases; we should avoid this when possible.
14012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
14026bb8017bb9e828d118e15e59d71c66bba323c364John McCall    R.addDecl(FoundDecl);
1403c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    R.resolveKind();
1404c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
14059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1406129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, FirstQualifierInScope,
1407c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                              R, ExplicitTemplateArgs);
1408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new binary operator expression.
14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1413b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
141460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
14152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                         BinaryOperatorKind Opc,
14169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *LHS, Expr *RHS) {
14179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new conditional operator expression.
14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
142460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildConditionalOperator(Expr *Cond,
1425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation QuestionLoc,
14269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *LHS,
1427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation ColonLoc,
14289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *RHS) {
14299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
14309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        LHS, RHS);
1431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C-style cast expression.
14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
143760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
14389d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                         TypeSourceInfo *TInfo,
1439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc,
14409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *SubExpr) {
1441b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall    return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
14429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubExpr);
1443b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new compound literal expression.
14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1447b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
144960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
145042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall                                              TypeSourceInfo *TInfo,
1451b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation RParenLoc,
14529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Init) {
145342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
14549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Init);
1455b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new extended vector element access expression.
14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
146160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildExtVectorElementExpr(Expr *Base,
1462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation OpLoc,
1463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation AccessorLoc,
1464b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               IdentifierInfo &Accessor) {
1465aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
1466129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    CXXScopeSpec SS;
14672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
14689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1469129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              OpLoc, /*IsArrow*/ false,
1470129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, /*FirstQualifierInScope*/ 0,
14712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                              NameInfo,
1472129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              /* TemplateArgs */ 0);
1473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new initializer list expression.
14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
147960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildInitList(SourceLocation LBraceLoc,
1480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Inits,
1481e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   SourceLocation RBraceLoc,
1482e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   QualType ResultTy) {
148360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1484e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1485e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    if (Result.isInvalid() || ResultTy->isDependentType())
1486e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      return move(Result);
1487c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1488e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // Patch in the result type we were given, which may have been computed
1489e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // when the initial InitListExpr was built.
1490e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1491e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    ILE->setType(ResultTy);
1492e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    return move(Result);
1493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new designated initializer expression.
14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
149960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1500b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             MultiExprArg ArrayExprs,
1501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation EqualOrColonLoc,
1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             bool GNUSyntax,
15039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *Init) {
150460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
15069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Init);
1507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1508f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
15091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.release();
1511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new value-initialized expression.
15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds the implicit value initialization without performing
1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// any semantic analysis. Subclasses may override this routine to provide
1518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
151960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildImplicitValueInitExpr(QualType T) {
1520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new \c va_arg expression.
15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
152760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
15289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SubExpr, TypeSourceInfo *TInfo,
15292cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    SourceLocation RParenLoc) {
15302cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara    return getSema().BuildVAArgExpr(BuiltinLoc,
15319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    SubExpr, TInfo,
15322cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    RParenLoc);
1533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression list in parentheses.
15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
153960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        MultiExprArg SubExprs,
1541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1542c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1543f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian                                               move(SubExprs));
1544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new address-of-label expression.
15471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis, using the name of the label
1549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// rather than attempting to map the label statement itself.
1550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
155160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation LabelLoc,
1553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        LabelStmt *Label) {
1554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new GNU statement expression.
15581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
156160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
15629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Stmt *SubStmt,
1563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
15649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new __builtin_choose_expr expression.
1568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
157160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
15729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Cond, Expr *LHS, Expr *RHS,
1573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                     SourceLocation RParenLoc) {
1574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.ActOnChooseExpr(BuiltinLoc,
15759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Cond, LHS, RHS,
1576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   RParenLoc);
1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new overloaded operator call expression.
1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// The semantic analysis provides the behavior of template instantiation,
1583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// copying with transformations that turn what looks like an overloaded
15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// operator call into a use of a builtin operator, performing
1585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument-dependent lookup, etc. Subclasses may override this routine to
1586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
158760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation OpLoc,
15899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Callee,
15909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *First,
15919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Second);
15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++ "named" cast expression, such as static_cast or
1594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// reinterpret_cast.
1595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine dispatches to one of the more-specific routines
15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
159960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           Stmt::StmtClass Class,
1601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
16029d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
16059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    switch (Class) {
1608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXStaticCastExprClass:
16099d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
16119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
1612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXDynamicCastExprClass:
16149d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                    RAngleLoc, LParenLoc,
16169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    SubExpr, RParenLoc);
16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXReinterpretCastExprClass:
16199d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                        RAngleLoc, LParenLoc,
16219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                        SubExpr,
1622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        RParenLoc);
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXConstCastExprClass:
16259d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
16279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    default:
1630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      assert(false && "Invalid C++ named cast");
1631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      break;
1632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1634f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
1635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ static_cast expression.
1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
164160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LAngleLoc,
16439d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                            TypeSourceInfo *TInfo,
1644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RAngleLoc,
1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LParenLoc,
16469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Expr *SubExpr,
1647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RParenLoc) {
1648c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
16499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1650c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1651c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ dynamic_cast expression.
1655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
165860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LAngleLoc,
16609d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                             TypeSourceInfo *TInfo,
1661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RAngleLoc,
1662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LParenLoc,
16639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *SubExpr,
1664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RParenLoc) {
1665c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
16669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1667c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1668c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ reinterpret_cast expression.
1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
167560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LAngleLoc,
16779d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                                 TypeSourceInfo *TInfo,
1678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RAngleLoc,
1679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LParenLoc,
16809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SubExpr,
1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RParenLoc) {
1682c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
16839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1684c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1685c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ const_cast expression.
1689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
169260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
16949d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
16979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1699c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
17009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1701c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1702c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ functional-style cast expression.
1706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1709ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1710ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation LParenLoc,
1711ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          Expr *Sub,
1712ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation RParenLoc) {
1713ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1714f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                               MultiExprArg(&Sub, 1),
1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(type) expression.
1719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
172260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
172357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
172457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        TypeSourceInfo *Operand,
1725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1726c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
172757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
1728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
173001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(expr) expression.
1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
173560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
173657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
17379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand,
1738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
17399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
174057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
17411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
17421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
174301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(type) expression.
174401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
174501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
174601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
174701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
174801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
174901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        TypeSourceInfo *Operand,
175001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
175101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
175201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
175301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
175401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
175501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(expr) expression.
175601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
175701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
175801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
175901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
176001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
176101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        Expr *Operand,
176201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
176301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
176401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
176501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
176601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "this" expression.
1768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new "this" expression without performing any
17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// semantic analysis. Subclasses may override this routine to provide
1771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
177260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1773ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                QualType ThisType,
1774ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                bool isImplicit) {
1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().Owned(
1776828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                      new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1777828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                                                          isImplicit));
1778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ throw expression.
1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
178460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
17859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXThrow(ThrowLoc, Sub);
1786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ default-argument expression.
1789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new default-argument expression, which does not
1791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// require any semantic analysis. Subclasses may override this routine to
1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
179360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1794036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                            ParmVarDecl *Param) {
1795036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1796036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                                     Param));
1797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ zero-initialization expression.
1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1803ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1804ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1805ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1806ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
18071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                               MultiExprArg(getSema(), 0, 0),
1808ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               RParenLoc);
1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "new" expression.
1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
181560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
18161bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               bool UseGlobal,
18171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementLParen,
18181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg PlacementArgs,
18191bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementRParen,
18201bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceRange TypeIdParens,
18211bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               QualType AllocatedType,
18221bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               TypeSourceInfo *AllocatedTypeInfo,
18231bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               Expr *ArraySize,
18241bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorLParen,
18251bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg ConstructorArgs,
18261bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorRParen) {
18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getSema().BuildCXXNew(StartLoc, UseGlobal,
1828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementLParen,
1829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(PlacementArgs),
1830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementRParen,
18314bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                 TypeIdParens,
18321bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedType,
18331bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedTypeInfo,
18349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 ArraySize,
1835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorLParen,
1836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(ConstructorArgs),
1837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorRParen);
1838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "delete" expression.
1841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
184460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsGlobalDelete,
1846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsArrayForm,
18479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand) {
1848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
18499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Operand);
1850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary type trait expression.
1853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
185660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
18573d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation StartLoc,
18583d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   TypeSourceInfo *T,
18593d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation RParenLoc) {
18603d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor    return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
1861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
18636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// \brief Build a new binary type trait expression.
18646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ///
18656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// By default, performs semantic analysis to build the new expression.
18666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Subclasses may override this routine to provide different behavior.
18676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
18686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation StartLoc,
18696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *LhsT,
18706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *RhsT,
18716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation RParenLoc) {
18726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
18736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
18746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new (previously unresolved) declaration reference
1876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// expression.
1877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1879b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
188060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
1881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                SourceRange QualifierRange,
18822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                       const DeclarationNameInfo &NameInfo,
1883f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
1885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SS.setRange(QualifierRange);
1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SS.setScopeRep(NNS);
1887f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1888f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (TemplateArgs)
18892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
1890f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                    *TemplateArgs);
1891f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
18922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
1893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new template-id expression.
1896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
189960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1900f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         LookupResult &R,
1901f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         bool RequiresADL,
1902d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                              const TemplateArgumentListInfo &TemplateArgs) {
1903f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
1904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
191060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstructExpr(QualType T,
19114411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                           SourceLocation Loc,
1912b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           CXXConstructorDecl *Constructor,
1913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           bool IsElidable,
19148c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           MultiExprArg Args,
19158c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           bool RequiresZeroInit,
1916428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                             CXXConstructExpr::ConstructionKind ConstructKind,
1917428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           SourceRange ParenRange) {
1918ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
1919c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
19204411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                          ConvertedArgs))
1921f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1922c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
19234411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor    return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
19248c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           move_arg(ConvertedArgs),
1925428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           RequiresZeroInit, ConstructKind,
1926428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           ParenRange);
1927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1929b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1933ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1934ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1935ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           MultiExprArg Args,
1936ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1937ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
1938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
1939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
1940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1943b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1944b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1947ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1948ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation LParenLoc,
1949ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               MultiExprArg Args,
1950ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation RParenLoc) {
1951ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
1952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
1953b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
1954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member reference expression.
1958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
196160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
1962aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  QualType BaseType,
1963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  bool IsArrow,
1964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  SourceLocation OperatorLoc,
1965a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                              NestedNameSpecifier *Qualifier,
1966a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                  SourceRange QualifierRange,
1967129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            NamedDecl *FirstQualifierInScope,
19682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                   const DeclarationNameInfo &MemberNameInfo,
1969129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
1971a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    SS.setRange(QualifierRange);
1972a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    SS.setScopeRep(Qualifier);
19731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1975aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
1976129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            SS, FirstQualifierInScope,
19772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            MemberNameInfo,
19782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            TemplateArgs);
1979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1981129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Build a new member reference expression.
19823b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  ///
19833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
19843b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
198560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
1986aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                               QualType BaseType,
1987129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceLocation OperatorLoc,
1988129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               bool IsArrow,
1989129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               NestedNameSpecifier *Qualifier,
1990129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceRange QualifierRange,
1991c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                               NamedDecl *FirstQualifierInScope,
1992129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               LookupResult &R,
1993129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                const TemplateArgumentListInfo *TemplateArgs) {
19943b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    CXXScopeSpec SS;
19953b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    SS.setRange(QualifierRange);
19963b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    SS.setScopeRep(Qualifier);
19971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1999aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
2000c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            SS, FirstQualifierInScope,
2001c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            R, TemplateArgs);
20023b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// \brief Build a new noexcept expression.
20052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ///
20062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// By default, performs semantic analysis to build the new expression.
20072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// Subclasses may override this routine to provide different behavior.
20082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
20092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
20102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
20112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2012ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Build a new expression to compute the length of a parameter pack.
2013ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2014ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation PackLoc,
2015ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation RParenLoc,
2016ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   unsigned Length) {
2017ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2018ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                                OperatorLoc, Pack, PackLoc,
2019ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                                RParenLoc, Length);
2020ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2021ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new Objective-C @encode expression.
2023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
202660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
202781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                         TypeSourceInfo *EncodeTypeInfo,
2028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc) {
202981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                           RParenLoc));
20311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
2032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
203392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C class message.
203460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
203592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2036f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                          SourceLocation SelectorLoc,
203792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
2038c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
203992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
204092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
204192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return SemaRef.BuildClassMessage(ReceiverTypeInfo,
204292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     ReceiverTypeInfo->getType(),
204392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     /*SuperLoc=*/SourceLocation(),
2044f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                     Sel, Method, LBracLoc, SelectorLoc,
2045f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                     RBracLoc, move(Args));
204692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
204792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
204892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C instance message.
204960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(Expr *Receiver,
205092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2051f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                          SourceLocation SelectorLoc,
205292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
2053c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
205492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
205592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
20569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildInstanceMessage(Receiver,
20579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Receiver->getType(),
205892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        /*SuperLoc=*/SourceLocation(),
2059f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                        Sel, Method, LBracLoc, SelectorLoc,
2060f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                        RBracLoc, move(Args));
206192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
206292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
2063f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C ivar reference expression.
2064f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2065f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2066f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
206760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2068f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          SourceLocation IvarLoc,
2069f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          bool IsArrow, bool IsFreeIvar) {
2070f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    // FIXME: We lose track of the IsFreeIvar bit.
2071f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
20729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
2073f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2074f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
207560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2076f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IvarLoc,
2077d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0,
2078ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall                                                         false);
2079f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.isInvalid())
2080f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2081c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2082f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
2083f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
2084c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
20859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2086c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IvarLoc, IsArrow, SS,
2087f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
2088c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2089f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2090f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2091e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor
2092e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// \brief Build a new Objective-C property reference expression.
2093e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  ///
2094e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2095e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
209660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2097e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              ObjCPropertyDecl *Property,
2098e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              SourceLocation PropertyLoc) {
2099e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    CXXScopeSpec SS;
21009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
2101e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2102e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                   Sema::LookupMemberName);
2103e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    bool IsArrow = false;
210460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2105e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                                         /*FIME:*/PropertyLoc,
2106d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2107e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.isInvalid())
2108f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2109c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2110e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.get())
2111e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      return move(Result);
2112c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
21139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2114c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/PropertyLoc, IsArrow,
2115c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              SS,
2116e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*FirstQualifierInScope=*/0,
2117c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2118e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*TemplateArgs=*/0);
2119e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  }
2120c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
212112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// \brief Build a new Objective-C property reference expression.
21229cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  ///
21239cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
212412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// Subclasses may override this routine to provide different behavior.
212512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
212612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Getter,
212712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Setter,
212812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        SourceLocation PropertyLoc) {
212912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // Since these expressions can only be value-dependent, we do not
213012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // need to perform semantic analysis again.
213112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return Owned(
213212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
213312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  VK_LValue, OK_ObjCProperty,
213412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  PropertyLoc, Base));
21359cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  }
21369cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor
2137f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C "isa" expression.
2138f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2139f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2140f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
214160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2142f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                      bool IsArrow) {
2143f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
21449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
2145f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2146f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
214760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2148f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IsaLoc,
2149d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2150f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.isInvalid())
2151f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2152c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2153f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
2154f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
2155c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
21569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2157c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IsaLoc, IsArrow, SS,
2158f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
2159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2160f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2161f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2162c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new shuffle vector expression.
2164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
216760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2168f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      MultiExprArg SubExprs,
2169f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      SourceLocation RParenLoc) {
2170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Find the declaration for __builtin_shufflevector
21711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const IdentifierInfo &Name
2172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.Context.Idents.get("__builtin_shufflevector");
2173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
21761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Build a reference to the __builtin_shufflevector builtin
2178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
21791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Expr *Callee
2180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2181f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                          VK_LValue, BuiltinLoc);
2182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SemaRef.UsualUnaryConversions(Callee);
21831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Build the CallExpr
2185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    unsigned NumSubExprs = SubExprs.size();
2186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Expr **Subs = (Expr **)SubExprs.release();
2187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       Subs, NumSubExprs,
21895291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor                                                   Builtin->getCallResultType(),
2190f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            Expr::getValueKindForType(Builtin->getResultType()),
2191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       RParenLoc);
219260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult OwnedCall(SemaRef.Owned(TheCall));
21931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Type-check the __builtin_shufflevector expression.
219560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
2196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
2197f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2199b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    OwnedCall.release();
22001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return move(Result);
2201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
220243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
22038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Build a new template argument pack expansion.
22048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
22058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
22068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// for a template argument. Subclasses may override this routine to provide
22078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// different behavior.
22088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2209cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           SourceLocation EllipsisLoc,
2210cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
22118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    switch (Pattern.getArgument().getKind()) {
22127a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    case TemplateArgument::Expression: {
22137a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      ExprResult Result
221467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
221567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                       EllipsisLoc, NumExpansions);
22167a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      if (Result.isInvalid())
22177a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor        return TemplateArgumentLoc();
22187a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor
22197a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      return TemplateArgumentLoc(Result.get(), Result.get());
22207a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    }
2221dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
22228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Template:
2223a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor      return TemplateArgumentLoc(TemplateArgument(
2224a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                          Pattern.getArgument().getAsTemplate(),
22252be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor                                                  NumExpansions),
2226a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 Pattern.getTemplateQualifierRange(),
2227a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 Pattern.getTemplateNameLoc(),
2228a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 EllipsisLoc);
22298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
22308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Null:
22318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Integral:
22328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Declaration:
22338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Pack:
2234a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    case TemplateArgument::TemplateExpansion:
22358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm_unreachable("Pack expansion pattern has no parameter packs");
22368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
22378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Type:
22388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (TypeSourceInfo *Expansion
22398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor            = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2240cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           EllipsisLoc,
2241cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           NumExpansions))
22428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
22438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                   Expansion);
22448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      break;
22458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
22468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
22478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return TemplateArgumentLoc();
22488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
22498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
2250dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// \brief Build a new expression pack expansion.
2251dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  ///
2252dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
2253dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// for an expression. Subclasses may override this routine to provide
2254dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// different behavior.
225567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
225667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                  llvm::Optional<unsigned> NumExpansions) {
225767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2258dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  }
2259dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
226043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate:
226143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformTypeInObjectScope(QualType T,
226243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      QualType ObjectType,
226343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      NamedDecl *FirstQualifierInScope,
226443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      NestedNameSpecifier *Prefix);
226543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
226643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
226743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             QualType ObjectType,
226843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             NamedDecl *FirstQualifierInScope,
226943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             NestedNameSpecifier *Prefix);
2270577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor};
2271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
227243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
227360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
227443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!S)
227543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return SemaRef.Owned(S);
22761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
227743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  switch (S->getStmtClass()) {
227843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::NoStmtClass: break;
22791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
228043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform individual statement nodes
228143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                                              \
228243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
228343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent)
22844bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
22851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
228643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform expressions by calling TransformExpr.
228743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)
22887381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
228943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class:
22904bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
229143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    {
229260d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
229343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      if (E.isInvalid())
2294f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
229743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    }
22981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
230143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
23021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2304670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived>
230560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!E)
2307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(E);
2308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  switch (E->getStmtClass()) {
2310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::NoStmtClass: break;
2311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break;
23127381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
2313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                                              \
2314454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall    case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
23154bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
23161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
23171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23183fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
2319657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor}
2320657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor
2321657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived>
2322aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2323aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            unsigned NumInputs,
2324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool IsCall,
2325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                      llvm::SmallVectorImpl<Expr *> &Outputs,
2326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool *ArgChanged) {
2327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  for (unsigned I = 0; I != NumInputs; ++I) {
2328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    // If requested, drop call arguments that need to be dropped.
2329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      if (ArgChanged)
2331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor        *ArgChanged = true;
2332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      break;
2334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    }
2335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2336dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2337dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      Expr *Pattern = Expansion->getPattern();
2338dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2339dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2340dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2341dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2342dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2343dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
2344dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // be expanded.
2345dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      bool Expand = true;
2346d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
234767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> OrigNumExpansions
234867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = Expansion->getNumExpansions();
234967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
2350dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2351dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Pattern->getSourceRange(),
2352dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Unexpanded.data(),
2353dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Unexpanded.size(),
2354d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand, RetainExpansion,
2355d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
2356dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        return true;
2357dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2358dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (!Expand) {
2359dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // The transform has determined that we should perform a simple
2360dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // transformation on the pack expansion, producing another pack
2361dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // expansion.
2362dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2363dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2364dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (OutPattern.isInvalid())
2365dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2366dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2367dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
236867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                Expansion->getEllipsisLoc(),
236967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                           NumExpansions);
2370dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2371dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2372dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2373dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (ArgChanged)
2374dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          *ArgChanged = true;
2375dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2376dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        continue;
2377dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2378dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2379dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // The transform has determined that we should perform an elementwise
2380dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // expansion of the pattern. Do so.
2381cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
2382dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2383dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().TransformExpr(Pattern);
2384dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2385dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2386dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
238777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.get()->containsUnexpandedParameterPack()) {
238867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor          Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
238967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                     OrigNumExpansions);
239077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.isInvalid())
239177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
239277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
239377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
2394dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (ArgChanged)
2395dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          *ArgChanged = true;
2396dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2397dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2398dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2399dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      continue;
2400dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    }
2401dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2402aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2403aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.isInvalid())
2404aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return true;
2405aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2406aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.get() != Inputs[I] && ArgChanged)
2407aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      *ArgChanged = true;
2408aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2409aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    Outputs.push_back(Result.get());
2410aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
2411aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2412aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  return false;
2413aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor}
2414aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2415aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived>
2416dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
2417dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
2418a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     SourceRange Range,
2419c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                     QualType ObjectType,
2420c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                             NamedDecl *FirstQualifierInScope) {
242143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  NestedNameSpecifier *Prefix = NNS->getPrefix();
24221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
242343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the prefix of this nested name specifier.
2424dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  if (Prefix) {
24251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
2426c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                       ObjectType,
2427c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                       FirstQualifierInScope);
2428dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    if (!Prefix)
2429dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return 0;
2430dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
24311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2432dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  switch (NNS->getKind()) {
2433dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Identifier:
243443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (Prefix) {
243543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // The object type and qualifier-in-scope really apply to the
243643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // leftmost entity.
243743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      ObjectType = QualType();
243843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      FirstQualifierInScope = 0;
243943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
244043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
24411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert((Prefix || !ObjectType.isNull()) &&
2442a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor            "Identifier nested-name-specifier with no prefix or object type");
2443a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2444a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor        ObjectType.isNull())
2445dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
24461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2448a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                   *NNS->getAsIdentifier(),
2449c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   ObjectType,
2450c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   FirstQualifierInScope);
24511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2452dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Namespace: {
24531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NamespaceDecl *NS
2454dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      = cast_or_null<NamespaceDecl>(
24557c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                    getDerived().TransformDecl(Range.getBegin(),
24567c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       NNS->getAsNamespace()));
24571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (!getDerived().AlwaysRebuild() &&
2458dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        Prefix == NNS->getPrefix() &&
2459dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        NS == NNS->getAsNamespace())
2460dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
24611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2462dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2463dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
24641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2465dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Global:
2466dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    // There is no meaningful transformation that one could perform on the
2467dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    // global scope.
2468dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return NNS;
24691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2470dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::TypeSpecWithTemplate:
2471dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::TypeSpec: {
2472fbf2c945f8f8bbfe0459d45c03f9ff34bb445c81Douglas Gregor    TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
247343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
247443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            ObjectType,
247543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            FirstQualifierInScope,
247643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            Prefix);
2477d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (T.isNull())
2478d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return 0;
24791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2480dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
2481dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        Prefix == NNS->getPrefix() &&
2482dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        T == QualType(NNS->getAsType(), 0))
2483dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
24841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
24861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
2487edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                   T);
2488dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
2489dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
24901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2491dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  // Required to silence a GCC warning
24921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return 0;
2493dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
2494dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
2495dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
24962577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo
24972577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived>
249843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
24992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name = NameInfo.getName();
250081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  if (!Name)
25012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo();
250281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
250381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  switch (Name.getNameKind()) {
250481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::Identifier:
250581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCZeroArgSelector:
250681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCOneArgSelector:
250781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCMultiArgSelector:
250881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXOperatorName:
25093e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  case DeclarationName::CXXLiteralOperatorName:
251081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXUsingDirective:
25112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NameInfo;
25121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
251381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConstructorName:
251481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXDestructorName:
251581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConversionFunctionName: {
25162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *NewTInfo;
25172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CanQualType NewCanTy;
25182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
251943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewTInfo = getDerived().TransformType(OldTInfo);
252043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NewTInfo)
252143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall        return DeclarationNameInfo();
252243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
25232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
25242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    else {
25252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewTInfo = 0;
25262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
252743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      QualType NewT = getDerived().TransformType(Name.getCXXNameType());
25282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      if (NewT.isNull())
25292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        return DeclarationNameInfo();
25302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewCanTy = SemaRef.Context.getCanonicalType(NewT);
25312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
25321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationName NewName
25342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
25352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                           NewCanTy);
25362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NewNameInfo(NameInfo);
25372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setName(NewName);
25382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setNamedTypeInfo(NewTInfo);
25392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NewNameInfo;
254081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  }
25411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
25421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  assert(0 && "Unknown name kind.");
25442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return DeclarationNameInfo();
254581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor}
254681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
254781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived>
25481eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
25493b6afbb99a1c44b4076f8e15fb7311405941b306Douglas GregorTreeTransform<Derived>::TransformTemplateName(TemplateName Name,
255043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              QualType ObjectType,
255143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              NamedDecl *FirstQualifierInScope) {
25527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  SourceLocation Loc = getDerived().getBaseLocation();
25537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor
2554d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
25551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NestedNameSpecifier *NNS
2556d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
255743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  /*FIXME*/ SourceRange(Loc),
255843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  ObjectType,
255943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  FirstQualifierInScope);
2560d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!NNS)
2561d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return TemplateName();
25621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2563d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (TemplateDecl *Template = QTN->getTemplateDecl()) {
25641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      TemplateDecl *TransTemplate
25657c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor        = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2566d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      if (!TransTemplate)
2567d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        return TemplateName();
25681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2569d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      if (!getDerived().AlwaysRebuild() &&
2570d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor          NNS == QTN->getQualifier() &&
2571d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor          TransTemplate == Template)
2572d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        return Name;
25731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2574d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2575d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                              TransTemplate);
2576d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    }
25771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2578f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // These should be getting filtered out before they make it into the AST.
257943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    llvm_unreachable("overloaded template name survived to here");
2580d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
25811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2582d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
258343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    NestedNameSpecifier *NNS = DTN->getQualifier();
258443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (NNS) {
258543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NNS = getDerived().TransformNestedNameSpecifier(NNS,
258643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  /*FIXME:*/SourceRange(Loc),
258743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ObjectType,
258843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      FirstQualifierInScope);
258943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NNS) return TemplateName();
259043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
259143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // These apply to the scope specifier, not the template.
259243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      ObjectType = QualType();
259343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      FirstQualifierInScope = 0;
259443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
25951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2596d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2597dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor        NNS == DTN->getQualifier() &&
2598dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor        ObjectType.isNull())
2599d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return Name;
26001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26011efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    if (DTN->isIdentifier()) {
26021efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      // FIXME: Bad range
26031efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      SourceRange QualifierRange(getDerived().getBaseLocation());
26041efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      return getDerived().RebuildTemplateName(NNS, QualifierRange,
26051efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                              *DTN->getIdentifier(),
260643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              ObjectType,
260743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              FirstQualifierInScope);
26081efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    }
2609c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2610c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2611ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            ObjectType);
2612d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
26131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2614d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
26151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TemplateDecl *TransTemplate
26167c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2617d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!TransTemplate)
2618d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return TemplateName();
26191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2620d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2621d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        TransTemplate == Template)
2622d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return Name;
26231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2624d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    return TemplateName(TransTemplate);
2625d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
26261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26271aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  if (SubstTemplateTemplateParmPackStorage *SubstPack
26281aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                 = Name.getAsSubstTemplateTemplateParmPack()) {
26291aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    TemplateTemplateParmDecl *TransParam
26301aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor      = cast_or_null<TemplateTemplateParmDecl>(
26311aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor               getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
26321aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    if (!TransParam)
26331aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor      return TemplateName();
26341aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
26351aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
26361aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor        TransParam == SubstPack->getParameterPack())
26371aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor      return Name;
26381aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
26391aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    return getDerived().RebuildTemplateName(TransParam,
26401aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                            SubstPack->getArgumentPack());
26411aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  }
26421aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
2643f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // These should be getting filtered out before they reach the AST.
264443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  llvm_unreachable("overloaded function decl survived to here");
2645f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return TemplateName();
2646d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
2647d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
2648d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
2649833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc(
2650833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgument &Arg,
2651833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2652833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation Loc = getDerived().getBaseLocation();
2653670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  switch (Arg.getKind()) {
2654670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Null:
26559f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("null template argument in TreeTransform");
2656833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2657833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2658833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
2659833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg,
2660a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall               SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2661c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2662833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2663833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2664788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
2665788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2666788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    break;
2667a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2668a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor  case TemplateArgument::TemplateExpansion:
2669a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2670a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    break;
2671a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2672833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
2673833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2674833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2675833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2676833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
2677670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Integral:
2678833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
2679828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2680833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2681833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
2682833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
2683833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2684833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived>
2685833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument(
2686833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgumentLoc &Input,
2687833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2688833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgument &Arg = Input.getArgument();
2689833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
2690833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
2691833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
2692833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = Input;
2693833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
26941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2695670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Type: {
2696a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *DI = Input.getTypeSourceInfo();
2697833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (DI == NULL)
2698a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall      DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2699833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2700833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    DI = getDerived().TransformType(DI);
2701833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!DI) return true;
2702833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2703833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2704833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2705670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
27061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2707670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Declaration: {
2708833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // FIXME: we should never have to transform one of these.
2709972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    DeclarationName Name;
2710972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2711972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor      Name = ND->getDeclName();
2712788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemporaryBase Rebase(*this, Input.getLocation(), Name);
27137c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2714833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!D) return true;
2715833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2716828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Expr *SourceExpr = Input.getSourceDeclExpression();
2717828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    if (SourceExpr) {
2718828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      EnterExpressionEvaluationContext Unevaluated(getSema(),
2719f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Sema::Unevaluated);
272060d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(SourceExpr);
27219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      SourceExpr = (E.isInvalid() ? 0 : E.take());
2722828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    }
2723828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
2724828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2725833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2726670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2728788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template: {
2729c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2730788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemplateName Template
2731788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      = getDerived().TransformTemplateName(Arg.getAsTemplate());
2732788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    if (Template.isNull())
2733788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      return true;
2734c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2735788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(Template),
2736788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateQualifierRange(),
2737788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateNameLoc());
2738788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return false;
2739788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  }
2740a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2741a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor  case TemplateArgument::TemplateExpansion:
2742a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    llvm_unreachable("Caller should expand pack expansions");
2743a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2744670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Expression: {
2745670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    // Template argument expressions are not potentially evaluated.
27461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EnterExpressionEvaluationContext Unevaluated(getSema(),
2747f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                 Sema::Unevaluated);
27481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2749833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Expr *InputExpr = Input.getSourceExpression();
2750833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2751833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
275260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult E
2753833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = getDerived().TransformExpr(InputExpr);
2754833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (E.isInvalid()) return true;
27559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2756833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2757670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
27581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2759670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Pack: {
2760670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2761670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    TransformedArgs.reserve(Arg.pack_size());
27621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2763670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor                                      AEnd = Arg.pack_end();
2764670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor         A != AEnd; ++A) {
27651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2766833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // FIXME: preserve source information here when we start
2767833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // caring about parameter packs.
2768833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2769828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc InputArg;
2770828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc OutputArg;
2771828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      getDerived().InventTemplateArgumentLoc(*A, InputArg);
2772828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2773833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall        return true;
2774833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2775828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TransformedArgs.push_back(OutputArg.getArgument());
2776670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    }
2777910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
2778910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    TemplateArgument *TransformedArgsPtr
2779910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2780910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2781910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor              TransformedArgsPtr);
2782910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2783910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                                  TransformedArgs.size()),
2784910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                 Input.getLocInfo());
2785833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2786670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
2787670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
27881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2789670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Work around bogus GCC warning
2790833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return true;
2791670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor}
2792670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
27937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information
27947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator.
27957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator>
27967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator {
27977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TreeTransform<Derived> &Self;
27987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  InputIterator Iter;
27997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic:
28017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc value_type;
28027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc reference;
28037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef typename std::iterator_traits<InputIterator>::difference_type
28047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    difference_type;
28057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef std::input_iterator_tag iterator_category;
28067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class pointer {
28087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Arg;
2809fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
28107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
28117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
28127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    const TemplateArgumentLoc *operator->() const { return &Arg; }
28147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
28157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator() { }
28177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
28197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                             InputIterator Iter)
28207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    : Self(Self), Iter(Iter) { }
28217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator &operator++() {
28237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++Iter;
28247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return *this;
2825fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  }
2826fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
28277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator operator++(int) {
28287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocInventIterator Old(*this);
28297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++(*this);
28307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Old;
28317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
28327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  reference operator*() const {
28347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Result;
28357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    Self.InventTemplateArgumentLoc(*Iter, Result);
28367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Result;
28377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
28387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  pointer operator->() const { return pointer(**this); }
28407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator==(const TemplateArgumentLocInventIterator &X,
28427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
28437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter == Y.Iter;
28447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
2845fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
28467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator!=(const TemplateArgumentLocInventIterator &X,
28477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
28487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter != Y.Iter;
28497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
28507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor};
28517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28527f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived>
28537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator>
28547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
28557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                        InputIterator Last,
28567f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor                                            TemplateArgumentListInfo &Outputs) {
28577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  for (; First != Last; ++First) {
28587f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    TemplateArgumentLoc Out;
28597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc In = *First;
28608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().getKind() == TemplateArgument::Pack) {
28628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Unpack argument packs, which we translate them into separate
28638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // arguments.
28647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // FIXME: We could do much better if we could guarantee that the
28657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // TemplateArgumentLocInfo for the pack expansion would be usable for
28667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // all of the template arguments in the argument pack.
28677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      typedef TemplateArgumentLocInventIterator<Derived,
28687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                TemplateArgument::pack_iterator>
28697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        PackLocIterator;
28707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      if (TransformTemplateArguments(PackLocIterator(*this,
28717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                 In.getArgument().pack_begin()),
28727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     PackLocIterator(*this,
28737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                   In.getArgument().pack_end()),
28747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     Outputs))
28757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return true;
28768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
28788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
28798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().isPackExpansion()) {
28818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // We have a pack expansion, for which we will be substituting into
28828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // the pattern.
28838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      SourceLocation Ellipsis;
2884cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> OrigNumExpansions;
28858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      TemplateArgumentLoc Pattern
2886cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2887cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                     getSema().Context);
28888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
28908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
28918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
28928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
28948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // be expanded.
28958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      bool Expand = true;
2896d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
2897cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
28988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (getDerived().TryExpandParameterPacks(Ellipsis,
28998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Pattern.getSourceRange(),
29008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.data(),
29018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.size(),
2902d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand,
2903d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
2904d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
29058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return true;
29068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (!Expand) {
29088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // The transform has determined that we should perform a simple
29098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // transformation on the pack expansion, producing another pack
29108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // expansion.
29118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        TemplateArgumentLoc OutPattern;
29128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
29138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
29148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
29158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
2916cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2917cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                NumExpansions);
29188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (Out.getArgument().isNull())
29198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
29208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
29228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        continue;
29238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
29248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // The transform has determined that we should perform an elementwise
29268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // expansion of the pattern. Do so.
2927cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
29288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
29298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
29318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
29328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
293377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.getArgument().containsUnexpandedParameterPack()) {
2934cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2935cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                  OrigNumExpansions);
293677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.getArgument().isNull())
293777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
293877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
293977d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
29408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
29418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
29428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29433cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
29443cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
29453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
29463cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
29473cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
29483cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
29493cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
29503cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
2951cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2952cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                OrigNumExpansions);
29533cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (Out.getArgument().isNull())
29543cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
29553cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
29563cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        Outputs.addArgument(Out);
29573cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
2958d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
29598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
29608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
29618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    // The simple case:
29638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (getDerived().TransformTemplateArgument(In, Out))
29647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor      return true;
29657f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
29667f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    Outputs.addArgument(Out);
29677f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  }
29687f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
29697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  return false;
29707f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
29717f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor}
29727f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
2973577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
2974577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation
2975577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
2976577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2977577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
297843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) {
2979577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (getDerived().AlreadyTransformed(T))
2980577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T;
29811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2982a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Temporary workaround.  All of these transformations should
2983a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // eventually turn into transformations on TypeLocs.
2984c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2985c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor                                                getDerived().getBaseLocation());
2986c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
298743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
29881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2989a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (!NewDI)
2990a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
29911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2992a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return NewDI->getType();
2993577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
29941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2995577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
299643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
2997a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlreadyTransformed(DI->getType()))
2998a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return DI;
29991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3000a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLocBuilder TLB;
30011bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
3002a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLoc TL = DI->getTypeLoc();
3003a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TLB.reserve(TL.getFullDataSize());
30041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
300543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, TL);
3006a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3007a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return 0;
30081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3009a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3010577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
30111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3013a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
301443fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3015a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  switch (T.getTypeLocClass()) {
3016a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
3017a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \
3018a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  case TypeLoc::CLASS: \
301943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3020a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
3021a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3022577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
30239f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("unhandled type loc!");
3024a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return QualType();
3025577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
30261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3027a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types
3028a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers
3029a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function
3030a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but
3031a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients.
30321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
30331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3034a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
303543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               QualifiedTypeLoc T) {
3036a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers Quals = T.getType().getLocalQualifiers();
3037a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
303843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3039a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3040577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
30411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3042a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Silently suppress qualifiers if the result type can't be qualified.
3043a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: this is the right thing for template instantiation, but
3044a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // probably not for other clients.
3045a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result->isFunctionType() || Result->isReferenceType())
3046a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return Result;
30471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30482865474261a608c7873b87ba4af110d17907896dJohn McCall  if (!Quals.empty()) {
30492865474261a608c7873b87ba4af110d17907896dJohn McCall    Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
30502865474261a608c7873b87ba4af110d17907896dJohn McCall    TLB.push<QualifiedTypeLoc>(Result);
30512865474261a608c7873b87ba4af110d17907896dJohn McCall    // No location information to preserve.
30522865474261a608c7873b87ba4af110d17907896dJohn McCall  }
3053a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3054a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3055a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3056a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
305743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// \brief Transforms a type that was written in a scope specifier,
305843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// given an object type, the results of unqualified lookup, and
305943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// an already-instantiated prefix.
306043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall///
306143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// The object type is provided iff the scope specifier qualifies the
306243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// member of a dependent member-access expression.  The prefix is
306343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// provided iff the the scope specifier in which this appears has a
306443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// prefix.
306543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall///
306643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// This is private to TreeTransform.
306743fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
306843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType
306943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
307043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
307143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
307243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *Prefix) {
307343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
307443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return T;
307543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
307643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TSI =
3077c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor    SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
307843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
307943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
308043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                UnqualLookup, Prefix);
308143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (!TSI) return QualType();
308243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TSI->getType();
308343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
308443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
308543fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
308643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *
308743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
308843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
308943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
309043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *Prefix) {
309143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: in some cases, we might be some verification to do here.
309243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (ObjectType.isNull())
309343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().TransformType(TSI);
309443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
309543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType T = TSI->getType();
309643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
309743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return TSI;
309843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
309943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeLocBuilder TLB;
310043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result;
310143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
310243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (isa<TemplateSpecializationType>(T)) {
310343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateSpecializationTypeLoc TL
310443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
310543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
310643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateName Template =
310743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
310843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         ObjectType, UnqualLookup);
310943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (Template.isNull()) return 0;
311043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
311143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived()
311243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      .TransformTemplateSpecializationType(TLB, TL, Template);
311343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else if (isa<DependentTemplateSpecializationType>(T)) {
311443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    DependentTemplateSpecializationTypeLoc TL
311543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
311643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
311743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived()
311843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
311943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else {
312043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    // Nothing special needs to be done for these.
312143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
312243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
312343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
312443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Result.isNull()) return 0;
312543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
312643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
312743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
3128a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline
3129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TyLoc NewT = TLB.push<TyLoc>(T.getType());
3131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewT.setNameLoc(T.getNameLoc());
3132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return T.getType();
3133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3136a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
313743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      BuiltinTypeLoc T) {
3138ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3139ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  NewT.setBuiltinLoc(T.getBuiltinLoc());
3140ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (T.needsExtraLocalData())
3141ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3142ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  return T.getType();
3143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
31451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
314743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ComplexTypeLoc T) {
3148a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: recurse?
3149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, T);
3150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
31511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
315443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      PointerTypeLoc TL) {
3155c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType PointeeType
3156c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
315792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (PointeeType.isNull())
315892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return QualType();
315992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
316092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  QualType Result = TL.getType();
3161c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (PointeeType->getAs<ObjCObjectType>()) {
316292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // A dependent pointer type 'T *' has is being transformed such
316392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // that an Objective-C class type is being replaced for 'T'. The
316492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // resulting pointer type is an ObjCObjectPointerType, not a
316592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // PointerType.
3166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3168c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3169c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NewT.setStarLoc(TL.getStarLoc());
317092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return Result;
317192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
317243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
317392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (getDerived().AlwaysRebuild() ||
317492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      PointeeType != TL.getPointeeLoc().getType()) {
317592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
317692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Result.isNull())
317792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      return QualType();
317892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
3179c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
318092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
318192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3182c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Result;
3183577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3184577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
31851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
31861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
318843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  BlockPointerTypeLoc TL) {
3189db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  QualType PointeeType
3190c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
3191c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (PointeeType.isNull())
3192c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return QualType();
3193c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType Result = TL.getType();
3195c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (getDerived().AlwaysRebuild() ||
3196c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      PointeeType != TL.getPointeeLoc().getType()) {
3197c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Result = getDerived().RebuildBlockPointerType(PointeeType,
3198db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor                                                  TL.getSigilLoc());
3199db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor    if (Result.isNull())
3200db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor      return QualType();
3201db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  }
3202db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor
320339968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3204db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3205db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  return Result;
3206a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
32071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
320885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type.  Note that somewhat paradoxically we
320985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value
321085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type;  we only care if the type was *written* as an l-value type
321185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type.
321285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived>
321385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType
321485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
321543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ReferenceTypeLoc TL) {
321685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  const ReferenceType *T = TL.getTypePtr();
321785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
321885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // Note that this works with the pointee-as-written.
321985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
322085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (PointeeType.isNull())
322185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return QualType();
322285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
322385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType Result = TL.getType();
322485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (getDerived().AlwaysRebuild() ||
322585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      PointeeType != T->getPointeeTypeAsWritten()) {
322685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildReferenceType(PointeeType,
322785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               T->isSpelledAsLValue(),
322885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               TL.getSigilLoc());
322985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    if (Result.isNull())
323085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      return QualType();
323185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
323285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
323385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // r-value references can be rebuilt as l-value references.
323485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  ReferenceTypeLoc NewTL;
323585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (isa<LValueReferenceType>(Result))
323685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
323785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  else
323885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
323985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
324085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
324185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  return Result;
324285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall}
324385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3244a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3245a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3246a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
324743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 LValueReferenceTypeLoc TL) {
324843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3249a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
32501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3251a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3252a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3253a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
325443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 RValueReferenceTypeLoc TL) {
325543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3256577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
32571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3258577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
32591eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3260a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
326143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   MemberPointerTypeLoc TL) {
3262f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const MemberPointerType *T = TL.getTypePtr();
3263a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3265577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (PointeeType.isNull())
3266577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3268a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // TODO: preserve source information for this.
3269a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ClassType
3270a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformType(QualType(T->getClass(), 0));
3271577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ClassType.isNull())
3272577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3275a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3276a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      PointeeType != T->getPointeeType() ||
3277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ClassType != QualType(T->getClass(), 0)) {
327885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
327985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getStarLoc());
3280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3285a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
3286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3288577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3289577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
32901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
32911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
329343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ConstantArrayTypeLoc TL) {
3294f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ConstantArrayType *T = TL.getTypePtr();
3295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3296577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3297577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3300a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3302a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildConstantArrayType(ElementType,
3303a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
3304a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSize(),
330585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             T->getIndexTypeCVRQualifiers(),
330685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3307a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3309a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3310c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3311a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3312a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3313a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
33141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3315a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = TL.getSizeExpr();
3316a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Size) {
3317f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3318a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3319a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3320a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
3321a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3322a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3323577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3325577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3326577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType(
3327a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                              TypeLocBuilder &TLB,
332843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              IncompleteArrayTypeLoc TL) {
3329f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const IncompleteArrayType *T = TL.getTypePtr();
3330a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3331577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3332577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3334a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3335a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3336a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3337a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildIncompleteArrayType(ElementType,
3338a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                     T->getSizeModifier(),
333985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                           T->getIndexTypeCVRQualifiers(),
334085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                     TL.getBracketsRange());
3341a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3342a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3344c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3345a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3346a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3348a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(0);
3349577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3350a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3354a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3355a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
335643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   VariableArrayTypeLoc TL) {
3357f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VariableArrayType *T = TL.getTypePtr();
3358a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3359577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3360577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3362670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3363f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3364670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
336560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
3366a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
3367a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
3368577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Size = SizeResult.take();
3371a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3372a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3373a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3374a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
3375a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
3376a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildVariableArrayType(ElementType,
3377a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
33789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Size,
3379a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                             T->getIndexTypeCVRQualifiers(),
338085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3381a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3382a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3384c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3385a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3386a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3387a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3388a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
33891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3390a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3391577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3394a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3395a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
339643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             DependentSizedArrayTypeLoc TL) {
3397f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedArrayType *T = TL.getTypePtr();
3398a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3400577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3402670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3403f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
34041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // Prefer the expression from the TypeLoc;  the other may have been uniqued.
34063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *origSize = TL.getSizeExpr();
34073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!origSize) origSize = T->getSizeExpr();
34083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
34093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExprResult sizeResult
34103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    = getDerived().TransformExpr(origSize);
34113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (sizeResult.isInvalid())
3412577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *size = sizeResult.get();
3415a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3416a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3417a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3418a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
34193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      size != origSize) {
3420a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3421a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                         T->getSizeModifier(),
34223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                                                         size,
3423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                T->getIndexTypeCVRQualifiers(),
342485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                        TL.getBracketsRange());
3425a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3426a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3427577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
34281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3429a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // We might have any sort of array type now, but fortunately they
3430a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // all have the same location layout.
3431a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3432a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3433a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
34343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  NewTL.setSizeExpr(size);
3435a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3436a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3437577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3440577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3441a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                      TypeLocBuilder &TLB,
344243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentSizedExtVectorTypeLoc TL) {
3443f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedExtVectorType *T = TL.getTypePtr();
3444a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3445a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: ext vector locs should be nested
3446577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3447577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3448577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3450670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Vector sizes are not potentially evaluated contexts
3451f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3452670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
345360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3454577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (Size.isInvalid())
3455577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3457a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3458a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3459eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      ElementType != T->getElementType() ||
3460eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      Size.get() != T->getSizeExpr()) {
3461a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
34629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                             Size.take(),
3463577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                         T->getAttributeLoc());
3464a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3465a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3466a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3467a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Result might be dependent or not.
3469a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (isa<DependentSizedExtVectorType>(Result)) {
3470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    DependentSizedExtVectorTypeLoc NewTL
3471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3472a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3473a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  } else {
3474a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3475a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3476a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3477a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3478a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3479577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3482a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
348343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     VectorTypeLoc TL) {
3484f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3485577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3486577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3487577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3488577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3491a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
349282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3493e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                            T->getVectorKind());
3494a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3496a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3497c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3498a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3499a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
35001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3502577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3505a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
350643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        ExtVectorTypeLoc TL) {
3507f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3508577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3509577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3510577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3513a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3514a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildExtVectorType(ElementType,
3516a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               T->getNumElements(),
3517a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               /*FIXME*/ SourceLocation());
3518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3519a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3521c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3522a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3523a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
35241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3525a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3526577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3527577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
35281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
352921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl *
35306a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
35316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
353221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
35336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  TypeSourceInfo *NewDI = 0;
35346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
35366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    // If we're substituting into a pack expansion type and we know the
35376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc OldTL = OldDI->getTypeLoc();
35386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
35396a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35406a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLocBuilder TLB;
35416a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc NewTL = OldDI->getTypeLoc();
35426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TLB.reserve(NewTL.getFullDataSize());
35436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35446a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    QualType Result = getDerived().TransformType(TLB,
35456a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                               OldExpansionTL.getPatternLoc());
35466a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
35476a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
35486a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35496a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    Result = RebuildPackExpansionType(Result,
35506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                OldExpansionTL.getPatternLoc().getSourceRange(),
35516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      OldExpansionTL.getEllipsisLoc(),
35526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      NumExpansions);
35536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
35546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
35556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc NewExpansionTL
35576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      = TLB.push<PackExpansionTypeLoc>(Result);
35586a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
35596a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
35606a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  } else
35616a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = getDerived().TransformType(OldDI);
356221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (!NewDI)
356321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return 0;
356421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
356521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (NewDI == OldDI)
356621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return OldParm;
356721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  else
356821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return ParmVarDecl::Create(SemaRef.Context,
356921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getDeclContext(),
357021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getLocation(),
357121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getIdentifier(),
357221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               NewDI->getType(),
357321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               NewDI,
357421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getStorageClass(),
357516573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor                               OldParm->getStorageClassAsWritten(),
357621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               /* DefArg */ NULL);
357721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
357821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
357921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
358021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>::
3581a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  TransformFunctionTypeParams(SourceLocation Loc,
3582a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              ParmVarDecl **Params, unsigned NumParams,
3583a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              const QualType *ParamTypes,
3584a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              llvm::SmallVectorImpl<QualType> &OutParamTypes,
3585a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3586a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  for (unsigned i = 0; i != NumParams; ++i) {
3587a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (ParmVarDecl *OldParm = Params[i]) {
35886a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      llvm::Optional<unsigned> NumExpansions;
3589603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (OldParm->isParameterPack()) {
3590603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We have a function parameter pack that may need to be expanded.
3591603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3592603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3593603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Find the parameter packs that could be expanded.
3594c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3595c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3596c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc Pattern = ExpansionTL.getPatternLoc();
3597c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3598603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3599603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Determine whether we should expand the parameter packs.
3600603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        bool ShouldExpand = false;
3601d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor        bool RetainExpansion = false;
36026a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        llvm::Optional<unsigned> OrigNumExpansions
36036a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor          = ExpansionTL.getTypePtr()->getNumExpansions();
36046a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        NumExpansions = OrigNumExpansions;
3605c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3606c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor                                                 Pattern.getSourceRange(),
3607603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.data(),
3608603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.size(),
3609d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 ShouldExpand,
3610d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 RetainExpansion,
3611d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 NumExpansions)) {
3612603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          return true;
3613603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3614603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3615603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        if (ShouldExpand) {
3616603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // Expand the function parameter pack into multiple, separate
3617603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // parameters.
361812c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor          getDerived().ExpandingFunctionParameterPack(OldParm);
3619cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          for (unsigned I = 0; I != *NumExpansions; ++I) {
3620603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3621603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            ParmVarDecl *NewParm
36226a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
36236a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3624603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            if (!NewParm)
3625603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor              return true;
3626603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3627a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            OutParamTypes.push_back(NewParm->getType());
3628a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            if (PVars)
3629a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor              PVars->push_back(NewParm);
3630603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          }
3631d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3632d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // If we're supposed to retain a pack expansion, do so by temporarily
3633d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // forgetting the partially-substituted parameter pack.
3634d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          if (RetainExpansion) {
3635d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3636d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ParmVarDecl *NewParm
36376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
36386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3639d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (!NewParm)
3640d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              return true;
3641d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3642d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            OutParamTypes.push_back(NewParm->getType());
3643d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (PVars)
3644d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              PVars->push_back(NewParm);
3645d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          }
3646d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3647603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // We're done with the pack expansion.
3648603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          continue;
3649603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3650603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3651603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We'll substitute the parameter now without expanding the pack
3652603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // expansion.
3653603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3654603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3655603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
36566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
36576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                                 NumExpansions);
365821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      if (!NewParm)
365921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3660603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3661a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      OutParamTypes.push_back(NewParm->getType());
3662a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (PVars)
3663a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor        PVars->push_back(NewParm);
3664603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      continue;
3665603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    }
3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // Deal with the possibility that we don't have a parameter
3668a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // declaration for this parameter.
3669a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    QualType OldType = ParamTypes[i];
3670603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    bool IsPackExpansion = false;
3671cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    llvm::Optional<unsigned> NumExpansions;
3672603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (const PackExpansionType *Expansion
3673603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                       = dyn_cast<PackExpansionType>(OldType)) {
3674603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We have a function parameter pack that may need to be expanded.
3675603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      QualType Pattern = Expansion->getPattern();
3676603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3677603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3678603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3679603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // Determine whether we should expand the parameter packs.
3680603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      bool ShouldExpand = false;
3681d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3682a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
3683603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.data(),
3684603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.size(),
3685d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               ShouldExpand,
3686d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3687d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions)) {
368821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3689603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3690603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3691603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (ShouldExpand) {
3692603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Expand the function parameter pack into multiple, separate
3693603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // parameters.
3694cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        for (unsigned I = 0; I != *NumExpansions; ++I) {
3695603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3696603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          QualType NewType = getDerived().TransformType(Pattern);
3697603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          if (NewType.isNull())
3698603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            return true;
3699603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3700a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          OutParamTypes.push_back(NewType);
3701a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          if (PVars)
3702a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            PVars->push_back(0);
3703603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3704603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3705603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We're done with the pack expansion.
3706603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        continue;
3707603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3708603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
37093cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
37103cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
37113cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
37123cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
37133cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        QualType NewType = getDerived().TransformType(Pattern);
37143cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (NewType.isNull())
37153cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
37163cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
37173cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        OutParamTypes.push_back(NewType);
37183cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (PVars)
37193cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          PVars->push_back(0);
37203cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
3721d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3722603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We'll substitute the parameter now without expanding the pack
3723603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // expansion.
3724603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      OldType = Expansion->getPattern();
3725603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      IsPackExpansion = true;
3726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    }
3727603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3728603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3729603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    QualType NewType = getDerived().TransformType(OldType);
3730603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (NewType.isNull())
3731603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      return true;
37321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3733603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (IsPackExpansion)
3734cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NewType = getSema().Context.getPackExpansionType(NewType,
3735cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                       NumExpansions);
3736603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3737a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    OutParamTypes.push_back(NewType);
3738a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (PVars)
3739a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      PVars->push_back(0);
3740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
37411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
374221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  return false;
3743603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor  }
374421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
374521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
374621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType
374721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
374843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   FunctionProtoTypeLoc TL) {
37497e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // Transform the parameters and return type.
37507e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
37517e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // We instantiate in source order, with the return type first followed by
37527e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // the parameters, because users tend to expect this (even if they shouldn't
37537e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // rely on it!).
37547e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
3755dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // When the function has a trailing return type, we instantiate the
3756dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // parameters before the return type,  since the return type can then refer
3757dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // to the parameters themselves (via decltype, sizeof, etc.).
3758dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
375921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<QualType, 4> ParamTypes;
376021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
3761f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionProtoType *T = TL.getTypePtr();
37627e010a04fef171049291d8cb3047f118566da090Douglas Gregor
3763dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  QualType ResultType;
3764dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3765dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  if (TL.getTrailingReturn()) {
3766a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3767a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
3768a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
3769a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
3770a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
3771dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3772dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3773dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3774dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
3775dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3776dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
3777dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  else {
3778dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3779dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
3780dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3781dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3782a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3783a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
3784a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
3785a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
3786a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
3787dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3788dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
3789dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3790a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3791a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3792a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType() ||
3793bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor      T->getNumArgs() != ParamTypes.size() ||
3794a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3795a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionProtoType(ResultType,
3796a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.data(),
3797a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.size(),
3798a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->isVariadic(),
3799fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getTypeQuals(),
3800c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                   T->getRefQualifier(),
3801fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getExtInfo());
3802a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3804a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
38051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3806a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3807a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3808a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3809dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(TL.getTrailingReturn());
3810a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3811a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setArg(i, ParamDecls[i]);
3812a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3813a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3814577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3816577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3817577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType(
3818a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                 TypeLocBuilder &TLB,
381943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 FunctionNoProtoTypeLoc TL) {
3820f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionNoProtoType *T = TL.getTypePtr();
3821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3822a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (ResultType.isNull())
3823a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
3824a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3825a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3826a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3827a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType())
3828a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3829a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3830a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3831a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3832a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3833dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(false);
3834a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3835a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3836577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3838ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType
3839ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
384043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 UnresolvedUsingTypeLoc TL) {
3841f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const UnresolvedUsingType *T = TL.getTypePtr();
38427c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
3843ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (!D)
3844ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return QualType();
3845ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3846ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType Result = TL.getType();
3847ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3848ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Result = getDerived().RebuildUnresolvedUsingType(D);
3849ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    if (Result.isNull())
3850ed97649e9574b9d854fa4d6109c9333ae0993554John McCall      return QualType();
3851ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3852ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3853ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // We might get an arbitrary type spec type back.  We should at
3854ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // least always get a type spec type, though.
3855ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3856ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  NewTL.setNameLoc(TL.getNameLoc());
3857ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3858ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return Result;
3859ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
3860ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3861577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3862a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
386343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypedefTypeLoc TL) {
3864f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypedefType *T = TL.getTypePtr();
3865577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  TypedefDecl *Typedef
38667c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
38677c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           T->getDecl()));
3868577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Typedef)
3869577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
38701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3871a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3872a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3873a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Typedef != T->getDecl()) {
3874a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildTypedefType(Typedef);
3875a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3876a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3877a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3878a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3879a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3880a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
38811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3882a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3883577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3885577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3886a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
388743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypeOfExprTypeLoc TL) {
3888670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // typeof expressions are not potentially evaluated contexts
3889f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
38901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
389160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
3892577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
3893577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3894577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3895a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3896a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3897cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      E.get() != TL.getUnderlyingExpr()) {
38982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
3899a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3900a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3901577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3902a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
39031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3904a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
3905cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
3906cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3907cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3908a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3909a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3910577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
39111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3913a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
391443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     TypeOfTypeLoc TL) {
3915cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3916cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3917cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (!New_Under_TI)
3918577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
39191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3920a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3921cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3922cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
3923a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3924a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3925a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
39261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3927a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
3928cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
3929cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3930cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3931cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setUnderlyingTInfo(New_Under_TI);
3932a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3933a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3934577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
39351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3937a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
393843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                       DecltypeTypeLoc TL) {
3939f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DecltypeType *T = TL.getTypePtr();
3940a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3941670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // decltype expressions are not potentially evaluated contexts
3942f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
39431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
394460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3945577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
3946577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
39471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3948a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3949a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3950a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      E.get() != T->getUnderlyingExpr()) {
39512a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
3952a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3953a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3954577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3955a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
3956a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3957a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3958a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
39591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3960a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3961577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3962577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3963577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3964a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
396543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     RecordTypeLoc TL) {
3966f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const RecordType *T = TL.getTypePtr();
3967577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  RecordDecl *Record
39687c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
39697c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                          T->getDecl()));
3970577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Record)
3971577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
39721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3973a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3974a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3975a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Record != T->getDecl()) {
3976a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildRecordType(Record);
3977a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3978a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3979a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
39801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3981a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3982a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
3983a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3984a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3985577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
39861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3988a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
398943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   EnumTypeLoc TL) {
3990f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const EnumType *T = TL.getTypePtr();
3991577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  EnumDecl *Enum
39927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
39937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                        T->getDecl()));
3994577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Enum)
3995577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
39961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3997a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3998a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3999a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Enum != T->getDecl()) {
4000a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildEnumType(Enum);
4001a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4002a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4003a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4004a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4005a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4006a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
40071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4008a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4009577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
40107da2431c23ef1ee8acb114e39692246e1801afc2John McCall
40113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived>
40123cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType(
40133cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         TypeLocBuilder &TLB,
401443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         InjectedClassNameTypeLoc TL) {
40153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
40163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                       TL.getTypePtr()->getDecl());
40173cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  if (!D) return QualType();
40183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
40193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
40203cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
40213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  return T;
40223cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
40233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
4024577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4025577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4026a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                TypeLocBuilder &TLB,
402743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TemplateTypeParmTypeLoc TL) {
4028a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
4029577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4030577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
40311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
403249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4033a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                         TypeLocBuilder &TLB,
403443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         SubstTemplateTypeParmTypeLoc TL) {
4035a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
403649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
403749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
403849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived>
4039c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4040c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          TypeLocBuilder &TLB,
4041c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          SubstTemplateTypeParmPackTypeLoc TL) {
4042c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  return TransformTypeSpecType(TLB, TL);
4043c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}
4044c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
4045c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived>
4046833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
404743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        TypeLocBuilder &TLB,
404843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                           TemplateSpecializationTypeLoc TL) {
404943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
4050828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
405143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TemplateName Template
405243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformTemplateName(T->getTemplateName());
405343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Template.isNull())
405443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4055833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
405643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4057dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor}
405843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
40597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace {
40607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \brief Simple iterator that traverses the template arguments in a
40617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// container that provides a \c getArgLoc() member function.
40627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
40637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// This iterator is intended to be used with the iterator form of
40647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \c TreeTransform<Derived>::TransformTemplateArguments().
40657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename ArgLocContainer>
40667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class TemplateArgumentLocContainerIterator {
40677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgLocContainer *Container;
40687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    unsigned Index;
40697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
40717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc value_type;
40727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc reference;
40737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef int difference_type;
40747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef std::input_iterator_tag iterator_category;
40757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    class pointer {
40777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLoc Arg;
40787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    public:
40807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
40817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      const TemplateArgumentLoc *operator->() const {
40837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return &Arg;
40847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      }
40857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    };
40867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator() {}
40897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
40917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                 unsigned Index)
40927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      : Container(&Container), Index(Index) { }
40937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator &operator++() {
40957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++Index;
40967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return *this;
40977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
40987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator operator++(int) {
41007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLocContainerIterator Old(*this);
41017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++(*this);
41027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Old;
41037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc operator*() const {
41067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Container->getArgLoc(Index);
41077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    pointer operator->() const {
41107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return pointer(Container->getArgLoc(Index));
41117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4114f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
41157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return X.Container == Y.Container && X.Index == Y.Index;
41167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4119f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
41207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return !(X == Y);
41217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
41237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}
41247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
412643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived>
4127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4128833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                        TypeLocBuilder &TLB,
4129833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                           TemplateSpecializationTypeLoc TL,
413043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TemplateName Template) {
4131d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo NewTemplateArgs;
4132d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4133d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
41347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
41357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgIterator;
41367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
41377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
41387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              NewTemplateArgs))
41397f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    return QualType();
41401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4141833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  // FIXME: maybe don't rebuild if all the template arguments are the same.
4142833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
4143833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType Result =
4144833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getDerived().RebuildTemplateSpecializationType(Template,
4145833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                   TL.getTemplateNameLoc(),
4146d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NewTemplateArgs);
41471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4148833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  if (!Result.isNull()) {
4149833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TemplateSpecializationTypeLoc NewTL
4150833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4151833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4152833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setLAngleLoc(TL.getLAngleLoc());
4153833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setRAngleLoc(TL.getRAngleLoc());
4154833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4155833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4156833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
41571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4158833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return Result;
4159577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4162a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4163465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
416443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ElaboratedTypeLoc TL) {
4165f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ElaboratedType *T = TL.getTypePtr();
4166465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
4167465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  NestedNameSpecifier *NNS = 0;
4168465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // NOTE: the qualifier in an ElaboratedType is optional.
4169465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  if (T->getQualifier() != 0) {
4170465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
417143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                    TL.getQualifierRange());
4172465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (!NNS)
4173465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      return QualType();
4174465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
41751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
417643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
417743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (NamedT.isNull())
417843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4179a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar
4180a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4181a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4182a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NNS != T->getQualifier() ||
4183e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      NamedT != T->getNamedType()) {
418421e413fe6305a198564d436ac515497716c47844John McCall    Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
418521e413fe6305a198564d436ac515497716c47844John McCall                                                T->getKeyword(), NNS, NamedT);
4186a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4188a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4190465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4191e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setKeywordLoc(TL.getKeywordLoc());
4192e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setQualifierRange(TL.getQualifierRange());
4193a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4195577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
41989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType(
41999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                TypeLocBuilder &TLB,
42009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                AttributedTypeLoc TL) {
42019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  const AttributedType *oldType = TL.getTypePtr();
42029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
42039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (modifiedType.isNull())
42049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return QualType();
42059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType result = TL.getType();
42079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // FIXME: dependent operand expressions?
42099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (getDerived().AlwaysRebuild() ||
42109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      modifiedType != oldType->getModifiedType()) {
42119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // TODO: this is really lame; we should really be rebuilding the
42129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // equivalent type from first principles.
42139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    QualType equivalentType
42149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      = getDerived().TransformType(oldType->getEquivalentType());
42159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (equivalentType.isNull())
42169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      return QualType();
42179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
42189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               modifiedType,
42199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               equivalentType);
42209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
42219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
42239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  newTL.setAttrNameLoc(TL.getAttrNameLoc());
42249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrOperand())
42259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
42269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrExprOperand())
42279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrExprOperand(TL.getAttrExprOperand());
42289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  else if (TL.hasAttrEnumOperand())
42299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
42309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  return result;
42329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
42339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived>
4235075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType
4236075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4237075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                                           ParenTypeLoc TL) {
4238075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4239075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (Inner.isNull())
4240075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType();
4241075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4242075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Result = TL.getType();
4243075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (getDerived().AlwaysRebuild() ||
4244075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      Inner != TL.getInnerLoc().getType()) {
4245075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Result = getDerived().RebuildParenType(Inner);
4246075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    if (Result.isNull())
4247075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      return QualType();
4248075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
4249075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4250075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4251075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setLParenLoc(TL.getLParenLoc());
4252075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setRParenLoc(TL.getRParenLoc());
4253075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  return Result;
4254075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
4255075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4256075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived>
42574714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
425843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      DependentNameTypeLoc TL) {
4259f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentNameType *T = TL.getTypePtr();
4260833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
4261577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  NestedNameSpecifier *NNS
4262e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
426343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TL.getQualifierRange());
4264577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!NNS)
4265577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
42661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
426733500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType Result
426833500955d731c73717af52088b7fc0e7a85681e7John McCall    = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
426933500955d731c73717af52088b7fc0e7a85681e7John McCall                                            T->getIdentifier(),
427033500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getKeywordLoc(),
427133500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getQualifierRange(),
427233500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getNameLoc());
4273a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
4274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4275a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4276e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4277e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    QualType NamedT = ElabT->getNamedType();
427833500955d731c73717af52088b7fc0e7a85681e7John McCall    TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
427933500955d731c73717af52088b7fc0e7a85681e7John McCall
4280e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4281e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
4282e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setQualifierRange(TL.getQualifierRange());
428333500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
4284e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4285e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
4286e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setQualifierRange(TL.getQualifierRange());
4287e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setNameLoc(TL.getNameLoc());
4288e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
4289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4290577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
42911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4292577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
429333500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>::
429433500955d731c73717af52088b7fc0e7a85681e7John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
429543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL) {
4296f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentTemplateSpecializationType *T = TL.getTypePtr();
429733500955d731c73717af52088b7fc0e7a85681e7John McCall
429833500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS
429933500955d731c73717af52088b7fc0e7a85681e7John McCall    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
430043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TL.getQualifierRange());
430133500955d731c73717af52088b7fc0e7a85681e7John McCall  if (!NNS)
430233500955d731c73717af52088b7fc0e7a85681e7John McCall    return QualType();
430333500955d731c73717af52088b7fc0e7a85681e7John McCall
430443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived()
430543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall           .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
430643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
430743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
430843fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
430943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::
431043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
431143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL,
431243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *NNS) {
4313f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentTemplateSpecializationType *T = TL.getTypePtr();
431443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
431533500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentListInfo NewTemplateArgs;
431633500955d731c73717af52088b7fc0e7a85681e7John McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
431733500955d731c73717af52088b7fc0e7a85681e7John McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
43187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
43197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLocContainerIterator<
43207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                            DependentTemplateSpecializationTypeLoc> ArgIterator;
43217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
43227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
43237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              NewTemplateArgs))
43247f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    return QualType();
432533500955d731c73717af52088b7fc0e7a85681e7John McCall
43261efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor  QualType Result
43271efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
43281efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              NNS,
43291efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                        TL.getQualifierRange(),
43301efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                            T->getIdentifier(),
43311efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              TL.getNameLoc(),
43321efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              NewTemplateArgs);
433333500955d731c73717af52088b7fc0e7a85681e7John McCall  if (Result.isNull())
433433500955d731c73717af52088b7fc0e7a85681e7John McCall    return QualType();
433533500955d731c73717af52088b7fc0e7a85681e7John McCall
433633500955d731c73717af52088b7fc0e7a85681e7John McCall  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
433733500955d731c73717af52088b7fc0e7a85681e7John McCall    QualType NamedT = ElabT->getNamedType();
433833500955d731c73717af52088b7fc0e7a85681e7John McCall
433933500955d731c73717af52088b7fc0e7a85681e7John McCall    // Copy information relevant to the template specialization.
434033500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateSpecializationTypeLoc NamedTL
434133500955d731c73717af52088b7fc0e7a85681e7John McCall      = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
434233500955d731c73717af52088b7fc0e7a85681e7John McCall    NamedTL.setLAngleLoc(TL.getLAngleLoc());
434333500955d731c73717af52088b7fc0e7a85681e7John McCall    NamedTL.setRAngleLoc(TL.getRAngleLoc());
434433500955d731c73717af52088b7fc0e7a85681e7John McCall    for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
434533500955d731c73717af52088b7fc0e7a85681e7John McCall      NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
434633500955d731c73717af52088b7fc0e7a85681e7John McCall
434733500955d731c73717af52088b7fc0e7a85681e7John McCall    // Copy information relevant to the elaborated type.
434833500955d731c73717af52088b7fc0e7a85681e7John McCall    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
434933500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTL.setKeywordLoc(TL.getKeywordLoc());
435033500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTL.setQualifierRange(TL.getQualifierRange());
435133500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
4352e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor    TypeLoc NewTL(Result, TL.getOpaqueData());
4353e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor    TLB.pushFullCopy(NewTL);
435433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
435533500955d731c73717af52088b7fc0e7a85681e7John McCall  return Result;
435633500955d731c73717af52088b7fc0e7a85681e7John McCall}
435733500955d731c73717af52088b7fc0e7a85681e7John McCall
435833500955d731c73717af52088b7fc0e7a85681e7John McCalltemplate<typename Derived>
43597536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
43607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor                                                      PackExpansionTypeLoc TL) {
43612fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Pattern
43622fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    = getDerived().TransformType(TLB, TL.getPatternLoc());
43632fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (Pattern.isNull())
43642fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    return QualType();
43652fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
43662fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Result = TL.getType();
43672fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (getDerived().AlwaysRebuild() ||
43682fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      Pattern != TL.getPatternLoc().getType()) {
43692fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    Result = getDerived().RebuildPackExpansionType(Pattern,
43702fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                           TL.getPatternLoc().getSourceRange(),
4371cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                   TL.getEllipsisLoc(),
4372cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           TL.getTypePtr()->getNumExpansions());
43732fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    if (Result.isNull())
43742fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      return QualType();
43752fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
43762fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
43772fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
43782fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  NewT.setEllipsisLoc(TL.getEllipsisLoc());
43792fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  return Result;
43807536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}
43817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
43827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived>
4383a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4384a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
438543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ObjCInterfaceTypeLoc TL) {
4386ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCInterfaceType is never dependent.
4387c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4388c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return TL.getType();
4389c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4390c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4391c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived>
4392c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType
4393c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
439443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjCObjectTypeLoc TL) {
4395c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // ObjCObjectType is never dependent.
4396c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4397ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
4398577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4401a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4402a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
440343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ObjCObjectPointerTypeLoc TL) {
4404ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCObjectPointerType is never dependent.
4405c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4406ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
440724fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}
440824fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis
4409577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
441043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation
441143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
441243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
441360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
44141eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
44153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
441643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
441743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
441843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
441960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
442043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
442143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().TransformCompoundStmt(S, false);
442243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
442343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
442443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
442560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
44261eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
442743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              bool IsStmtExpr) {
44287114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  bool SubStmtInvalid = false;
442943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool SubStmtChanged = false;
4430ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Statements(getSema());
443143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
443243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       B != BEnd; ++B) {
443360d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Result = getDerived().TransformStmt(*B);
44347114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    if (Result.isInvalid()) {
44357114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Immediately fail if this was a DeclStmt, since it's very
44367114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // likely that this will cause problems for future statements.
44377114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      if (isa<DeclStmt>(*B))
44387114cbab7eb6e8b714eb22f014327daf2c741c08John McCall        return StmtError();
44397114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
44407114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Otherwise, just keep processing substatements and fail later.
44417114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      SubStmtInvalid = true;
44427114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      continue;
44437114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
44441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
444543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    SubStmtChanged = SubStmtChanged || Result.get() != *B;
444643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Statements.push_back(Result.takeAs<Stmt>());
444743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
44481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44497114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  if (SubStmtInvalid)
44507114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    return StmtError();
44517114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
445243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
445343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !SubStmtChanged)
44543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
445543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
445643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
445743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          move_arg(Statements),
445843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          S->getRBracLoc(),
445943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          IsStmtExpr);
446043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
44611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
446243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
446360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
44641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
446560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS, RHS;
4466264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  {
4467264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // The case value expressions are not potentially evaluated.
4468f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
44691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4470264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the left-hand case value.
4471264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    LHS = getDerived().TransformExpr(S->getLHS());
4472264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (LHS.isInvalid())
4473f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
44741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4475264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the right-hand case value (for the GNU case-range extension).
4476264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    RHS = getDerived().TransformExpr(S->getRHS());
4477264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (RHS.isInvalid())
4478f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4479264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  }
44801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
448143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Build the case statement.
448243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Case statements are always rebuilt so that they will attached to their
448343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transformed switch statement.
448460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
44859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       LHS.get(),
448643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getEllipsisLoc(),
44879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       RHS.get(),
448843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getColonLoc());
448943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Case.isInvalid())
4490f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
44911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
449243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the case
449360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
449443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4495f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
44961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
449743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Attach the body to the case statement
44989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
449943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
450043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
450143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
450260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
45031eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
450443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the default case
450560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
450643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4507f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
450943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Default statements are always rebuilt
451043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
45119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubStmt.get());
451243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
45131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
451443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
451560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
45161eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
451760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
451843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4519f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
452143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // FIXME: Pass the real colon location in.
452243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
452343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
45241a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                       SubStmt.get(), S->HasUnusedAttribute());
452543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
45261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
452743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
452860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
45291eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
453043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
453160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
45328cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  VarDecl *ConditionVar = 0;
45338cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  if (S->getConditionVariable()) {
4534c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
45358cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor      = cast_or_null<VarDecl>(
4536aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4537aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4538aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
45398cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    if (!ConditionVar)
4540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
454199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
45428cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4543c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
454499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4545f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4546eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
4547eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor    // Convert the condition to a boolean value.
4548afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
45498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
45508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
4551afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
4552f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4553eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
45549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
4555afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
455699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
4557c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
45589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
45599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
4560f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4561eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
456243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "then" branch.
456360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Then = getDerived().TransformStmt(S->getThen());
456443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Then.isInvalid())
4565f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
456743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "else" branch.
456860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Else = getDerived().TransformStmt(S->getElse());
456943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Else.isInvalid())
4570f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
457243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
45739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
457499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
457543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Then.get() == S->getThen() &&
457643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Else.get() == S->getElse())
45773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
45781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4579eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
458044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                    Then.get(),
45819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    S->getElseLoc(), Else.get());
458243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
458343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
458443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
458560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
45861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
458743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition.
458860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
4589d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  VarDecl *ConditionVar = 0;
4590d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  if (S->getConditionVariable()) {
4591c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
4592d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor      = cast_or_null<VarDecl>(
4593aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4594aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4595aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
4596d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    if (!ConditionVar)
4597f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
459899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
4599d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4600c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
460199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
460399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
46041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
460543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Rebuild the switch statement.
460660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Switch
46079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
4608586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                          ConditionVar);
460943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Switch.isInvalid())
4610f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
46111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
461243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body of the switch statement.
461360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
461443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
4615f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
46161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
461743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Complete the switch statement.
46189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
46199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Body.get());
462043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
46211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
462243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
462360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
46241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
462543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
462660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
46275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  VarDecl *ConditionVar = 0;
46285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  if (S->getConditionVariable()) {
4629c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
46305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      = cast_or_null<VarDecl>(
4631aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4632aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4633aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
46345656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    if (!ConditionVar)
4635f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
463699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
46375656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4638c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
463999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4640f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4641afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
4642afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
4643afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
46448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
46458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
4646afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
4647f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
46489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE;
4649afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
465099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
46511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
46539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
4654f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4655eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
465643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
465760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
465843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
4659f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
46601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
466143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
46629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
466399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
466443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
46659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(S);
46661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4667eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
46689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       ConditionVar, Body.get());
466943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
46701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
467143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
467260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
467343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
467443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
467560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
467643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
4677f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
46781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4679eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  // Transform the condition
468060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(S->getCond());
4681eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  if (Cond.isInvalid())
4682f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4683eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
468443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
468543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Cond.get() == S->getCond() &&
468643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
46873fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
46881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
46909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    /*FIXME:*/S->getWhileLoc(), Cond.get(),
469143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    S->getRParenLoc());
469243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
46931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
469443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
469560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
46961eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) {
469743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the initialization statement
469860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Init = getDerived().TransformStmt(S->getInit());
469943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Init.isInvalid())
4700f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
47011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
470243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
470360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
470499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  VarDecl *ConditionVar = 0;
470599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  if (S->getConditionVariable()) {
4706c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
470799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      = cast_or_null<VarDecl>(
4708aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4709aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4710aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
471199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (!ConditionVar)
4712f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
471399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
471499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4715c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
471699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4717f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4718afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
4719afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
4720afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
47218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
47228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
4723afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
4724f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4725afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
47269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
4727afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
472899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
47291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
47319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
4732f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4733eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
473443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the increment
473560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Inc = getDerived().TransformExpr(S->getInc());
473643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Inc.isInvalid())
4737f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
47381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
47409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (S->getInc() && !FullInc.get())
4741f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4742eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
474343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
474460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
474543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
4746f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
47471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
474843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
474943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Init.get() == S->getInit() &&
47509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
475143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Inc.get() == S->getInc() &&
475243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
47533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
47541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
475543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
47569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Init.get(), FullCond, ConditionVar,
47579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     FullInc, S->getRParenLoc(), Body.get());
475843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
475943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
476043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
476160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
47621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
476343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Goto statements must always be rebuilt, to resolve the label.
47641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
476543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getLabel());
476643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
476743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
476843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
476960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
47701eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
477160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Target = getDerived().TransformExpr(S->getTarget());
477243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Target.isInvalid())
4773f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
47741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
477543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
477643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Target.get() == S->getTarget())
47773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
477843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
477943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
47809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Target.get());
478143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
478243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
478343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
478460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
47851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
47863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
478743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
47881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
478943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
479060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
47911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
47923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
479343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
47941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
479543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
479660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
47971eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
479860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = getDerived().TransformExpr(S->getRetValue());
479943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Result.isInvalid())
4800f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
480143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
48021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: We always rebuild the return statement because there is no way
480343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // to tell whether the return type of the function has changed.
48049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
480543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
48061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
480743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
480860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48091eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
481043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool DeclChanged = false;
481143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  llvm::SmallVector<Decl *, 4> Decls;
481243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
481343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       D != DEnd; ++D) {
4814aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor    Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4815aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                         *D);
481643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (!Transformed)
4817f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
48181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
481943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Transformed != *D)
482043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      DeclChanged = true;
48211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
482243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Decls.push_back(Transformed);
482343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
48241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
482543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() && !DeclChanged)
48263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
48271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
482943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getStartLoc(), S->getEndLoc());
483043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
48311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
483243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
483360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48341eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
483543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  assert(false && "SwitchCase is abstract and cannot be transformed");
48363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
483743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
483843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
483943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
484060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
484143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
4842c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4843ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Constraints(getSema());
4844ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Exprs(getSema());
4845ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  llvm::SmallVector<IdentifierInfo *, 4> Names;
4846a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson
484760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AsmString;
4848ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Clobbers(getSema());
4849703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4850703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  bool ExprsChanged = false;
4851c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4852703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the outputs.
4853703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
4854ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getOutputIdentifier(I));
4855c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4856703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
48573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getOutputConstraintLiteral(I));
4858c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4859703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the output expr.
4860703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *OutputExpr = S->getOutputExpr(I);
486160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(OutputExpr);
4862703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
4863f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4864c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4865703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != OutputExpr;
4866c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
48679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
4868703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
4869c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4870703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the inputs.
4871703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
4872ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getInputIdentifier(I));
4873c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4874703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
48753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getInputConstraintLiteral(I));
4876c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4877703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the input expr.
4878703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *InputExpr = S->getInputExpr(I);
487960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(InputExpr);
4880703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
4881f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4882c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4883703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != InputExpr;
4884c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
48859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
4886703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
4887c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4888703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
48893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4890703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4891703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the clobbers.
4892703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
48933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Clobbers.push_back(S->getClobber(I));
4894703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4895703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // No need to transform the asm string literal.
4896703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  AsmString = SemaRef.Owned(S->getAsmString());
4897703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4898703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4899703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isSimple(),
4900703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isVolatile(),
4901703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumOutputs(),
4902703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumInputs(),
4903a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson                                     Names.data(),
4904703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Constraints),
4905703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Exprs),
49069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     AsmString.get(),
4907703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Clobbers),
4908703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getRParenLoc(),
4909703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isMSAsm());
491043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
491143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
491243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
491343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
491460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49151eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
49164dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body of the @try.
491760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
49184dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (TryBody.isInvalid())
4919f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4920c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49218f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  // Transform the @catch statements (if present).
49228f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  bool AnyCatchChanged = false;
4923ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> CatchStmts(SemaRef);
49248f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
492560d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
49264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Catch.isInvalid())
4927f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
49288f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    if (Catch.get() != S->getCatchStmt(I))
49298f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      AnyCatchChanged = true;
49308f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    CatchStmts.push_back(Catch.release());
49314dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
4932c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the @finally statement (if present).
493460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Finally;
49354dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (S->getFinallyStmt()) {
49364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    Finally = getDerived().TransformStmt(S->getFinallyStmt());
49374dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Finally.isInvalid())
4938f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
49394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
49404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
49414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
49424dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
49434dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      TryBody.get() == S->getTryBody() &&
49448f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      !AnyCatchChanged &&
49454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Finally.get() == S->getFinallyStmt())
49463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4947c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49484dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
49499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
49509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           move_arg(CatchStmts), Finally.get());
495143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
495343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
495460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
4956be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  // Transform the @catch parameter, if there is one.
4957be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *Var = 0;
4958be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (VarDecl *FromVar = S->getCatchParamDecl()) {
4959be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    TypeSourceInfo *TSInfo = 0;
4960be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (FromVar->getTypeSourceInfo()) {
4961be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4962be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (!TSInfo)
4963f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4964be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
4965c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4966be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    QualType T;
4967be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (TSInfo)
4968be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = TSInfo->getType();
4969be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    else {
4970be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = getDerived().TransformType(FromVar->getType());
4971be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (T.isNull())
4972f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4973be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
4974c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4975be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4976be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (!Var)
4977f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4978be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
4979c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
498060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
4981be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (Body.isInvalid())
4982f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4983c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4984c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
4985be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                             S->getRParenLoc(),
49869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Var, Body.get());
498743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
498943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
499060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
49924dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body.
499360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
49944dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (Body.isInvalid())
4995f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4996c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49974dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
49984dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
49994dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Body.get() == S->getFinallyBody())
50003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
50014dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
50024dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
50034dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
50049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                               Body.get());
500543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
50061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
500743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
500860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50091eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
501060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand;
5011d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (S->getThrowExpr()) {
5012d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    Operand = getDerived().TransformExpr(S->getThrowExpr());
5013d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    if (Operand.isInvalid())
5014f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5015d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
5016c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5017d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5018d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor      Operand.get() == S->getThrowExpr())
50193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return getSema().Owned(S);
5020c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
502243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
50231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
502443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
502560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
502643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
50271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCAtSynchronizedStmt *S) {
50288fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the object we are locking.
502960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
50308fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Object.isInvalid())
5031f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5032c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50338fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the body.
503460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
50358fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Body.isInvalid())
5036f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5037c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50388fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // If nothing change, just retain the current statement.
50398fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
50408fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Object.get() == S->getSynchExpr() &&
50418fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Body.get() == S->getSynchBody())
50423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
50438fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor
50448fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Build a new statement.
50458fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
50469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    Object.get(), Body.get());
504743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
504843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
504943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
505060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
505143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt(
50521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCForCollectionStmt *S) {
5053c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the element statement.
505460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Element = getDerived().TransformStmt(S->getElement());
5055c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Element.isInvalid())
5056f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5057c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5058c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the collection expression.
505960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5060c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Collection.isInvalid())
5061f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5062c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5063c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the body.
506460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
5065c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Body.isInvalid())
5066f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5067c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5068c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // If nothing changed, just retain this statement.
5069c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
5070c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Element.get() == S->getElement() &&
5071c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Collection.get() == S->getCollection() &&
5072c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Body.get() == S->getBody())
50733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5074c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5075c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Build a new statement.
5076c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5077c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   /*FIXME:*/S->getForLoc(),
50789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Element.get(),
50799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Collection.get(),
5080c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   S->getRParenLoc(),
50819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Body.get());
508243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
508343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
508443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
508543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
508660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
508743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
508843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the exception declaration, if any.
508943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  VarDecl *Var = 0;
509043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (S->getExceptionDecl()) {
509143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    VarDecl *ExceptionDecl = S->getExceptionDecl();
509283cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    TypeSourceInfo *T = getDerived().TransformType(
509383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getTypeSourceInfo());
509483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    if (!T)
5095f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
50961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
509783cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
509843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                            ExceptionDecl->getIdentifier(),
509983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getLocation());
5100ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor    if (!Var || Var->isInvalidDecl())
5101f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
510243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
51031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
510443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the actual exception handler.
510560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5106ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor  if (Handler.isInvalid())
5107f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
510943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
511043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !Var &&
511143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Handler.get() == S->getHandlerBlock())
51123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
511443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
511543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          Var,
51169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Handler.get());
511743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
511943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
512060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
512143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
512243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the try block itself.
512360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBlock
512443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    = getDerived().TransformCompoundStmt(S->getTryBlock());
512543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (TryBlock.isInvalid())
5126f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
512843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the handlers.
512943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool HandlerChanged = false;
5130ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Handlers(SemaRef);
513143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
513260d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Handler
513343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      = getDerived().TransformCXXCatchStmt(S->getHandler(I));
513443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Handler.isInvalid())
5135f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
51361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
513843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Handlers.push_back(Handler.takeAs<Stmt>());
513943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
51401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
514143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
514243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      TryBlock.get() == S->getTryBlock() &&
514343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !HandlerChanged)
51443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
514543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
51469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
51471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        move_arg(Handlers));
514843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
515043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
5151b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation
5152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
51531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
515460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5155454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
51563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
51571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
51581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
516060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5161454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
5162a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *Qualifier = 0;
5163a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (E->getQualifier()) {
5164a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5165edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                       E->getQualifierRange());
5166a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!Qualifier)
5167f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5168a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5169dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5170dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *ND
51717c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
51727c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getDecl()));
5173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!ND)
5174f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
51751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5176ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  DeclarationNameInfo NameInfo = E->getNameInfo();
5177ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  if (NameInfo.getName()) {
5178ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5179ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    if (!NameInfo.getName())
5180f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5181ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  }
51822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
51832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!getDerived().AlwaysRebuild() &&
5184a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      Qualifier == E->getQualifier() &&
5185a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ND == E->getDecl() &&
51862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NameInfo.getName() == E->getDecl()->getDeclName() &&
5187096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
51881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5189dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // Mark it referenced in the new context regardless.
5190dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: this is a bit instantiation-specific.
5191dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5192a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
51933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5194a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5195dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5196dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
5197096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
5198dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TemplateArgs = &TransArgs;
5199dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
5200dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
5201fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5202fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
5203fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
5204fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
5205dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
5206dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5207a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
52082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, TemplateArgs);
5209577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
52101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
521260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5213454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
52143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5215577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
52161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
521860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5219454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
52203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
522460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5225454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
52263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
523060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5231454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
52323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5233b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
523660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5237454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
52383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5241b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
524260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5243454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
524460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5245b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5246f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5248b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
52493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
52501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
5252b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       E->getRParen());
5253b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
52551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
525660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5257454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
525860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5260f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
52633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
52641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getOpcode(),
52679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get());
5268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5270b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
527160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
52728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
52738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform the type.
52748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
52758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!Type)
5276f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5277c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
52788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform all of the components into components similar to what the
52798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // parser uses.
5280c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // FIXME: It would be slightly more efficient in the non-dependent case to
5281c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // just map FieldDecls, rather than requiring the rebuilder to look for
5282c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // the fields again. However, __builtin_offsetof is rare enough in
52838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // template code that we don't care.
52848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool ExprChanged = false;
5285f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::OffsetOfComponent Component;
52868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef OffsetOfExpr::OffsetOfNode Node;
52878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  llvm::SmallVector<Component, 4> Components;
52888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
52898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const Node &ON = E->getComponent(I);
52908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Component Comp;
529172be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor    Comp.isBrackets = true;
52928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Comp.LocStart = ON.getRange().getBegin();
52938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Comp.LocEnd = ON.getRange().getEnd();
52948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    switch (ON.getKind()) {
52958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Array: {
52968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
529760d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(FromIndex);
52988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (Index.isInvalid())
5299f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
5300c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      ExprChanged = ExprChanged || Index.get() != FromIndex;
53028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = true;
53039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Comp.U.E = Index.get();
53048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
53058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5306c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Field:
53088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Identifier:
53098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = false;
53108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.U.IdentInfo = ON.getFieldName();
531129d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor      if (!Comp.U.IdentInfo)
531229d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor        continue;
5313c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
5315c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5316cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    case Node::Base:
5317cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      // Will be recomputed during the rebuild.
5318cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      continue;
53198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5320c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Components.push_back(Comp);
53228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
5323c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // If nothing changed, retain the existing expression.
53258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
53268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Type == E->getTypeSourceInfo() &&
53278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      !ExprChanged)
53283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5329c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Build a new offsetof expression.
53318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
53328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          Components.data(), Components.size(),
53338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          E->getRParenLoc());
53347cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}
53357cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
53367cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived>
53377cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult
53387cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
53397cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  assert(getDerived().AlreadyTransformed(E->getType()) &&
53407cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall         "opaque value expression requires transformation");
53417cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  return SemaRef.Owned(E);
53428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
53438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
53448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived>
534560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5346454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
5347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isArgumentType()) {
5348a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *OldT = E->getArgumentTypeInfo();
53495557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor
5350a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *NewT = getDerived().TransformType(OldT);
53515ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!NewT)
5352f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53545ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!getDerived().AlwaysRebuild() && OldT == NewT)
53553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
53561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53575ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
53581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             E->isSizeOf(),
5359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getSourceRange());
5360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
53611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
536260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr;
53631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  {
5364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // C++0x [expr.sizeof]p1:
5365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   The operand is either an expression, which is an unevaluated operand
5366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   [...]
5367f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
53681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
5371f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
53743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
5375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
53761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
5378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isSizeOf(),
5379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getSourceRange());
5380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
53811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
538360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5384454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
538560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5387f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
53881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
538960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5391f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
53921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5394b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
53973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
53981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
5400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           /*FIXME:*/E->getLHS()->getLocStart(),
54019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                RHS.get(),
5402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getRBracketLoc());
5403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
540660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5407454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
5408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the callee.
540960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
5411f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5413b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform arguments.
5414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgChanged = false;
5415ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
5416aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5417aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
5418aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
5419aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
5420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
5422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgChanged)
54233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
54241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Wrong source location information for the '('.
54261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLParenLoc
5427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = ((Expr *)Callee.get())->getSourceRange().getBegin();
54289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
5429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      move_arg(Args),
5430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
5431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
543460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5435454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
543660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
5437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
5438f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
544083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  NestedNameSpecifier *Qualifier = 0;
544183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (E->hasQualifier()) {
54421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Qualifier
544383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5444edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  E->getQualifierRange());
5445c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (Qualifier == 0)
5446f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
544783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
54481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5449f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *Member
54507c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
54517c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getMemberDecl()));
5452b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Member)
5453f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54556bb8017bb9e828d118e15e59d71c66bba323c364John McCall  NamedDecl *FoundDecl = E->getFoundDecl();
54566bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (FoundDecl == E->getMemberDecl()) {
54576bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = Member;
54586bb8017bb9e828d118e15e59d71c66bba323c364John McCall  } else {
54596bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = cast_or_null<NamedDecl>(
54606bb8017bb9e828d118e15e59d71c66bba323c364John McCall                   getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
54616bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!FoundDecl)
5462f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
54636bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
54646bb8017bb9e828d118e15e59d71c66bba323c364John McCall
5465b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase() &&
546783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      Qualifier == E->getQualifier() &&
54688a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor      Member == E->getMemberDecl() &&
54696bb8017bb9e828d118e15e59d71c66bba323c364John McCall      FoundDecl == E->getFoundDecl() &&
5470096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
5471c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54721f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // Mark it referenced in the new context regardless.
54731f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // FIXME: this is a bit instantiation-specific.
54741f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
54753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
54761f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson  }
5477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5478d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs;
5479096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
5480d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
5481d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
5482fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5483fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
5484fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
5485fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
54868a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor  }
5487c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bogus source location for the operator
5489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeOperatorLoc
5490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5492c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
5493c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
5494c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
5495c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
5496c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
5497c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
54989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
5499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isArrow(),
550083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                        Qualifier,
550183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                        E->getQualifierRange(),
55022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                        E->getMemberNameInfo(),
55038a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor                                        Member,
55046bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        FoundDecl,
5505096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                        (E->hasExplicitTemplateArgs()
5506d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                           ? &TransArgs : 0),
5507c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                        FirstQualifierInScope);
5508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
55091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
551160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5512454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
551360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5515f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
551760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5519f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
55243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
55251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
55279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            LHS.get(), RHS.get());
5528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
55301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
553160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator(
5533454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CompoundAssignOperator *E) {
5534454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformBinaryOperator(E);
5535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
55361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
553860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5539454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
554060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
5541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
5542f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
554460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5546f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
554860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5550f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
5554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
55563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
55571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
55589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildConditionalOperator(Cond.get(),
555947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getQuestionLoc(),
55609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 LHS.get(),
556147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getColonLoc(),
55629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 RHS.get());
5563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
55641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
55651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
556660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5567454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
5568a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // Implicit casts are eliminated during transformation, since they
5569a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // will be recomputed by semantic analysis after transformation.
55706eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return getDerived().TransformExpr(E->getSubExprAsWritten());
5571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
55721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
557460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5575454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
5576ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5577ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
5578ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
5579ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
558060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
55816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
5582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5583f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5586ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
5587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
55883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
55891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
55909d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
5591ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                            Type,
5592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc(),
55939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            SubExpr.get());
5594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
55951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
559760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5598454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
559942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *OldT = E->getTypeSourceInfo();
560042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
560142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  if (!NewT)
5602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
560460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
5605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
5606f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
560942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      OldT == NewT &&
5610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInitializer())
56113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
56131d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // Note: the expression type doesn't necessarily match the
56141d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // type-as-written, but that's okay, because it should always be
56151d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // derivable from the initializer.
56161d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
561742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
5618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   /*FIXME:*/E->getInitializer()->getLocEnd(),
56199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Init.get());
5620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
562360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5624454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
562560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
5626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
5627f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase())
56313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
56321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bad source location
56341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeOperatorLoc
5635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
56369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
5637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessorLoc(),
5638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessor());
5639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
564260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5643454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
5644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool InitChanged = false;
56451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5646ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
5647aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5648aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  Inits, &InitChanged))
5649aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
5650aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
5651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && !InitChanged)
56523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
56531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
5655e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                      E->getRBraceLoc(), E->getType());
5656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
565960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5660454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
5661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Designation Desig;
56621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
566343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the initializer value
566460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInit());
5665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
5666f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
566843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the designators.
5669ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
5670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ExprChanged = false;
5671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             DEnd = E->designators_end();
5673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       D != DEnd; ++D) {
5674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isFieldDesignator()) {
5675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Desig.AddDesignator(Designator::getField(D->getFieldName(),
5676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getDotLoc(),
5677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getFieldLoc()));
5678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
5679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
56801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isArrayDesignator()) {
568260d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
5683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Index.isInvalid())
5684f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
56851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Desig.AddDesignator(Designator::getArray(Index.get(),
5687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getLBracketLoc()));
56881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArrayExprs.push_back(Index.release());
5691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
5692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
56931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(D->isArrayRangeDesignator() && "New kind of designator?");
569560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Start
5696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Start.isInvalid())
5698f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
56991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
570060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
5701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (End.isInvalid())
5702f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
57031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Desig.AddDesignator(Designator::getArrayRange(Start.get(),
5705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  End.get(),
5706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getLBracketLoc(),
5707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getEllipsisLoc()));
57081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      End.get() != E->getArrayRangeEnd(*D);
57111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(Start.release());
5713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(End.release());
5714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
57151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInit() &&
5718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ExprChanged)
57193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
57201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getEqualOrColonLoc(),
57239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                E->usesGNUSyntax(), Init.get());
5724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
572760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr(
5729454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     ImplicitValueInitExpr *E) {
57305557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5731c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
57325557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // FIXME: Will we ever have proper type location here? Will we actually
57335557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // need to transform the type?
5734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
5735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
5736f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType())
57403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
57411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildImplicitValueInitExpr(T);
5743b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
574660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5747454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
57489bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
57499bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo)
5750f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
575260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5754f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
57572cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      TInfo == E->getWrittenTypeInfo() &&
5758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
57593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
57601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
57622cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                       TInfo, E->getRParenLoc());
5763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
576660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5767454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
5768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5769ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
5770aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5771aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
5772aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
5773aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
5774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           move_arg(Inits),
5776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getRParenLoc());
5777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression.
5780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
5781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always
5782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to
5783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis.
5784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
578560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5786454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
5787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLabel());
5789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
579260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5793454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
579460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt
5795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubStmt.isInvalid())
5797f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubStmt.get() == E->getSubStmt())
58013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
58049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      SubStmt.get(),
5805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
5806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
580960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5810454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
581160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
5812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
5813f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
581560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5817f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
581960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5821f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
5825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
58273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
58309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Cond.get(), LHS.get(), RHS.get(),
5831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->getRParenLoc());
5832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
583560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5836454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
58373fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
584160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5842454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
5843668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  switch (E->getOperator()) {
5844668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_New:
5845668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Delete:
5846668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_New:
5847668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_Delete:
5848668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
5849f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5850c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5851668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Call: {
5852668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // This is a call to an object's operator().
5853668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5854668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5855668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the object itself.
585660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Object = getDerived().TransformExpr(E->getArg(0));
5857668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    if (Object.isInvalid())
5858f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5859668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5860668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // FIXME: Poor location information
5861668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    SourceLocation FakeLParenLoc
5862668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      = SemaRef.PP.getLocForEndOfToken(
5863668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                              static_cast<Expr *>(Object.get())->getLocEnd());
5864668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5865668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the call arguments.
5866ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> Args(SemaRef);
5867aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5868aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                    Args))
5869aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return ExprError();
5870668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
58719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
5872668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        move_arg(Args),
5873668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        E->getLocEnd());
5874668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
5875668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5876668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5877668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_##Name:
5878668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5879668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def"
5880668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Subscript:
5881668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Handled below.
5882668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    break;
5883668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5884668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Conditional:
5885668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("conditional operator is not actually overloadable");
5886f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5887668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5888668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_None:
5889668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case NUM_OVERLOADED_OPERATORS:
5890668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("not an overloaded operator?");
5891f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5892668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
5893668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
589460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
5896f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
589860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult First = getDerived().TransformExpr(E->getArg(0));
5899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (First.isInvalid())
5900f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
590260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Second;
5903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->getNumArgs() == 2) {
5904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Second = getDerived().TransformExpr(E->getArg(1));
5905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Second.isInvalid())
5906f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
59081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5910b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
5911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      First.get() == E->getArg(0) &&
59121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
59133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
59141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5915b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 E->getOperatorLoc(),
59179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Callee.get(),
59189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 First.get(),
59199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Second.get());
5920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
592360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5924454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5925454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCallExpr(E);
5926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
592960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5930454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
5931ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5932ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
5933ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
5934ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
593560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
59366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
5937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5938f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5941ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
5942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
59433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
59441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Poor source location information here.
59461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLAngleLoc
5947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRParenLoc
5950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(
5951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  E->getSubExpr()->getSourceRange().getEnd());
5952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
59531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              E->getStmtClass(),
5954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeLAngleLoc,
5955ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                              Type,
5956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
5957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
59589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              SubExpr.get(),
5959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRParenLoc);
5960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
596360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5964454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5965454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
596960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5970454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5971454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
597560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr(
5977454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CXXReinterpretCastExpr *E) {
5978454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
598260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5983454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5984454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
598860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5989b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr(
5990454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXFunctionalCastExpr *E) {
5991ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5992ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
5993ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
59941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
599560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
59966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
5997b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5998f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6001ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
60033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6005ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  return getDerived().RebuildCXXFunctionalCastExpr(Type,
6006b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      /*FIXME:*/E->getSubExpr()->getLocStart(),
60079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr.get(),
6008b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   E->getRParenLoc());
6009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
601260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6013454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
6014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isTypeOperand()) {
601557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    TypeSourceInfo *TInfo
601657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      = getDerived().TransformType(E->getTypeOperandSourceInfo());
601757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    if (!TInfo)
6018f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
60191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
602157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        TInfo == E->getTypeOperandSourceInfo())
60223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
60231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
602457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return getDerived().RebuildCXXTypeidExpr(E->getType(),
602557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             E->getLocStart(),
602657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             TInfo,
6027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getLocEnd());
6028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
60291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // We don't know whether the expression is potentially evaluated until
6031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // after we perform semantic analysis, so the expression is potentially
6032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // potentially evaluated.
60331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  EnterExpressionEvaluationContext Unevaluated(SemaRef,
6034f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      Sema::PotentiallyPotentiallyEvaluated);
60351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
603660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6038f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6040b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getExprOperand())
60423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
604457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  return getDerived().RebuildCXXTypeidExpr(E->getType(),
604557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                           E->getLocStart(),
60469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get(),
6047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLocEnd());
6048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
605160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
605201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
605301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (E->isTypeOperand()) {
605401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    TypeSourceInfo *TInfo
605501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      = getDerived().TransformType(E->getTypeOperandSourceInfo());
605601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!TInfo)
605701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      return ExprError();
605801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
605901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!getDerived().AlwaysRebuild() &&
606001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet        TInfo == E->getTypeOperandSourceInfo())
60613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
606201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
606301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getDerived().RebuildCXXTypeidExpr(E->getType(),
606401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocStart(),
606501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             TInfo,
606601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocEnd());
606701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
606801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
606901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // We don't know whether the expression is potentially evaluated until
607001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // after we perform semantic analysis, so the expression is potentially
607101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // potentially evaluated.
607201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
607301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
607401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
607501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (SubExpr.isInvalid())
607601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return ExprError();
607701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
607801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (!getDerived().AlwaysRebuild() &&
607901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      SubExpr.get() == E->getExprOperand())
60803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
608101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
608201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  return getDerived().RebuildCXXUuidofExpr(E->getType(),
608301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocStart(),
608401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           SubExpr.get(),
608501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocEnd());
608601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}
608701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
608801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived>
608901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult
6090454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
60913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6094b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
609560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6096b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
6097454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXNullPtrLiteralExpr *E) {
60983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
610260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6103454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
6104ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  DeclContext *DC = getSema().getFunctionLevelDeclContext();
6105ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6106ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  QualType T = MD->getThisType(getSema().Context);
61071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6108ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!getDerived().AlwaysRebuild() && T == E->getType())
61093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6111828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
6112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6114b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
611560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6116454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
611760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6118b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6119f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6122b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
61233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
61259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
6126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
612960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6130454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
61311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParmVarDecl *Param
61327c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
61337c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           E->getParam()));
6134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Param)
6135f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
613753cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth  if (!getDerived().AlwaysRebuild() &&
6138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Param == E->getParam())
61393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6141036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
6142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6144b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
614560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6146ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6147ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXScalarValueInitExpr *E) {
6148ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6149ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6150f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6151ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
6152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6153ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo())
61543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6156ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXScalarValueInitExpr(T,
6157ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
6158ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor                                                    E->getRParenLoc());
6159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
616260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6163454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
6164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the type that we're allocating
61651bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocTypeInfo
61661bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
61671bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  if (!AllocTypeInfo)
6168f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the size of the array we're allocating (if any).
617160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
6172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (ArraySize.isInvalid())
6173f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the placement arguments (if any).
6176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6177ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> PlacementArgs(SemaRef);
6178aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getPlacementArgs(),
6179aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  E->getNumPlacementArgs(), true,
6180aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  PlacementArgs, &ArgumentChanged))
6181aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
61821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
618343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the constructor arguments (if any).
6184ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
6185aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6186aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     ConstructorArgs, &ArgumentChanged))
6187aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
61881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform constructor, new operator, and delete operator.
61901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  CXXConstructorDecl *Constructor = 0;
61911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getConstructor()) {
61921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    Constructor = cast_or_null<CXXConstructorDecl>(
61937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
61947c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
61951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!Constructor)
6196f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
61971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
61981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
61991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorNew = 0;
62001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorNew()) {
62011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorNew = cast_or_null<FunctionDecl>(
62027c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(E->getLocStart(),
62037c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getOperatorNew()));
62041af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorNew)
6205f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
62061af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
62071af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
62081af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
62091af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
62101af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
62117c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
62127c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
62131af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6214f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
62151af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6216c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
62181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor      AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
6219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArraySize.get() == E->getArraySize() &&
62201af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Constructor == E->getConstructor() &&
62211af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorNew == E->getOperatorNew() &&
62221af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete() &&
62231af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      !ArgumentChanged) {
62241af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
62251af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
62261af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (Constructor)
62271af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
62281af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorNew)
62291af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
62301af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
62311af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
62323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62331af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
62341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62351bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  QualType AllocType = AllocTypeInfo->getType();
62365b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  if (!ArraySize.get()) {
62375b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // If no array size was specified, but the new expression was
62385b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with an array type (e.g., "new T" where T is
62395b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with "int[4]"), extract the outer bound from the
62405b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // array type as our array size. We do this with constant and
62415b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // dependently-sized array types.
62425b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
62435b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    if (!ArrayT) {
62445b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      // Do nothing
62455b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const ConstantArrayType *ConsArrayT
62465b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                                     = dyn_cast<ConstantArrayType>(ArrayT)) {
6247c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      ArraySize
62489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
62499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               ConsArrayT->getSize(),
62509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               SemaRef.Context.getSizeType(),
62519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               /*FIXME:*/E->getLocStart()));
62525b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      AllocType = ConsArrayT->getElementType();
62535b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const DependentSizedArrayType *DepArrayT
62545b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                              = dyn_cast<DependentSizedArrayType>(ArrayT)) {
62555b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      if (DepArrayT->getSizeExpr()) {
62563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall        ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
62575b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor        AllocType = DepArrayT->getElementType();
62585b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      }
62595b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    }
62605b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  }
62611bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
6262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isGlobalNew(),
6264b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
6265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(PlacementArgs),
6266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
62674bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                        E->getTypeIdParens(),
6268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        AllocType,
62691bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                        AllocTypeInfo,
62709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        ArraySize.get(),
6271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
6272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(ConstructorArgs),
62731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        E->getLocEnd());
6274b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
627760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6278454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
627960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
6280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Operand.isInvalid())
6281f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62831af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform the delete operator, if known.
62841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
62851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
62861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
62877c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
62887c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
62891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6290f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
62911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6292c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
62941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Operand.get() == E->getArgument() &&
62951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete()) {
62961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
62971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
62981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
62991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
63005833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
63015833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    if (!E->getArgument()->isTypeDependent()) {
63025833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      QualType Destroyed = SemaRef.Context.getBaseElementType(
63035833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                                         E->getDestroyedType());
63045833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
63055833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
63065833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        SemaRef.MarkDeclarationReferenced(E->getLocStart(),
63075833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                          SemaRef.LookupDestructor(Record));
63085833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      }
63095833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    }
63105833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
63113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63121af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
63131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isGlobalDelete(),
6316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isArrayForm(),
63179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Operand.get());
6318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
632160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6322a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
6323454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXPseudoDestructorExpr *E) {
632460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6325a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  if (Base.isInvalid())
6326f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6328b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ObjectTypePtr;
6329a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  bool MayBePseudoDestructor = false;
63309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
6331a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              E->getOperatorLoc(),
6332a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        E->isArrow()? tok::arrow : tok::period,
6333a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              ObjectTypePtr,
6334a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              MayBePseudoDestructor);
6335a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (Base.isInvalid())
6336f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6337c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6338b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  QualType ObjectType = ObjectTypePtr.get();
633943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  NestedNameSpecifier *Qualifier = E->getQualifier();
634043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Qualifier) {
634143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Qualifier
634243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
634343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  E->getQualifierRange(),
634443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  ObjectType);
634543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (!Qualifier)
634643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      return ExprError();
634743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
63481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6349a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage Destroyed;
6350a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (E->getDestroyedTypeInfo()) {
6351a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    TypeSourceInfo *DestroyedTypeInfo
635243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
635343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjectType, 0, Qualifier);
6354a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!DestroyedTypeInfo)
6355f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6356a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = DestroyedTypeInfo;
6357a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else if (ObjectType->isDependentType()) {
6358a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // We aren't likely to be able to resolve the identifier down to a type
6359a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // now anyway, so just retain the identifier.
6360a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6361a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                            E->getDestroyedTypeLoc());
6362a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else {
6363a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // Look for a destructor known with the given name.
6364a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    CXXScopeSpec SS;
6365a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (Qualifier) {
6366a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      SS.setScopeRep(Qualifier);
6367a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      SS.setRange(E->getQualifierRange());
6368a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    }
6369c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6370b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
6371a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              *E->getDestroyedTypeIdentifier(),
6372a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                E->getDestroyedTypeLoc(),
6373a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                /*Scope=*/0,
6374a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                SS, ObjectTypePtr,
6375a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                false);
6376a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!T)
6377f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6379a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed
6380a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6381a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                 E->getDestroyedTypeLoc());
6382a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
638326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
638426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *ScopeTypeInfo = 0;
638526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (E->getScopeTypeInfo()) {
638643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
638726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    if (!ScopeTypeInfo)
6388f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6389a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
6390c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
63919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
6392a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->getOperatorLoc(),
6393a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->isArrow(),
6394a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     Qualifier,
639526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getQualifierRange(),
639626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     ScopeTypeInfo,
639726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getColonColonLoc(),
6398fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                     E->getTildeLoc(),
6399a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                     Destroyed);
6400a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}
64011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6402a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived>
640360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6404ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr(
6405454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  UnresolvedLookupExpr *Old) {
6406f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6407f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6408f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6409f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                 Sema::LookupOrdinaryName);
6410f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6411f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Transform all the decls.
6412f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6413f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall         E = Old->decls_end(); I != E; ++I) {
64147c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
64157c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(Old->getNameLoc(),
64167c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                            *I));
64179f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
64189f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
64199f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
64209f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
64219f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
64229f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
6423f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
64249f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
6425f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6426f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // Expand using declarations.
6427f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (isa<UsingDecl>(InstD)) {
6428f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
6429f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6430f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall             E = UD->shadow_end(); I != E; ++I)
6431f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        R.addDecl(*I);
6432f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      continue;
6433f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    }
6434f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6435f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    R.addDecl(InstD);
6436f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
6437f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6438f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Resolve a kind, but don't do any further analysis.  If it's
6439f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // ambiguous, the callee needs to deal with it.
6440f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  R.resolveKind();
6441f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6442f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Rebuild the nested-name qualifier, if present.
6443f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  CXXScopeSpec SS;
6444f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  NestedNameSpecifier *Qualifier = 0;
6445f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (Old->getQualifier()) {
6446f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
6447edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                    Old->getQualifierRange());
6448f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!Qualifier)
6449f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6450c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6451f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SS.setScopeRep(Qualifier);
6452f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SS.setRange(Old->getQualifierRange());
6453c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
6454c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6455c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (Old->getNamingClass()) {
645666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    CXXRecordDecl *NamingClass
645766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
645866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                            Old->getNameLoc(),
645966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
646066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
6461f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6462c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
646366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
6464f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
6465f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6466f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have no template arguments, it's a normal declaration name.
6467f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!Old->hasExplicitTemplateArgs())
6468f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6469f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6470f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have template arguments, rebuild them, then rebuild the
6471f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // templateid expression.
6472f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
6473fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6474fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              Old->getNumTemplateArgs(),
6475fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
6476fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
6477f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6478f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6479f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                            TransArgs);
6480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
648360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6484454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
64853d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
64863d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  if (!T)
6487f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
64903d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      T == E->getQueriedTypeSourceInfo())
64913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
6494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocStart(),
6495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            T,
6496b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocEnd());
6497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
650060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
65016ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
65026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
65036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!LhsT)
65046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
65056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
65066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
65076ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!RhsT)
65086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
65096ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
65106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!getDerived().AlwaysRebuild() &&
65116ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
65126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SemaRef.Owned(E);
65136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
65146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
65156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocStart(),
65166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            LhsT, RhsT,
65176ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocEnd());
65186ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}
65196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
65206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived>
65216ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult
6522865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
65232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                               DependentScopeDeclRefExpr *E) {
6524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  NestedNameSpecifier *NNS
6525f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor    = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6526edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                E->getQualifierRange());
6527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!NNS)
6528f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
653043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
653143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
653243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
653343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
65342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
65352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
65362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
6537f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6539f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!E->hasExplicitTemplateArgs()) {
6540f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!getDerived().AlwaysRebuild() &&
6541f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        NNS == E->getQualifier() &&
65422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // Note: it is sufficient to compare the Name component of NameInfo:
65432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // if name has not changed, DNLoc has not changed either.
65442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getDeclName())
65453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
65461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6547f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6548f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         E->getQualifierRange(),
65492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                         NameInfo,
6550f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         /*TemplateArgs*/ 0);
6551f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor  }
6552d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
6553d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
6554fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6555fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
6556fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
6557fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
6558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6559f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6560f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       E->getQualifierRange(),
65612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
6562f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       &TransArgs);
6563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
656660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6567454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
6568321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // CXXConstructExprs are always implicit, so when we have a
6569321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // 1-argument construction we just transform that argument.
6570321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  if (E->getNumArgs() == 1 ||
6571321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor      (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6572321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor    return getDerived().TransformExpr(E->getArg(0));
6573321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor
6574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
6577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
6578f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
6581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
65827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(E->getLocStart(),
65837c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
6584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
6585f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6588ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6589aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6590aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
6591aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6592aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType() &&
6595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
6596c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor      !ArgumentChanged) {
65971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark the constructor as referenced.
65981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: Instantiation-specific
6599c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
66003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6601c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor  }
66021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66034411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
66044411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                              Constructor, E->isElidable(),
66058c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              move_arg(Args),
66068c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              E->requiresZeroInitialization(),
6607428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getConstructionKind(),
6608428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getParenRange());
6609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression.
6612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
66135132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
66145132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that.
6615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
661660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6617454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
66185132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
6619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66214765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should
66224765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated.
6623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
66244765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we
66255132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that.
6626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
662760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
66284765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
66295132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
6630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
663360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
6635ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXTemporaryObjectExpr *E) {
6636ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6637ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6638f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
6641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
6642c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                  getDerived().TransformDecl(E->getLocStart(),
66437c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
6644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
6645f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6648ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Args.reserve(E->getNumArgs());
6650aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6651aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
6652aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
66531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6655ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
6656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
665791be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      !ArgumentChanged) {
665891be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    // FIXME: Instantiation-specific
6659ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
66603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.MaybeBindToTemporary(E);
666191be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor  }
6662ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
6663ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXTemporaryObjectExpr(T,
6664ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
6665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    move_arg(Args),
6666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    E->getLocEnd());
6667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
667060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
6672454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  CXXUnresolvedConstructExpr *E) {
6673ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6674ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6675f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6678ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6679aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->arg_size());
6680aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6681aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
6682aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6683aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6685ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
6686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
66873fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: we're faking the locations of the commas
6690ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
6691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getLParenLoc(),
6692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        move_arg(Args),
6693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getRParenLoc());
6694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
669760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6698865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
66992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                             CXXDependentScopeMemberExpr *E) {
6700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the base of the expression.
670160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
6702aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *OldBase;
6703aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
6704aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType ObjectType;
6705aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->isImplicitAccess()) {
6706aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = E->getBase();
6707aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(OldBase);
6708aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
6709f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
67101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6711aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    // Start the member reference and compute the object's type.
6712b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ObjectTy;
6713d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor    bool MayBePseudoDestructor = false;
67149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
6715aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                E->getOperatorLoc(),
6716a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                      E->isArrow()? tok::arrow : tok::period,
6717d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                ObjectTy,
6718d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                MayBePseudoDestructor);
6719aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
6720f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6721aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
6722b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ObjectType = ObjectTy.get();
6723aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
6724aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
6725aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = 0;
6726aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(E->getBaseType());
6727aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6728aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
67291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67306cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // Transform the first part of the nested-name-specifier that qualifies
67316cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // the member name.
6732c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierInScope
67336cd219879ffce00920189ec1dcea927a42602961Douglas Gregor    = getDerived().TransformFirstQualifierInScope(
67346cd219879ffce00920189ec1dcea927a42602961Douglas Gregor                                          E->getFirstQualifierFoundInScope(),
67356cd219879ffce00920189ec1dcea927a42602961Douglas Gregor                                          E->getQualifierRange().getBegin());
67361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6737a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  NestedNameSpecifier *Qualifier = 0;
6738a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  if (E->getQualifier()) {
6739a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6740a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                      E->getQualifierRange(),
6741aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                      ObjectType,
6742aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                      FirstQualifierInScope);
6743a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    if (!Qualifier)
6744f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6745a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  }
67461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
674743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
674843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
674943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
675043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
67512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
675243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
67532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
6754f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6756aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->hasExplicitTemplateArgs()) {
67573b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // This is a reference to a member without an explicitly-specified
67583b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // template argument list. Optimize for this common case.
67593b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
6760aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        Base.get() == OldBase &&
6761aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        BaseType == E->getBaseType() &&
67623b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        Qualifier == E->getQualifier() &&
67632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getMember() &&
67643b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        FirstQualifierInScope == E->getFirstQualifierFoundInScope())
67653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
67661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
6768aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                       BaseType,
67693b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->isArrow(),
67703b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getOperatorLoc(),
67713b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       Qualifier,
67723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getQualifierRange(),
6773129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       FirstQualifierInScope,
67742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
6775129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       /*TemplateArgs*/ 0);
67763b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
67773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor
6778d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
6779fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6780fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
6781fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
6782fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
67831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
6785aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                     BaseType,
6786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->isArrow(),
6787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->getOperatorLoc(),
6788a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     Qualifier,
6789a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     E->getQualifierRange(),
67903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                     FirstQualifierInScope,
67912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                     NameInfo,
6792129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                     &TransArgs);
6793129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}
6794129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6795129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived>
679660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6797454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
6798129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform the base of the expression.
679960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
6800aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
6801aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!Old->isImplicitAccess()) {
6802aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(Old->getBase());
6803aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
6804f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6805aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
6806aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
6807aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(Old->getBaseType());
6808aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
6809129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6810129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  NestedNameSpecifier *Qualifier = 0;
6811129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->getQualifier()) {
6812129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    Qualifier
6813129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
6814edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  Old->getQualifierRange());
6815129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (Qualifier == 0)
6816f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6817129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6818129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
68192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  LookupResult R(SemaRef, Old->getMemberNameInfo(),
6820129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                 Sema::LookupOrdinaryName);
6821129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6822129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform all the decls.
6823129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6824129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         E = Old->decls_end(); I != E; ++I) {
68257c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
68267c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(Old->getMemberLoc(),
68277c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           *I));
68289f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
68299f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
68309f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
68319f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
68329f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
68339f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
6834f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
68359f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
6836129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6837129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    // Expand using declarations.
6838129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (isa<UsingDecl>(InstD)) {
6839129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
6840129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6841129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall             E = UD->shadow_end(); I != E; ++I)
6842129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall        R.addDecl(*I);
6843129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      continue;
6844129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
6845129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6846129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    R.addDecl(InstD);
6847129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6848129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6849129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  R.resolveKind();
6850129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6851c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  // Determine the naming class.
6852042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth  if (Old->getNamingClass()) {
6853c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    CXXRecordDecl *NamingClass
6854c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
685566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                          Old->getMemberLoc(),
685666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
685766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
6858f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6859c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
686066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
6861c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  }
6862c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6863129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  TemplateArgumentListInfo TransArgs;
6864129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->hasExplicitTemplateArgs()) {
6865129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setLAngleLoc(Old->getLAngleLoc());
6866129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setRAngleLoc(Old->getRAngleLoc());
6867fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6868fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                Old->getNumTemplateArgs(),
6869fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
6870fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
6871129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6872c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
6873c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
6874c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
6875c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
6876c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
6877c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
6878c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
68799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
6880aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  BaseType,
6881129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getOperatorLoc(),
6882129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->isArrow(),
6883129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Qualifier,
6884129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getQualifierRange(),
6885c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                                  FirstQualifierInScope,
6886129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  R,
6887129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              (Old->hasExplicitTemplateArgs()
6888129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  ? &TransArgs : 0));
6889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
689260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
68932e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
68942e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
68952e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (SubExpr.isInvalid())
68962e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return ExprError();
68972e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
68982e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
68993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
69002e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
69012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
69022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}
69032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
69042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived>
69052e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult
6906be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
69074f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
69084f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (Pattern.isInvalid())
69094f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return ExprError();
69104f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
69114f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
69124f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return SemaRef.Owned(E);
69134f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
691467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
691567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                           E->getNumExpansions());
6916be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}
6917ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
6918ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived>
6919ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult
6920ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6921ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // If E is not value-dependent, then nothing will change when we transform it.
6922ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: This is an instantiation-centric view.
6923ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (!E->isValueDependent())
6924ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
6925ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
6926ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: None of the implementations of TryExpandParameterPacks can ever
6927ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // produce a diagnostic when given only a single unexpanded parameter pack,
6928ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // so
6929ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6930ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  bool ShouldExpand = false;
6931d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  bool RetainExpansion = false;
6932cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> NumExpansions;
6933ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6934ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                           &Unexpanded, 1,
6935d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           ShouldExpand, RetainExpansion,
6936d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           NumExpansions))
6937ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return ExprError();
6938ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
6939d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  if (!ShouldExpand || RetainExpansion)
6940ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
6941be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
6942ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // We now know the length of the parameter pack, so build a new expression
6943ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // that stores that length.
6944ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6945ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                            E->getPackLoc(), E->getRParenLoc(),
6946cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                            *NumExpansions);
6947ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}
6948ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
6949be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived>
6950be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult
6951c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6952c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                          SubstNonTypeTemplateParmPackExpr *E) {
6953c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Default behavior is to do nothing with this transformation.
6954c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  return SemaRef.Owned(E);
6955c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}
6956c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
6957c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived>
6958c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult
6959454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
69603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
69631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
696460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6965454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
696681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  TypeSourceInfo *EncodedTypeInfo
696781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
696881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  if (!EncodedTypeInfo)
6969f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
69701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
697281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
69733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6975b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
697681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                            EncodedTypeInfo,
6977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc());
6978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
698160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6982454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
698392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Transform arguments.
698492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  bool ArgChanged = false;
6985ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6986aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->getNumArgs());
6987aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6988aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
6989aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6990aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
699192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
699292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Class message: transform the receiver type.
699392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    TypeSourceInfo *ReceiverTypeInfo
699492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      = getDerived().TransformType(E->getClassReceiverTypeInfo());
699592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!ReceiverTypeInfo)
6996f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6997c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
699892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // If nothing changed, just retain the existing message send.
699992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
700092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor        ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
70013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
700292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
700392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Build a new class message send.
700492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
700592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getSelector(),
7006f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                               E->getSelectorLoc(),
700792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getMethodDecl(),
700892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getLeftLoc(),
700992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               move_arg(Args),
701092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getRightLoc());
701192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
701292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
701392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Instance message: transform the receiver
701492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
701592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         "Only class and instance messages may be instantiated");
701660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Receiver
701792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    = getDerived().TransformExpr(E->getInstanceReceiver());
701892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (Receiver.isInvalid())
7019f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
702092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
702192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // If nothing changed, just retain the existing message send.
702292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
702392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
70243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7025c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
702692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Build a new instance message send.
70279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
702892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getSelector(),
7029f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                             E->getSelectorLoc(),
703092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getMethodDecl(),
703192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getLeftLoc(),
703292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             move_arg(Args),
703392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getRightLoc());
7034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
70361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
703760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7038454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
70393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7040b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
70421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
704360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7044454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
70453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7046b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
70481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
704960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7050454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
7051f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
705260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7053f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7054f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7055f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor
7056f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // We don't need to transform the ivar; it will never change.
7057c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7058f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7059f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7060f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
70613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7062c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
70639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
7064f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->getLocation(),
7065f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->isArrow(), E->isFreeIvar());
7066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
70681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
706960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7070454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
707112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // 'super' and types never change. Property never changes. Just
707212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // retain the existing expression.
707312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (!E->isObjectReceiver())
70743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
70758ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian
7076e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // Transform the base expression.
707760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7078e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (Base.isInvalid())
7079f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7080c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7081e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // We don't need to transform the property; it will never change.
7082c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7083e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // If nothing changed, just retain the existing expression.
7084e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7085e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      Base.get() == E->getBase())
70863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
708812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (E->isExplicitProperty())
708912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
709012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getExplicitProperty(),
709112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getLocation());
709212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall
709312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
709412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getType(),
709512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertyGetter(),
709612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertySetter(),
709712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getLocation());
7098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
71001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
710160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7102454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
7103f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
710460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7105f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7106f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7107c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7108f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7109f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7110f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
71113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7112c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
71139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
7114f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                         E->isArrow());
7115b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7116b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
71171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
711860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7119454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
7120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7121ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> SubExprs(SemaRef);
7122aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  SubExprs.reserve(E->getNumSubExprs());
7123aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7124aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  SubExprs, &ArgumentChanged))
7125aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
71261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
71293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
71301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move_arg(SubExprs),
7133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               E->getRParenLoc());
7134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
71361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
713760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7138454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
7139a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  SourceLocation CaretLoc(E->getExprLoc());
7140a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7141a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
7142a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
7143a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
7144a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  llvm::SmallVector<ParmVarDecl*, 4> Params;
7145a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  llvm::SmallVector<QualType, 4> ParamTypes;
7146a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7147a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Parameter substitution.
7148a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  BlockDecl *BD = E->getBlockDecl();
7149a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7150a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                                               BD->param_begin(),
7151a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                                               BD->param_size(), 0, ParamTypes,
7152a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                                               &Params))
7153a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return true;
7154a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7155a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7156a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  const FunctionType *BExprFunctionType = E->getFunctionType();
7157a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  QualType BExprResultType = BExprFunctionType->getResultType();
7158a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!BExprResultType.isNull()) {
7159a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    if (!BExprResultType->isDependentType())
7160a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      CurBlock->ReturnType = BExprResultType;
7161a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    else if (BExprResultType != SemaRef.Context.DependentTy)
7162a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
7163a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7164a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7165a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type has not been determined yet, leave it as a dependent
7166a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // type; it'll get set when we process the body.
7167a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  if (CurBlock->ReturnType.isNull())
7168a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    CurBlock->ReturnType = getSema().Context.DependentTy;
7169a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7170a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // Don't allow returning a objc interface by value.
7171a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  if (CurBlock->ReturnType->isObjCObjectType()) {
7172a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    getSema().Diag(E->getLocStart(),
7173a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                   diag::err_object_cannot_be_passed_returned_by_value)
7174a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor      << 0 << CurBlock->ReturnType;
7175a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return ExprError();
7176a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  }
7177711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7178a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  QualType FunctionType = getDerived().RebuildFunctionProtoType(
7179a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        CurBlock->ReturnType,
7180a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        ParamTypes.data(),
7181a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        ParamTypes.size(),
7182a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        BD->isVariadic(),
7183c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                        0, RQ_None,
7184fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                               BExprFunctionType->getExtInfo());
7185a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  CurBlock->FunctionType = FunctionType;
7186711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7187711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Set the parameters on the block decl.
7188711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  if (!Params.empty())
7189711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    CurBlock->TheDecl->setParams(Params.data(), Params.size());
7190a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7191a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type wasn't explicitly set, it will have been marked as a
7192a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // dependent type (DependentTy); clear out the return type setting so
7193a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // we will deduce the return type when type-checking the block's body.
7194a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  if (CurBlock->ReturnType == getSema().Context.DependentTy)
7195a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    CurBlock->ReturnType = QualType();
7196a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7197711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Transform the body
7198711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  StmtResult Body = getDerived().TransformStmt(E->getBody());
7199711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  if (Body.isInvalid())
7200711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    return ExprError();
7201711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
72029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
7203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7204b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
72051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
720660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7207454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
7208a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  NestedNameSpecifier *Qualifier = 0;
7209a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7210a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  ValueDecl *ND
7211a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7212a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                       E->getDecl()));
7213a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!ND)
7214f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
7216a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!getDerived().AlwaysRebuild() &&
7217a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      ND == E->getDecl()) {
7218a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // Mark it referenced in the new context regardless.
7219a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // FIXME: this is a bit instantiation-specific.
7220a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7221a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
72223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7223a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7224a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
72252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
7226a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
72272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, 0);
7228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
72291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7230b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
7231b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction
7232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
7233b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
72341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
723585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
723685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                    SourceLocation Star) {
72372865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildPointerType(PointeeType, Star,
7238b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  getDerived().getBaseEntity());
7239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7240b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
72411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
724285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
724385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                         SourceLocation Star) {
72442865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildBlockPointerType(PointeeType, Star,
7245b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       getDerived().getBaseEntity());
7246b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
72481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
72491eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
725085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
725185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             bool WrittenAsLValue,
725285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             SourceLocation Sigil) {
72532865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
725485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    Sigil, getDerived().getBaseEntity());
7255b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7256b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
72571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
72581eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
725985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
726085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 QualType ClassType,
726185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceLocation Sigil) {
72622865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
726385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        Sigil, getDerived().getBaseEntity());
7264577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7265577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7266577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
72671eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
7268577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7269577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         ArrayType::ArraySizeModifier SizeMod,
7270577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         const llvm::APInt *Size,
7271577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         Expr *SizeExpr,
7272577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         unsigned IndexTypeQuals,
7273577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         SourceRange BracketsRange) {
7274577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (SizeExpr || !Size)
7275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  IndexTypeQuals, BracketsRange,
7277577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  getDerived().getBaseEntity());
72781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType Types[] = {
72801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
72811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
72821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
7283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  };
7284577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType SizeType;
7286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  for (unsigned I = 0; I != NumTypes; ++I)
7287577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7288577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      SizeType = Types[I];
7289577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      break;
7290577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    }
72911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
72939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                           /*FIXME*/BracketsRange.getBegin());
72941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
7295577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                IndexTypeQuals, BracketsRange,
72961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                getDerived().getBaseEntity());
7297577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
72981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7299577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
73001eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
73011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
7302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 ArrayType::ArraySizeModifier SizeMod,
7303577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 const llvm::APInt &Size,
730485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
730585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceRange BracketsRange) {
73061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
730785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        IndexTypeQuals, BracketsRange);
7308577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7309577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7310577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
73111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
73121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
7313577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
731485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
731585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   SourceRange BracketsRange) {
73161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
731785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                       IndexTypeQuals, BracketsRange);
7318577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
73191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7320577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
73211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
73221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
7323577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
73249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SizeExpr,
7325577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 unsigned IndexTypeQuals,
7326577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceRange BracketsRange) {
73271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
73289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
7329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
7330577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7331577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7332577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
73331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
73341eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
7335577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
73369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Expr *SizeExpr,
7337577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                       unsigned IndexTypeQuals,
7338577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                   SourceRange BracketsRange) {
73391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
73409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
7341577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
7342577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7343577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7344577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7345577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
7346e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               unsigned NumElements,
7347e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               VectorType::VectorKind VecKind) {
7348577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  // FIXME: semantic checking!
7349e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
7350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
73511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7354577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                      unsigned NumElements,
7355577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceLocation AttributeLoc) {
7356577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7357577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                          NumElements, true);
7358577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  IntegerLiteral *VectorSize
73599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
73609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             AttributeLoc);
73619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
7362577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
73631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7364577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
73651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
73661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
73679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                           Expr *SizeExpr,
7368577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                  SourceLocation AttributeLoc) {
73699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
7370577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
73711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7372577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7373577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
73741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          QualType *ParamTypes,
7375577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                        unsigned NumParamTypes,
73761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          bool Variadic,
7377fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                          unsigned Quals,
7378c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                  RefQualifierKind RefQualifier,
7379fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                            const FunctionType::ExtInfo &Info) {
73801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
7381c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                   Quals, RefQualifier,
7382577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   getDerived().getBaseLocation(),
7383fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   getDerived().getBaseEntity(),
7384fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   Info);
7385577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
73861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7387577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7388a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7389a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return SemaRef.Context.getFunctionNoProtoType(T);
7390a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
7391a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
7392a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
7393ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7394ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  assert(D && "no decl found");
7395ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (D->isInvalidDecl()) return QualType();
7396ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
739792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // FIXME: Doesn't account for ObjCInterfaceDecl!
7398ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeDecl *Ty;
7399ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (isa<UsingDecl>(D)) {
7400ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    UsingDecl *Using = cast<UsingDecl>(D);
7401ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(Using->isTypeName() &&
7402ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-typename using");
7403ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
7404ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    // A valid resolved using typename decl points to exactly one type decl.
7405ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(++Using->shadow_begin() == Using->shadow_end());
7406ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
7407c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7408ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  } else {
7409ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7410ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-using decl");
7411ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<UnresolvedUsingTypenameDecl>(D);
7412ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
7413ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
7414ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return SemaRef.Context.getTypeDeclType(Ty);
7415ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
7416ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
7417ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived>
74182a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
74192a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                       SourceLocation Loc) {
74202a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildTypeofExprType(E, Loc);
7421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7422577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7423577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7424577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7425577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  return SemaRef.Context.getTypeOfType(Underlying);
7426577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7427577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7428577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
74292a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
74302a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                     SourceLocation Loc) {
74312a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildDecltypeType(E, Loc);
7432577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7433577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7434577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7435577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
7436833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                      TemplateName Template,
7437833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateNameLoc,
7438d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                               const TemplateArgumentListInfo &TemplateArgs) {
7439d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
7440577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
74411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7442dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
7443dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
7444dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7445dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
7446a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                   IdentifierInfo &II,
7447c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   QualType ObjectType,
7448d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NamedDecl *FirstQualifierInScope) {
7449dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  CXXScopeSpec SS;
7450dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  // FIXME: The source location information is all wrong.
7451dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SS.setRange(Range);
7452dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SS.setScopeRep(Prefix);
7453dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return static_cast<NestedNameSpecifier *>(
74541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
7455495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor                                                        Range.getEnd(), II,
7456c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                        ObjectType,
7457c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                        FirstQualifierInScope,
745846646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner                                                        false, false));
7459dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
7460dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
7461dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
7462dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
7463dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7464dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
7465dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   NamespaceDecl *NS) {
7466dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7467dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
7468dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
7469dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
7470dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
7471dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7472dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
7473dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   bool TemplateKW,
7474edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                   QualType T) {
7475edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor  if (T->isDependentType() || T->isRecordType() ||
7476dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
7477a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
7478dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7479dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                       T.getTypePtr());
7480dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
74811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7482dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7483dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return 0;
7484dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
74851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7486d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
74871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
7488d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7489d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            bool TemplateKW,
7490d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            TemplateDecl *Template) {
74911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
7492d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                                  Template);
7493d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
7494d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
7495d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
74961eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
7497d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
74981efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                            SourceRange QualifierRange,
74993b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                            const IdentifierInfo &II,
750043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            QualType ObjectType,
750143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            NamedDecl *FirstQualifierInScope) {
7502d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  CXXScopeSpec SS;
75031efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor  SS.setRange(QualifierRange);
75041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SS.setScopeRep(Qualifier);
7505014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  UnqualifiedId Name;
7506014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
7507d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
7508d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
7509d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*FIXME:*/getDerived().getBaseLocation(),
7510d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
7511d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
7512b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
7513d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
7514d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
751543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return Template.get();
7516d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
75171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
7519ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName
7520ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7521ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            OverloadedOperatorKind Operator,
7522ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            QualType ObjectType) {
7523ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  CXXScopeSpec SS;
7524ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SS.setRange(SourceRange(getDerived().getBaseLocation()));
7525ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SS.setScopeRep(Qualifier);
7526ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  UnqualifiedId Name;
7527ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7528ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7529ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                             Operator, SymbolLocations);
7530d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
7531d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
7532ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                       /*FIXME:*/getDerived().getBaseLocation(),
7533d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
7534d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
7535b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
7536d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
7537d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
7538d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  return Template.template getAsVal<TemplateName>();
7539ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor}
7540c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7541ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived>
754260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   SourceLocation OpLoc,
75459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *OrigCallee,
75469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *First,
75479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *Second) {
75489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Callee = OrigCallee->IgnoreParenCasts();
75499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
75501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Determine whether this should be a builtin operation.
7552f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript) {
75539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
75549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType())
75559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinArraySubscriptExpr(First,
75569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Callee->getLocStart(),
75579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Second, OpLoc);
75581a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman  } else if (Op == OO_Arrow) {
75591a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman    // -> is never a builtin operation.
75609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
75619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  } else if (Second == 0 || isPostIncDec) {
75629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType()) {
7563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // The argument is not of overloadable type, so try to create a
7564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // built-in unary operation.
75652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      UnaryOperatorKind Opc
7566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor        = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
75671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
7569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
7570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  } else {
75719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
75729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType()) {
7573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // Neither of the arguments is an overloadable type, so try to
7574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // create a built-in binary operation.
75752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
757660d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Result
75779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
7578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Result.isInvalid())
7579f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
75801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      return move(Result);
7582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
7583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
75841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Compute the transformed set of functions (and function templates) to be
7586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // used during overload resolution.
75876e26689f5d513e24ad7783a4493201930fdeccc0John McCall  UnresolvedSet<16> Functions;
75881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
7590ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    assert(ULE->requiresADL());
7591ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
7592ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // FIXME: Do we have to check
7593ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // IsAcceptableNonMemberOperatorCandidate for each of these?
75946e26689f5d513e24ad7783a4493201930fdeccc0John McCall    Functions.append(ULE->decls_begin(), ULE->decls_end());
7595ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  } else {
75969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
7597ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
75981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Add any functions found via argument-dependent lookup.
76009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Args[2] = { First, Second };
76019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  unsigned NumArgs = 1 + (Second != 0);
76021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for unary operators.
7604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (NumArgs == 1 || isPostIncDec) {
76052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    UnaryOperatorKind Opc
7606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
76079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
7608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
76091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7610f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript)
76119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
7612ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                                      OpLoc,
76139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      First,
76149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Second);
7615f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl
7616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for binary operators.
76172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
761860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result
7619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Result.isInvalid())
7621f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
76221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return move(Result);
7624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
76251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
762626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived>
762760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
76289ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
762926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceLocation OperatorLoc,
763026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       bool isArrow,
763126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                 NestedNameSpecifier *Qualifier,
763226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceRange QualifierRange,
763326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     TypeSourceInfo *ScopeType,
763426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       SourceLocation CCLoc,
7635fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                       SourceLocation TildeLoc,
7636a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed) {
763726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  CXXScopeSpec SS;
763826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (Qualifier) {
763926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    SS.setRange(QualifierRange);
764026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    SS.setScopeRep(Qualifier);
764126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
764226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
76439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  QualType BaseType = Base->getType();
76449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
764526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      (!isArrow && !BaseType->getAs<RecordType>()) ||
7646c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      (isArrow && BaseType->getAs<PointerType>() &&
7647bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif       !BaseType->getAs<PointerType>()->getPointeeType()
7648bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif                                              ->template getAs<RecordType>())){
764926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    // This pseudo-destructor expression is still a pseudo-destructor.
76509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
765126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             isArrow? tok::arrow : tok::period,
7652fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                             SS, ScopeType, CCLoc, TildeLoc,
7653a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                             Destroyed,
765426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             /*FIXME?*/true);
765526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
76562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
7657a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
76582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
76592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
76602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
76612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  NameInfo.setNamedTypeInfo(DestroyedType);
76622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
766326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  // FIXME: the ScopeType should be tacked onto SS.
76642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
76659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getSema().BuildMemberReferenceExpr(Base, BaseType,
766626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            OperatorLoc, isArrow,
766726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            SS, /*FIXME: FirstQualifier*/ 0,
76682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            NameInfo,
766926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            /*TemplateArgs*/ 0);
767026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor}
767126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
7672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang
7673577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
7675