TreeTransform.h revision 34b41d939a1328f484511c6002ba2456db879a29
157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
3577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//                     The LLVM Compiler Infrastructure
4577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
5577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file is distributed under the University of Illinois Open Source
6577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// License. See LICENSE.TXT for details.
757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===//
8577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
9577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//  This file implements a semantic tree transformation that takes a given
10577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//  AST and rebuilds it, possibly transforming some nodes in the process.
11577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
1257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===//
1357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
172d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h"
18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h"
198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor#include "clang/Sema/ParsedTemplate.h"
20dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h"
21781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h"
22c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h"
237cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h"
24657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h"
25b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h"
26b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h"
2743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h"
2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h"
2943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h"
3019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h"
3119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h"
32b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h"
33a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h"
347e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h"
35577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm>
36577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
37577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang {
38781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema;
391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one
41577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another.
42577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of
441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template
46577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the
47577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the
48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar
49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and
50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters.
51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow
531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can
54577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an
55577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The
56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual.
57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which
59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node
60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions,
61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation
63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g.,
64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes
65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create
66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node.
67577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The
69670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(),
70577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations.
73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the
75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
7643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
77577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation
781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template
79577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX
80577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change.
81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps.
84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one
861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation
87577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the
89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking
90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()).
91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform {
93d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief Private RAII object that helps us forget and then re-remember
94d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// the template argument corresponding to a partially-substituted parameter
95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack.
96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  class ForgetPartiallySubstitutedPackRAII {
97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    Derived &Self;
98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    TemplateArgument Old;
99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  public:
101d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Old = Self.ForgetPartiallySubstitutedPack();
103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ~ForgetPartiallySubstitutedPackRAII() {
106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Self.RememberPartiallySubstitutedPack(Old);
107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  };
109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
110577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected:
111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &SemaRef;
1128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Initializes a new tree transformer.
115b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
117577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Derived &getDerived() { return static_cast<Derived&>(*this); }
119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Derived &getDerived() const {
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return static_cast<const Derived&>(*this);
123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
12560d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline ExprResult Owned(Expr *E) { return E; }
12660d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline StmtResult Owned(Stmt *S) { return S; }
1279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall
128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the semantic analysis object used for
129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// this tree transform.
130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &getSema() const { return SemaRef; }
1311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
132577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Whether the transformation should always rebuild AST nodes, even
133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// if none of the children have changed.
134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this function to specify when the transformation
136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// should rebuild all AST nodes.
137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlwaysRebuild() { return false; }
1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the location of the entity being transformed, if that
140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, returns no source-location information. Subclasses can
143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// provide an alternative implementation that provides better location
144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information.
145577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  SourceLocation getBaseLocation() { return SourceLocation(); }
1461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the name of the entity being transformed, if that
148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, returns an empty name. Subclasses can provide an alternative
151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// implementation with a more precise name.
152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  DeclarationName getBaseEntity() { return DeclarationName(); }
153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Sets the "base" location and entity when that
155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// information is known based on another transformation.
156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, the source location and entity are ignored. Subclasses can
158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// override this function to provide a customized implementation.
159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  void setBase(SourceLocation Loc, DeclarationName Entity) { }
1601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief RAII object that temporarily sets the base location and entity
162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// used for reporting diagnostics in types.
163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  class TemporaryBase {
164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TreeTransform &Self;
165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SourceLocation OldLocation;
166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclarationName OldEntity;
1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  public:
169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TemporaryBase(TreeTransform &Self, SourceLocation Location,
1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  DeclarationName Entity) : Self(Self) {
171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldLocation = Self.getDerived().getBaseLocation();
172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldEntity = Self.getDerived().getBaseEntity();
173ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor
174ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor      if (Location.isValid())
175ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor        Self.getDerived().setBase(Location, Entity);
176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ~TemporaryBase() {
179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Self.getDerived().setBase(OldLocation, OldEntity);
180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  };
1821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determine whether the given type \p T has already been
184577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// transformed.
185577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses can provide an alternative implementation of this routine
1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// to short-circuit evaluation when it is known that a given type will
188577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// not change. For example, template instantiation need not traverse
189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// non-dependent types.
190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlreadyTransformed(QualType T) {
191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T.isNull();
192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
1946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether the given call argument should be dropped, e.g.,
1956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// because it is a default argument.
1966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
1976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Subclasses can provide an alternative implementation of this routine to
1986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// determine which kinds of call arguments get dropped. By default,
1996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// CXXDefaultArgument nodes are dropped (prior to transformation).
2006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool DropCallArgument(Expr *E) {
2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return E->isDefaultArgument();
2026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
203c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Determine whether we should expand a pack expansion with the
2058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// given set of parameter packs into separate arguments by repeatedly
2068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// transforming the pattern.
2078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
208b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  /// By default, the transformer never tries to expand pack expansions.
2098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// Subclasses can override this routine to provide different behavior.
2108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param EllipsisLoc The location of the ellipsis that identifies the
2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pack expansion.
2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param PatternRange The source range that covers the entire pattern of
2158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// the pack expansion.
2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param Unexpanded The set of unexpanded parameter packs within the
2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pattern.
2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumUnexpanded The number of unexpanded parameter packs in
2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \p Unexpanded.
2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param ShouldExpand Will be set to \c true if the transformer should
2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// expand the corresponding pack expansions into separate arguments. When
2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// set, \c NumExpansions must also be set.
2268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
227d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \param RetainExpansion Whether the caller should add an unexpanded
228d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack expansion after all of the expanded arguments. This is used
229d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when extending explicitly-specified template argument packs per
230d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// C++0x [temp.arg.explicit]p9.
231d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
2328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumExpansions The number of separate arguments that will be in
233cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// the expanded form of the corresponding pack expansion. This is both an
234cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// input and an output parameter, which can be set by the caller if the
235cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// number of expansions is known a priori (e.g., due to a prior substitution)
236cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// and will be set by the callee when the number of expansions is known.
237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// The callee must set this value when \c ShouldExpand is \c true; it may
238cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// set this value in other cases.
2398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \returns true if an error occurred (e.g., because the parameter packs
2418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// are to be instantiated with arguments of different lengths), false
2428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// must be set.
2448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
2458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               SourceRange PatternRange,
2468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               const UnexpandedParameterPack *Unexpanded,
2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               unsigned NumUnexpanded,
2488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               bool &ShouldExpand,
249d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                               bool &RetainExpansion,
250cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                               llvm::Optional<unsigned> &NumExpansions) {
2518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    ShouldExpand = false;
2528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return false;
2538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
2548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
255d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Forget" about the partially-substituted pack template argument,
256d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when performing an instantiation that must preserve the parameter pack
257d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  TemplateArgument ForgetPartiallySubstitutedPack() {
261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    return TemplateArgument();
262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  }
263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Remember" the partially-substituted pack template argument
265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// after performing an instantiation that must preserve the parameter pack
266d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
27112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// \brief Note to the derived class when a function parameter pack is
27212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// being expanded.
27312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor
275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transforms the given type into another type.
276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by creating a
278a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// TypeSourceInfo for it and delegating to the appropriate
279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// function.  This is expensive, but we don't mind, because
280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// this method is deprecated anyway;  all users should be
281a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// switched to storing TypeSourceInfos.
282577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \returns the transformed type.
28443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(QualType T);
2851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transforms the given type-with-location into a new
287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type-with-location.
288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ///
289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by delegating to the
290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// appropriate TransformXXXType to build a new type.  Subclasses
291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// may override this function (to take over all type
292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// transformations) or some set of the TransformXXXType functions
293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// to alter the transformation.
29443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transform the given type-with-location into a new
297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type, collecting location information in the given builder
298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// as necessary.
299577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
30043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
3011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
302657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given statement.
303577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
3041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this routine transforms a statement by delegating to the
30543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// appropriate TransformXXXStmt function to transform a specific kind of
30643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// statement or the TransformExpr() function to transform an expression.
30743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to transform statements using some
30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// other mechanism.
30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \returns the transformed statement.
31160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformStmt(Stmt *S);
3121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
313657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given expression.
314657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  ///
315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine transforms an expression by delegating to the
316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// appropriate TransformXXXExpr function to build a new expression.
317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this function to transform expressions using some
318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// other mechanism.
319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \returns the transformed expression.
32160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformExpr(Expr *E);
3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
323aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Transform the given list of expressions.
324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// This routine transforms a list of expressions by invoking
326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \c TransformExpr() for each subexpression. However, it also provides
327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// support for variadic templates by expanding any pack expansions (if the
328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// derived class permits such expansion) along the way. When pack expansions
329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// are present, the number of outputs may not equal the number of inputs.
330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Inputs The set of expressions to be transformed.
332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param NumInputs The number of expressions in \c Inputs.
334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param IsCall If \c true, then this transform is being performed on
336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// function-call arguments, and any arguments that should be dropped, will
337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// be.
338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
339aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Outputs The transformed input expressions will be added to this
340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// vector.
341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// due to transformation.
344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \returns true if an error occurred, false otherwise.
346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                      llvm::SmallVectorImpl<Expr *> &Outputs,
348aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                      bool *ArgChanged = 0);
349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given declaration, which is referenced from a type
351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// or expression.
352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
353dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, acts as the identity function on declarations. Subclasses
354dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// may override this function to provide alternate behavior.
3557c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
35643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
35743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Transform the definition of the given declaration.
35843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, invokes TransformDecl() to transform the declaration.
36043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
361c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().TransformDecl(Loc, D);
3637c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  }
3641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3656cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// \brief Transform the given declaration, which was the first part of a
3666cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// nested-name-specifier in a member access expression.
3676cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
368c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// This specific declaration transformation only applies to the first
3696cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// identifier in a nested-name-specifier of a member access expression, e.g.,
3706cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// the \c T in \c x->T::member
3716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
3726cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// By default, invokes TransformDecl() to transform the declaration.
3736cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// Subclasses may override this function to provide alternate behavior.
374c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
3766cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  }
377c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given nested-name-specifier.
379577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, transforms all of the types and declarations within the
381dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this function to provide
382dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// alternate behavior.
383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
384a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                    SourceRange Range,
385c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                              QualType ObjectType = QualType(),
386c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                          NamedDecl *FirstQualifierInScope = 0);
3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// \brief Transform the given declaration name.
38981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  ///
39081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// By default, transforms the types of conversion function, constructor,
39181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// and destructor names and then (if needed) rebuilds the declaration name.
39281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// Identifiers and selectors are returned unmodified. Sublcasses may
39381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// override this function to provide alternate behavior.
3942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo
39543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
397577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template name.
3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
399d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, transforms the template name by transforming the declarations
4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// and nested-name-specifiers that occur within the template name.
401d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
4023b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  TemplateName TransformTemplateName(TemplateName Name,
40343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                     QualType ObjectType = QualType(),
40443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                     NamedDecl *FirstQualifierInScope = 0);
4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template argument.
407577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this operation transforms the type, expression, or
4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// declaration stored within the template argument and constructs a
410670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// new template argument from the transformed result. Subclasses may
411670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// override this function to provide alternate behavior.
412833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  ///
413833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// Returns true if there was an error.
414833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
415833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &Output);
416833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
417fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \brief Transform the given set of template arguments.
418fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
419fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// By default, this operation transforms all of the template arguments
420fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
421fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// the transformed arguments to the output list.
422fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
4237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// Note that this overload of \c TransformTemplateArguments() is merely
4247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// a convenience function. Subclasses that wish to override this behavior
4257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// should override the iterator-based member template version.
4267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
427fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Inputs The set of template arguments to be transformed.
428fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
429fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param NumInputs The number of template arguments in \p Inputs.
430fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
431fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Outputs The set of transformed template arguments output by this
432fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// routine.
433fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
434fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// Returns true if an error occurred.
435fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
436fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                  unsigned NumInputs,
4377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs) {
4387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
4397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
4407f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
4417f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \brief Transform the given set of template arguments.
4427f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4437f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// By default, this operation transforms all of the template arguments
4447f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
4457f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// the transformed arguments to the output list.
4467f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param First An iterator to the first template argument.
4487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
4497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param Last An iterator one step past the last template argument.
4507f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4517f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \param Outputs The set of transformed template arguments output by this
4527f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// routine.
4537f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4547f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// Returns true if an error occurred.
4557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename InputIterator>
4567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  bool TransformTemplateArguments(InputIterator First,
4577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  InputIterator Last,
4587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs);
4597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
460833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
461833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
462833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &ArgLoc);
463833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
464a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// \brief Fakes up a TypeSourceInfo for a type.
465a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *InventTypeSourceInfo(QualType T) {
466a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return SemaRef.Context.getTrivialTypeSourceInfo(T,
467833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                       getDerived().getBaseLocation());
468833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT)                                   \
47243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
473a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
474577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
47543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
47643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
47743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateSpecializationTypeLoc TL,
47843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateName Template);
47943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
48043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
48143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
48243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentTemplateSpecializationTypeLoc TL,
48343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               NestedNameSpecifier *Prefix);
48443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
48521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms the parameters of a function type into the
48621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// given vectors.
48721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
48821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// The result vectors should be kept in sync; null entries in the
48921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// variables vector are acceptable.
49021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
49121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// Return true on error.
492a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  bool TransformFunctionTypeParams(SourceLocation Loc,
493a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   ParmVarDecl **Params, unsigned NumParams,
494a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   const QualType *ParamTypes,
49521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                                   llvm::SmallVectorImpl<QualType> &PTypes,
496a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
49721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
49821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms a single function-type parameter.  Return null
49921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// on error.
5006a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
5016a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                        llvm::Optional<unsigned> NumExpansions);
50221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
50343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
504833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
50560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
50660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
5071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                        \
50960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Transform##Node(Node *S);
510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                        \
51160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Transform##Node(Node *E);
5127381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
5134bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
5141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
515577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new pointer type given its pointee type.
516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
517577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the pointer type.
518577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
51985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
520577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new block pointer type given its pointee type.
522577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis when building the block pointer
524577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
52585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
526577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
52785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \brief Build a new reference type given the type it references.
528577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
52985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// By default, performs semantic analysis when building the
53085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// reference type. Subclasses may override this routine to provide
53185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// different behavior.
532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
53385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \param LValue whether the type was written with an lvalue sigil
53485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// or an rvalue sigil.
53585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildReferenceType(QualType ReferentType,
53685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                bool LValue,
53785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                SourceLocation Sigil);
5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
539577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new member pointer type given the pointee type and the
540577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// class type it refers into.
541577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
542577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the member pointer
543577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
54485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
54585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceLocation Sigil);
5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new array type given the element type, size
548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, size of the array (if known), size expression, and index type
549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// qualifiers.
550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
551577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Also by default, all of the other Rebuild*Array
554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildArrayType(QualType ElementType,
555577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            ArrayType::ArraySizeModifier SizeMod,
556577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            const llvm::APInt *Size,
557577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            Expr *SizeExpr,
558577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            unsigned IndexTypeQuals,
559577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            SourceRange BracketsRange);
5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
561577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new constant array type given the element type, size
562577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, (known) size of the array, and index type qualifiers.
563577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
565577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildConstantArrayType(QualType ElementType,
567577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
568577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    const llvm::APInt &Size,
56985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    unsigned IndexTypeQuals,
57085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceRange BracketsRange);
571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new incomplete array type given the element type, size
573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, and index type qualifiers.
574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
576577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildIncompleteArrayType(QualType ElementType,
578577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                      ArrayType::ArraySizeModifier SizeMod,
57985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      unsigned IndexTypeQuals,
58085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      SourceRange BracketsRange);
581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
5821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new variable-length array type given the element type,
583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildVariableArrayType(QualType ElementType,
588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
5899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SizeExpr,
590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned IndexTypeQuals,
591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    SourceRange BracketsRange);
592577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new dependent-sized array type given the element type,
594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
596577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedArrayType(QualType ElementType,
599577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
6009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *SizeExpr,
601577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          unsigned IndexTypeQuals,
602577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          SourceRange BracketsRange);
603577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new vector type given the element type and
605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
60982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
610e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                             VectorType::VectorKind VecKind);
6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new extended vector type given the element type and
613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
614577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                SourceLocation AttributeLoc);
6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new potentially dependently-sized extended vector type
621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// given the element type and number of elements.
622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
6269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *SizeExpr,
627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                              SourceLocation AttributeLoc);
6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new function type.
630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the function type.
632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildFunctionProtoType(QualType T,
6341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    QualType *ParamTypes,
635577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned NumParamTypes,
636fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    bool Variadic, unsigned Quals,
637c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                    RefQualifierKind RefQualifier,
638fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    const FunctionType::ExtInfo &Info);
6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
640a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Build a new unprototyped function type.
641a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType RebuildFunctionNoProtoType(QualType ResultType);
642a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
643ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// \brief Rebuild an unresolved typename type, given the decl that
644ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// the UnresolvedUsingTypenameDecl was transformed to.
645ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType RebuildUnresolvedUsingType(Decl *D);
646ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typedef type.
648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypedefType(TypedefDecl *Typedef) {
649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Typedef);
650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
651577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
652577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new class/struct/union type.
653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildRecordType(RecordDecl *Record) {
654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Record);
655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new Enum type.
658577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildEnumType(EnumDecl *Enum) {
659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Enum);
660577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
6617da2431c23ef1ee8acb114e39692246e1801afc2John McCall
6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(expr) type.
663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typeof type.
665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6662a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(type) type.
669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
670577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, builds a new TypeOfType with the given underlying type.
671577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypeOfType(QualType Underlying);
672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++0x decltype type.
674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the decltype type.
676577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6772a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
6781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67934b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Build a new C++0x auto type.
68034b41d939a1328f484511c6002ba2456db879a29Richard Smith  ///
68134b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// By default, builds a new AutoType with the given deduced type.
68234b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType RebuildAutoType(QualType Deduced) {
68334b41d939a1328f484511c6002ba2456db879a29Richard Smith    return SemaRef.Context.getAutoType(Deduced);
68434b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
68534b41d939a1328f484511c6002ba2456db879a29Richard Smith
686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new template specialization type.
687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the template
689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// specialization type. Subclasses may override this routine to provide
690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTemplateSpecializationType(TemplateName Template,
692833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateLoc,
693d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                       const TemplateArgumentListInfo &Args);
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
695075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// \brief Build a new parenthesized type.
696075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ///
697075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// By default, builds a new ParenType type from the inner type.
698075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
699075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType RebuildParenType(QualType InnerType) {
700075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return SemaRef.Context.getParenType(InnerType);
701075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
702075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new qualified name type.
704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
705465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// By default, builds a new ElaboratedType type from the keyword,
706465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// the nested-name-specifier and the named type.
707465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
70821e413fe6305a198564d436ac515497716c47844John McCall  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
70921e413fe6305a198564d436ac515497716c47844John McCall                                 ElaboratedTypeKeyword Keyword,
710465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                                 NestedNameSpecifier *NNS, QualType Named) {
711465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
714577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to a template-id.
715577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
716e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// By default, builds a new DependentNameType type from the
717e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// nested-name-specifier and the given type. Subclasses may override
718e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// this routine to provide different behavior.
71933500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType RebuildDependentTemplateSpecializationType(
72033500955d731c73717af52088b7fc0e7a85681e7John McCall                                    ElaboratedTypeKeyword Keyword,
7211efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                    NestedNameSpecifier *Qualifier,
7221efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                    SourceRange QualifierRange,
72333500955d731c73717af52088b7fc0e7a85681e7John McCall                                    const IdentifierInfo *Name,
72433500955d731c73717af52088b7fc0e7a85681e7John McCall                                    SourceLocation NameLoc,
72533500955d731c73717af52088b7fc0e7a85681e7John McCall                                    const TemplateArgumentListInfo &Args) {
72633500955d731c73717af52088b7fc0e7a85681e7John McCall    // Rebuild the template name.
72733500955d731c73717af52088b7fc0e7a85681e7John McCall    // TODO: avoid TemplateName abstraction
72833500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateName InstName =
7291efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
73043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                       QualType(), 0);
73133500955d731c73717af52088b7fc0e7a85681e7John McCall
73296fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor    if (InstName.isNull())
73396fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor      return QualType();
73496fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor
73533500955d731c73717af52088b7fc0e7a85681e7John McCall    // If it's still dependent, make a dependent specialization.
73633500955d731c73717af52088b7fc0e7a85681e7John McCall    if (InstName.getAsDependentTemplateName())
73733500955d731c73717af52088b7fc0e7a85681e7John McCall      return SemaRef.Context.getDependentTemplateSpecializationType(
7381efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                          Keyword, Qualifier, Name, Args);
73933500955d731c73717af52088b7fc0e7a85681e7John McCall
74033500955d731c73717af52088b7fc0e7a85681e7John McCall    // Otherwise, make an elaborated type wrapping a non-dependent
74133500955d731c73717af52088b7fc0e7a85681e7John McCall    // specialization.
74233500955d731c73717af52088b7fc0e7a85681e7John McCall    QualType T =
74333500955d731c73717af52088b7fc0e7a85681e7John McCall      getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
74433500955d731c73717af52088b7fc0e7a85681e7John McCall    if (T.isNull()) return QualType();
745465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
74622f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara    // NOTE: NNS is already recorded in template specialization type T.
74722f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
749577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
750577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to an identifier.
751577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
752577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typename type
753e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// (or elaborated type). Subclasses may override this routine to provide
754577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
755e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
7564a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                                    NestedNameSpecifier *NNS,
7574a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                                    const IdentifierInfo *Id,
758e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation KeywordLoc,
759e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceRange NNSRange,
760e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation IdLoc) {
7614033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    CXXScopeSpec SS;
7624033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SS.setScopeRep(NNS);
763e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    SS.setRange(NNSRange);
764e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
7654033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (NNS->isDependent()) {
7664033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      // If the name is still dependent, just build a new dependent name type.
7674033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      if (!SemaRef.computeDeclContext(SS))
7684033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
7694033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
7704033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
771465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (Keyword == ETK_None || Keyword == ETK_Typename)
772e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
773e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                       KeywordLoc, NNSRange, IdLoc);
774465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
775465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
776465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
777e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    // We had a dependent elaborated-type-specifier that has been transformed
7784033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // into a non-dependent elaborated-type-specifier. Find the tag we're
7794033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // referring to.
780e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
7814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    DeclContext *DC = SemaRef.computeDeclContext(SS, false);
7824033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!DC)
7834033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
7844033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
7855613876991c80a684595fe8de1f039296a0657ffJohn McCall    if (SemaRef.RequireCompleteDeclContext(SS, DC))
7865613876991c80a684595fe8de1f039296a0657ffJohn McCall      return QualType();
7875613876991c80a684595fe8de1f039296a0657ffJohn McCall
7884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    TagDecl *Tag = 0;
7894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SemaRef.LookupQualifiedName(Result, DC);
7904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    switch (Result.getResultKind()) {
7914033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFound:
7924033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFoundInCurrentInstantiation:
7934033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
794c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7954033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Found:
7964033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        Tag = Result.getAsSingle<TagDecl>();
7974033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
798c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7994033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundOverloaded:
8004033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundUnresolvedValue:
8014033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        llvm_unreachable("Tag lookup cannot find non-tags");
8024033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
803c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8044033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Ambiguous:
8054033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        // Let the LookupResult structure handle ambiguities.
8064033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
8074033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8084033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8094033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!Tag) {
810446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // Check where the name exists but isn't a tag type and use that to emit
811446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // better diagnostics.
812446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
813446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      SemaRef.LookupQualifiedName(Result, DC);
814446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      switch (Result.getResultKind()) {
815446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::Found:
816446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundOverloaded:
817446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundUnresolvedValue: {
818446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky	  NamedDecl *SomeDecl = Result.getRepresentativeDecl();
819446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          unsigned Kind = 0;
820446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
821446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
822446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
823446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
824446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
825446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky	}
826446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        default:
827446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          // FIXME: Would be nice to highlight just the source range.
828446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
829446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky            << Kind << Id << DC;
830446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
831446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      }
8324033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8334033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
834465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
835e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
836e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
8374033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
8384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8404033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // Build the elaborated-type-specifier type.
8424033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    QualType T = SemaRef.Context.getTypeDeclType(Tag);
843465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
844dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8462fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// \brief Build a new pack expansion type.
8472fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  ///
8482fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// By default, builds a new PackExpansionType type from the given pattern.
8492fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
8502fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType RebuildPackExpansionType(QualType Pattern,
8512fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                    SourceRange PatternRange,
852cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    SourceLocation EllipsisLoc,
853cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    llvm::Optional<unsigned> NumExpansions) {
854cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
855cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                        NumExpansions);
8562fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
8572fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
858dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and an
859dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// identifier that names the next step in the nested-name-specifier.
860dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
861dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
862dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
863dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
864dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
865dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
866a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                  IdentifierInfo &II,
867c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                  QualType ObjectType,
868c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                              NamedDecl *FirstQualifierInScope);
869dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
870dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and the
871dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// namespace named in the next step in the nested-name-specifier.
872dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
873dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
874dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
875dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
876dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
877dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
878dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  NamespaceDecl *NS);
879dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
880dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and the
881dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// type named in the next step in the nested-name-specifier.
882dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
883dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
884dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
885dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
886dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
887dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
888dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  bool TemplateKW,
889edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  QualType T);
890d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
891d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier, a flag
892d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// indicating whether the "template" keyword was provided, and the template
893d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// that the template name refers to.
894d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
895d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, builds the new template name directly. Subclasses may override
896d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// this routine to provide different behavior.
897d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
898d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   bool TemplateKW,
899d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   TemplateDecl *Template);
900d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
901d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier and the
902d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// name that is referred to as a template.
903d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
904d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
905d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
906d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// template name. Subclasses may override this routine to provide different
907d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// behavior.
908d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
9091efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                   SourceRange QualifierRange,
9103b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                   const IdentifierInfo &II,
91143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   QualType ObjectType,
91243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   NamedDecl *FirstQualifierInScope);
9131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
914ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// \brief Build a new template name given a nested name specifier and the
915ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// overloaded operator name that is referred to as a template.
916ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  ///
917ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// By default, performs semantic analysis to determine whether the name can
918ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
919ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// template name. Subclasses may override this routine to provide different
920ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// behavior.
921ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
922ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   OverloadedOperatorKind Operator,
923ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   QualType ObjectType);
9241aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
9251aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// \brief Build a new template name given a template template parameter pack
9261aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// and the
9271aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  ///
9281aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
9291aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
9301aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// template name. Subclasses may override this routine to provide different
9311aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// behavior.
9321aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
9331aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                   const TemplateArgument &ArgPack) {
9341aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
9351aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  }
9361aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
93743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new compound statement.
93843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
93943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
94043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
94160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
94243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       MultiStmtArg Statements,
94343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       SourceLocation RBraceLoc,
94443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       bool IsStmtExpr) {
9459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
94643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       IsStmtExpr);
94743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
94843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
94943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new case statement.
95043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
95143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
95243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
95360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
9549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *LHS,
95543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EllipsisLoc,
9569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *RHS,
95743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation ColonLoc) {
9589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
95943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   ColonLoc);
96043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to a new case statement.
96343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
96443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
96543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
96660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
9679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().ActOnCaseStmtBody(S, Body);
9689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return S;
96943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new default statement.
97243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
97343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
97443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
97560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
97643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      SourceLocation ColonLoc,
9779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      Stmt *SubStmt) {
9789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
97943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      /*CurScope=*/0);
98043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new label statement.
98343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
98443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
98543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
98657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
98757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                              SourceLocation ColonLoc, Stmt *SubStmt) {
98857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
98943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new "if" statement.
99243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
99343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
99560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
99657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                           VarDecl *CondVar, Stmt *Then,
99757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                           SourceLocation ElseLoc, Stmt *Else) {
99844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis    return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
99943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Start building a new switch statement.
100243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
100343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
100560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
100657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                    Expr *Cond, VarDecl *CondVar) {
10079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1008d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                            CondVar);
100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to the switch statement.
101243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
101343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
101443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
101560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
101657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                   Stmt *Switch, Stmt *Body) {
10179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
101843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
101943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
102043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new while statement.
102143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
102243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
102343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
102457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
102557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                              VarDecl *CondVar, Stmt *Body) {
10269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new do-while statement.
103043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
103143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
103360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1034ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                           SourceLocation WhileLoc, SourceLocation LParenLoc,
1035ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                           Expr *Cond, SourceLocation RParenLoc) {
10369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
10379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Cond, RParenLoc);
103843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
103943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
104043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new for statement.
104143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
104243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
104343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1044ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1045ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            Stmt *Init, Sema::FullExprArg Cond,
1046ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            VarDecl *CondVar, Sema::FullExprArg Inc,
1047ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            SourceLocation RParenLoc, Stmt *Body) {
10489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1049ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                  CondVar, Inc, RParenLoc, Body);
105043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
105243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new goto statement.
105343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
105443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
105543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1056ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1057ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                             LabelDecl *Label) {
105857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
105943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
106043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
106143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new indirect goto statement.
106243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
106343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
106443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
106560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1066ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                     SourceLocation StarLoc,
1067ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                     Expr *Target) {
10689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
106943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new return statement.
107243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
107343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
107443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1075ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
10769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnReturnStmt(ReturnLoc, Result);
107743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new declaration statement.
108043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
108143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
108243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
108360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   SourceLocation StartLoc,
108543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EndLoc) {
108643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return getSema().Owned(
108743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor             new (getSema().Context) DeclStmt(
108843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                        DeclGroupRef::Create(getSema().Context,
108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                             Decls, NumDecls),
109043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              StartLoc, EndLoc));
109143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1093703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// \brief Build a new inline asm statement.
1094703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  ///
1095703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// By default, performs semantic analysis to build the new statement.
1096703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// Subclasses may override this routine to provide different behavior.
109760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
1098703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsSimple,
1099703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsVolatile,
1100703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumOutputs,
1101703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumInputs,
1102ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                  IdentifierInfo **Names,
1103703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Constraints,
1104703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Exprs,
11059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Expr *AsmString,
1106703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Clobbers,
1107703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  SourceLocation RParenLoc,
1108703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool MSAsm) {
1109c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1110703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  NumInputs, Names, move(Constraints),
11119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Exprs, AsmString, Clobbers,
1112703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  RParenLoc, MSAsm);
1113703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
11144dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
11154dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @try statement.
11164dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11174dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11184dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
111960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
11209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *TryBody,
11218f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                        MultiStmtArg CatchStmts,
11229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *Finally) {
11239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
11249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Finally);
11254dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
11264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
1127be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Rebuild an Objective-C exception declaration.
1128be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1129be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new declaration.
1130be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1131be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1132be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                    TypeSourceInfo *TInfo, QualType T) {
1133c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildObjCExceptionDecl(TInfo, T,
1134c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                            ExceptionDecl->getIdentifier(),
1135be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                            ExceptionDecl->getLocation());
1136be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
1137c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1138be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Build a new Objective-C @catch statement.
1139be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1140be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1141be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
114260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1143be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          SourceLocation RParenLoc,
1144be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          VarDecl *Var,
11459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Stmt *Body) {
1146be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
11479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Var, Body);
1148be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
1149c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11504dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @finally statement.
11514dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11524dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11534dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
115460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
11559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Stmt *Body) {
11569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
11574dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
1158c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11598fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @throw statement.
1160d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  ///
1161d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
1162d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
116360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
11649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Operand) {
11659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1166d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
1167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11688fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @synchronized statement.
11698fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  ///
11708fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
11718fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
117260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
11739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *Object,
11749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Stmt *Body) {
11759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
11769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Body);
11778fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  }
1178c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor
1179c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// \brief Build a new Objective-C fast enumeration statement.
1180c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  ///
1181c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1182c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
118360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1184f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation LParenLoc,
1185f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Element,
1186f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Expr *Collection,
1187f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation RParenLoc,
1188f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Body) {
1189c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor    return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
11909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Element,
11919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Collection,
1192c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                RParenLoc,
11939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Body);
1194c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  }
1195c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
119643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ exception declaration.
119743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
119843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new decaration.
119943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
120083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1201a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                                TypeSourceInfo *Declarator,
120243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                IdentifierInfo *Name,
120383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                SourceLocation Loc) {
120483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
120543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
120643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
120743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ catch statement.
120843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
120943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
121043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
121160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 VarDecl *ExceptionDecl,
1213f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 Stmt *Handler) {
12149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
12159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Handler));
121643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
121843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ try statement.
121943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
122043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
122143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
122260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1223f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               Stmt *TryBlock,
1224f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               MultiStmtArg Handlers) {
12259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
122643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression that references a declaration.
1229b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1230b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1231b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
123260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        LookupResult &R,
1234f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        bool RequiresADL) {
1235f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1236f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1237f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1238f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1239f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Build a new expression that references a declaration.
1240f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  ///
1241f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// By default, performs semantic analysis to build the new expression.
1242f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Subclasses may override this routine to provide different behavior.
124360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1244f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                SourceRange QualifierRange,
1245f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                ValueDecl *VD,
1246f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                const DeclarationNameInfo &NameInfo,
1247f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                TemplateArgumentListInfo *TemplateArgs) {
1248a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    CXXScopeSpec SS;
1249a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    SS.setScopeRep(Qualifier);
1250a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    SS.setRange(QualifierRange);
1251dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
1252dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: loses template args.
12532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
12542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1255b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1257b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression in parentheses.
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
126160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                    SourceLocation RParen) {
12639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1264b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1266a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Build a new pseudo-destructor expression.
12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1268a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1269a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
127060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1271a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                  SourceLocation OperatorLoc,
1272a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                  bool isArrow,
1273a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                NestedNameSpecifier *Qualifier,
127426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  SourceRange QualifierRange,
127526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  TypeSourceInfo *ScopeType,
127626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  SourceLocation CCLoc,
1277fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                  SourceLocation TildeLoc,
1278a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed);
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary operator expression.
12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
128460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
12852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                        UnaryOperatorKind Opc,
12869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *SubExpr) {
12879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build a new builtin offsetof expression.
12918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
12928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
12938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
129460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
12958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       TypeSourceInfo *Type,
1296f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                       Sema::OffsetOfComponent *Components,
12978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       unsigned NumComponents,
12988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       SourceLocation RParenLoc) {
12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
13008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          NumComponents, RParenLoc);
13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new sizeof or alignof expression with a type argument.
13041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
130760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
13085ab75172051a6d2ea71a80a79e81c65519fd3462John McCall                                        SourceLocation OpLoc,
1309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool isSizeOf, SourceRange R) {
1310a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
1311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new sizeof or alignof expression with an expression
1314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument.
13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
131860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
1319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool isSizeOf, SourceRange R) {
132060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
13219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
1322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1323f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new array subscript expression.
13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
133260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LBracketLoc,
13349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *RHS,
1335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RBracketLoc) {
13369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
13379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             LBracketLoc, RHS,
1338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             RBracketLoc);
1339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new call expression.
13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
134560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Args,
1347e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   SourceLocation RParenLoc,
1348e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   Expr *ExecConfig = 0) {
13499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1350e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   move(Args), RParenLoc, ExecConfig);
1351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member access expression.
13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
135760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1358f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               bool isArrow,
1359f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NestedNameSpecifier *Qualifier,
1360f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               SourceRange QualifierRange,
1361f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               const DeclarationNameInfo &MemberNameInfo,
1362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               ValueDecl *Member,
1363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FoundDecl,
1364d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                        const TemplateArgumentListInfo *ExplicitTemplateArgs,
1365f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FirstQualifierInScope) {
1366d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    if (!Member->getDeclName()) {
1367f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // We have a reference to an unnamed field.  This is always the
1368f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // base of an anonymous struct/union member access, i.e. the
1369f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // field is always of record type.
1370d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
1371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      assert(Member->getType()->isRecordType() &&
1372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             "unnamed member not of record type?");
13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      if (getSema().PerformObjectMemberConversion(Base, Qualifier,
13756bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                                  FoundDecl, Member))
1376f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
13778aa5f407d9e4787ff08bd66e1a2fe39be174fddcDouglas Gregor
1378f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
13791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      MemberExpr *ME =
13809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        new (getSema().Context) MemberExpr(Base, isArrow,
13812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           Member, MemberNameInfo,
1382f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           cast<FieldDecl>(Member)->getType(),
1383f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           VK, OK_Ordinary);
1384d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      return getSema().Owned(ME);
1385d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    }
13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
138783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    CXXScopeSpec SS;
138883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    if (Qualifier) {
138983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      SS.setRange(QualifierRange);
139083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      SS.setScopeRep(Qualifier);
139183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    }
139283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
13939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().DefaultFunctionArrayConversion(Base);
13949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    QualType BaseType = Base->getType();
1395aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
13966bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // FIXME: this involves duplicating earlier analysis in a lot of
13976bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // cases; we should avoid this when possible.
13982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
13996bb8017bb9e828d118e15e59d71c66bba323c364John McCall    R.addDecl(FoundDecl);
1400c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    R.resolveKind();
1401c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
14029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1403129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, FirstQualifierInScope,
1404c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                              R, ExplicitTemplateArgs);
1405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new binary operator expression.
14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
141160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
14122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                         BinaryOperatorKind Opc,
14139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *LHS, Expr *RHS) {
14149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new conditional operator expression.
14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
142160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildConditionalOperator(Expr *Cond,
142256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        SourceLocation QuestionLoc,
142356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        Expr *LHS,
142456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        SourceLocation ColonLoc,
142556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        Expr *RHS) {
14269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
14279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        LHS, RHS);
1428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C-style cast expression.
14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
143460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
14359d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                         TypeSourceInfo *TInfo,
1436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc,
14379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *SubExpr) {
1438b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall    return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
14399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubExpr);
1440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new compound literal expression.
14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
144660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
144742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall                                              TypeSourceInfo *TInfo,
1448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation RParenLoc,
14499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Init) {
145042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
14519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Init);
1452b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new extended vector element access expression.
14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
145860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildExtVectorElementExpr(Expr *Base,
1459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation OpLoc,
1460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation AccessorLoc,
1461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               IdentifierInfo &Accessor) {
1462aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
1463129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    CXXScopeSpec SS;
14642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
14659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1466129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              OpLoc, /*IsArrow*/ false,
1467129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, /*FirstQualifierInScope*/ 0,
14682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                              NameInfo,
1469129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              /* TemplateArgs */ 0);
1470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new initializer list expression.
14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
147660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildInitList(SourceLocation LBraceLoc,
1477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Inits,
1478e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   SourceLocation RBraceLoc,
1479e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   QualType ResultTy) {
148060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1481e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1482e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    if (Result.isInvalid() || ResultTy->isDependentType())
1483e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      return move(Result);
1484c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1485e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // Patch in the result type we were given, which may have been computed
1486e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // when the initial InitListExpr was built.
1487e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1488e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    ILE->setType(ResultTy);
1489e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    return move(Result);
1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new designated initializer expression.
14931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
149660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             MultiExprArg ArrayExprs,
1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation EqualOrColonLoc,
1499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             bool GNUSyntax,
15009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *Init) {
150160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
15039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Init);
1504b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1505f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
15061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.release();
1508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new value-initialized expression.
15121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds the implicit value initialization without performing
1514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// any semantic analysis. Subclasses may override this routine to provide
1515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
151660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildImplicitValueInitExpr(QualType T) {
1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new \c va_arg expression.
15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
152460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
15259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SubExpr, TypeSourceInfo *TInfo,
15262cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    SourceLocation RParenLoc) {
15272cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara    return getSema().BuildVAArgExpr(BuiltinLoc,
15289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    SubExpr, TInfo,
15292cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    RParenLoc);
1530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression list in parentheses.
15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
153660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        MultiExprArg SubExprs,
1538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1539c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1540f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian                                               move(SubExprs));
1541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new address-of-label expression.
15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
15451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis, using the name of the label
1546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// rather than attempting to map the label statement itself.
1547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
154860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1549ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                  SourceLocation LabelLoc, LabelDecl *Label) {
155057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
1551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new GNU statement expression.
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
155760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
15589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Stmt *SubStmt,
1559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
15609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new __builtin_choose_expr expression.
1564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
156760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
15689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Cond, Expr *LHS, Expr *RHS,
1569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                     SourceLocation RParenLoc) {
1570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.ActOnChooseExpr(BuiltinLoc,
15719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Cond, LHS, RHS,
1572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   RParenLoc);
1573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new overloaded operator call expression.
1576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// The semantic analysis provides the behavior of template instantiation,
1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// copying with transformations that turn what looks like an overloaded
15801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// operator call into a use of a builtin operator, performing
1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument-dependent lookup, etc. Subclasses may override this routine to
1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
158360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation OpLoc,
15859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Callee,
15869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *First,
15879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Second);
15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++ "named" cast expression, such as static_cast or
1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// reinterpret_cast.
1591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine dispatches to one of the more-specific routines
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
159560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           Stmt::StmtClass Class,
1597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
15989d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
16019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    switch (Class) {
1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXStaticCastExprClass:
16059d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
16079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
1608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXDynamicCastExprClass:
16109d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                    RAngleLoc, LParenLoc,
16129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    SubExpr, RParenLoc);
16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXReinterpretCastExprClass:
16159d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                        RAngleLoc, LParenLoc,
16179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                        SubExpr,
1618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        RParenLoc);
16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXConstCastExprClass:
16219d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
16239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    default:
1626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      assert(false && "Invalid C++ named cast");
1627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      break;
1628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1630f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
1631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ static_cast expression.
1634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1636b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
163760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LAngleLoc,
16399d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                            TypeSourceInfo *TInfo,
1640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RAngleLoc,
1641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LParenLoc,
16429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Expr *SubExpr,
1643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RParenLoc) {
1644c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
16459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1646c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1647c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ dynamic_cast expression.
1651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
165460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LAngleLoc,
16569d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                             TypeSourceInfo *TInfo,
1657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RAngleLoc,
1658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LParenLoc,
16599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *SubExpr,
1660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RParenLoc) {
1661c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
16629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1663c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1664c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ reinterpret_cast expression.
1668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
167160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LAngleLoc,
16739d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                                 TypeSourceInfo *TInfo,
1674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RAngleLoc,
1675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LParenLoc,
16769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SubExpr,
1677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RParenLoc) {
1678c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
16799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1680c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1681c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ const_cast expression.
1685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
168860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
16909d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
16939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1695c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
16969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1697c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1698c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ functional-style cast expression.
1702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1705ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1706ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation LParenLoc,
1707ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          Expr *Sub,
1708ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation RParenLoc) {
1709ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1710f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                               MultiExprArg(&Sub, 1),
1711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(type) expression.
1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
171860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
171957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
172057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        TypeSourceInfo *Operand,
1721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1722c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
172357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
1724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
172601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(expr) expression.
1728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
173160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
173257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
17339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand,
1734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
17359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
173657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
17371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
17381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
173901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(type) expression.
174001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
174101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
174201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
174301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
174401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
174501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        TypeSourceInfo *Operand,
174601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
174701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
174801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
174901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
175001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
175101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(expr) expression.
175201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
175301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
175401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
175501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
175601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
175701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        Expr *Operand,
175801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
175901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
176001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
176101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
176201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "this" expression.
1764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new "this" expression without performing any
17661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// semantic analysis. Subclasses may override this routine to provide
1767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
176860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1769ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                QualType ThisType,
1770ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                bool isImplicit) {
1771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().Owned(
1772828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                      new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1773828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                                                          isImplicit));
1774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ throw expression.
1777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
178060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
17819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXThrow(ThrowLoc, Sub);
1782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ default-argument expression.
1785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new default-argument expression, which does not
1787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// require any semantic analysis. Subclasses may override this routine to
1788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
178960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1790036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                            ParmVarDecl *Param) {
1791036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1792036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                                     Param));
1793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ zero-initialization expression.
1796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1799ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1800ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1801ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1802ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
18031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                               MultiExprArg(getSema(), 0, 0),
1804ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               RParenLoc);
1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "new" expression.
1808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
181160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
18121bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               bool UseGlobal,
18131bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementLParen,
18141bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg PlacementArgs,
18151bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementRParen,
18161bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceRange TypeIdParens,
18171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               QualType AllocatedType,
18181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               TypeSourceInfo *AllocatedTypeInfo,
18191bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               Expr *ArraySize,
18201bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorLParen,
18211bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg ConstructorArgs,
18221bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorRParen) {
18231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getSema().BuildCXXNew(StartLoc, UseGlobal,
1824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementLParen,
1825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(PlacementArgs),
1826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementRParen,
18274bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                 TypeIdParens,
18281bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedType,
18291bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedTypeInfo,
18309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 ArraySize,
1831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorLParen,
1832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(ConstructorArgs),
1833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorRParen);
1834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "delete" expression.
1837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
184060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsGlobalDelete,
1842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsArrayForm,
18439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand) {
1844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
18459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Operand);
1846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary type trait expression.
1849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
185260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
18533d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation StartLoc,
18543d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   TypeSourceInfo *T,
18553d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation RParenLoc) {
18563d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor    return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
1857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
18596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// \brief Build a new binary type trait expression.
18606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ///
18616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// By default, performs semantic analysis to build the new expression.
18626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Subclasses may override this routine to provide different behavior.
18636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
18646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation StartLoc,
18656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *LhsT,
18666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *RhsT,
18676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation RParenLoc) {
18686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
18696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
18706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
18711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new (previously unresolved) declaration reference
1872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// expression.
1873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
187660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
1877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                SourceRange QualifierRange,
18782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                       const DeclarationNameInfo &NameInfo,
1879f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1880b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
1881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SS.setRange(QualifierRange);
1882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SS.setScopeRep(NNS);
1883f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1884f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (TemplateArgs)
18852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
1886f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                    *TemplateArgs);
1887f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
18882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
1889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new template-id expression.
1892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
189560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1896f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         LookupResult &R,
1897f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         bool RequiresADL,
1898d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                              const TemplateArgumentListInfo &TemplateArgs) {
1899f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
1900b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
190660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstructExpr(QualType T,
19074411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                           SourceLocation Loc,
1908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           CXXConstructorDecl *Constructor,
1909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           bool IsElidable,
19108c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           MultiExprArg Args,
19118c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           bool RequiresZeroInit,
1912428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                             CXXConstructExpr::ConstructionKind ConstructKind,
1913428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           SourceRange ParenRange) {
1914ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
1915c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
19164411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                          ConvertedArgs))
1917f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1918c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
19194411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor    return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
19208c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           move_arg(ConvertedArgs),
1921428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           RequiresZeroInit, ConstructKind,
1922428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           ParenRange);
1923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1924b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1929ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1930ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1931ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           MultiExprArg Args,
1932ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1933ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
1934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
1935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
1936b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1943ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1944ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation LParenLoc,
1945ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               MultiExprArg Args,
1946ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation RParenLoc) {
1947ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
1948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
1949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1953b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member reference expression.
1954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
195760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
1958aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  QualType BaseType,
1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  bool IsArrow,
1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  SourceLocation OperatorLoc,
1961a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                              NestedNameSpecifier *Qualifier,
1962a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                  SourceRange QualifierRange,
1963129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            NamedDecl *FirstQualifierInScope,
19642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                   const DeclarationNameInfo &MemberNameInfo,
1965129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
1967a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    SS.setRange(QualifierRange);
1968a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    SS.setScopeRep(Qualifier);
19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1971aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
1972129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            SS, FirstQualifierInScope,
19732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            MemberNameInfo,
19742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            TemplateArgs);
1975b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1977129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Build a new member reference expression.
19783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  ///
19793b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
19803b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
198160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
1982aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                               QualType BaseType,
1983129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceLocation OperatorLoc,
1984129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               bool IsArrow,
1985129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               NestedNameSpecifier *Qualifier,
1986129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceRange QualifierRange,
1987c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                               NamedDecl *FirstQualifierInScope,
1988129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               LookupResult &R,
1989129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                const TemplateArgumentListInfo *TemplateArgs) {
19903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    CXXScopeSpec SS;
19913b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    SS.setRange(QualifierRange);
19923b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    SS.setScopeRep(Qualifier);
19931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1995aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
1996c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            SS, FirstQualifierInScope,
1997c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            R, TemplateArgs);
19983b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
19991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20002e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// \brief Build a new noexcept expression.
20012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ///
20022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// By default, performs semantic analysis to build the new expression.
20032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// Subclasses may override this routine to provide different behavior.
20042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
20052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
20062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
20072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2008ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Build a new expression to compute the length of a parameter pack.
2009ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2010ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation PackLoc,
2011ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation RParenLoc,
2012ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   unsigned Length) {
2013ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2014ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                                OperatorLoc, Pack, PackLoc,
2015ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                                RParenLoc, Length);
2016ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2017ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new Objective-C @encode expression.
2019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
202260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
202381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                         TypeSourceInfo *EncodeTypeInfo,
2024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc) {
202581d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                           RParenLoc));
20271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
2028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
202992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C class message.
203060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
203192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2032f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                          SourceLocation SelectorLoc,
203392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
2034c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
203592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
203692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
203792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return SemaRef.BuildClassMessage(ReceiverTypeInfo,
203892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     ReceiverTypeInfo->getType(),
203992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     /*SuperLoc=*/SourceLocation(),
2040f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                     Sel, Method, LBracLoc, SelectorLoc,
2041f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                     RBracLoc, move(Args));
204292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
204392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
204492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C instance message.
204560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(Expr *Receiver,
204692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2047f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                          SourceLocation SelectorLoc,
204892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
2049c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
205092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
205192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
20529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildInstanceMessage(Receiver,
20539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Receiver->getType(),
205492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        /*SuperLoc=*/SourceLocation(),
2055f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                        Sel, Method, LBracLoc, SelectorLoc,
2056f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                        RBracLoc, move(Args));
205792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
205892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
2059f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C ivar reference expression.
2060f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2061f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2062f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
206360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2064f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          SourceLocation IvarLoc,
2065f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          bool IsArrow, bool IsFreeIvar) {
2066f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    // FIXME: We lose track of the IsFreeIvar bit.
2067f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
20689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
2069f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2070f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
207160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2072f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IvarLoc,
2073d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0,
2074ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall                                                         false);
2075f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.isInvalid())
2076f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2077c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2078f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
2079f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
2080c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
20819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2082c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IvarLoc, IsArrow, SS,
2083f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
2084c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2085f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2086f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2087e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor
2088e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// \brief Build a new Objective-C property reference expression.
2089e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  ///
2090e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2091e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
209260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2093e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              ObjCPropertyDecl *Property,
2094e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              SourceLocation PropertyLoc) {
2095e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    CXXScopeSpec SS;
20969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
2097e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2098e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                   Sema::LookupMemberName);
2099e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    bool IsArrow = false;
210060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2101e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                                         /*FIME:*/PropertyLoc,
2102d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2103e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.isInvalid())
2104f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2105c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2106e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.get())
2107e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      return move(Result);
2108c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
21099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2110c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/PropertyLoc, IsArrow,
2111c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              SS,
2112e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*FirstQualifierInScope=*/0,
2113c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2114e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*TemplateArgs=*/0);
2115e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  }
2116c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
211712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// \brief Build a new Objective-C property reference expression.
21189cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  ///
21199cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
212012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// Subclasses may override this routine to provide different behavior.
212112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
212212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Getter,
212312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Setter,
212412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        SourceLocation PropertyLoc) {
212512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // Since these expressions can only be value-dependent, we do not
212612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // need to perform semantic analysis again.
212712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return Owned(
212812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
212912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  VK_LValue, OK_ObjCProperty,
213012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  PropertyLoc, Base));
21319cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  }
21329cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor
2133f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C "isa" expression.
2134f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2135f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2136f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
213760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2138f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                      bool IsArrow) {
2139f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
21409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
2141f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2142f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
214360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2144f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IsaLoc,
2145d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2146f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.isInvalid())
2147f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2148c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2149f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
2150f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
2151c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
21529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
2153c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IsaLoc, IsArrow, SS,
2154f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
2155c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2156f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2157f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2158c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new shuffle vector expression.
2160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
216360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      MultiExprArg SubExprs,
2165f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      SourceLocation RParenLoc) {
2166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Find the declaration for __builtin_shufflevector
21671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const IdentifierInfo &Name
2168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.Context.Idents.get("__builtin_shufflevector");
2169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
21721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Build a reference to the __builtin_shufflevector builtin
2174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
21751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Expr *Callee
2176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2177f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                          VK_LValue, BuiltinLoc);
2178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SemaRef.UsualUnaryConversions(Callee);
21791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Build the CallExpr
2181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    unsigned NumSubExprs = SubExprs.size();
2182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Expr **Subs = (Expr **)SubExprs.release();
2183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       Subs, NumSubExprs,
21855291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor                                                   Builtin->getCallResultType(),
2186f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            Expr::getValueKindForType(Builtin->getResultType()),
2187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       RParenLoc);
218860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult OwnedCall(SemaRef.Owned(TheCall));
21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Type-check the __builtin_shufflevector expression.
219160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
2192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
2193f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    OwnedCall.release();
21961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return move(Result);
2197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
219843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
21998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Build a new template argument pack expansion.
22008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
22018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
22028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// for a template argument. Subclasses may override this routine to provide
22038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// different behavior.
22048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2205cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           SourceLocation EllipsisLoc,
2206cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
22078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    switch (Pattern.getArgument().getKind()) {
22087a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    case TemplateArgument::Expression: {
22097a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      ExprResult Result
221067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
221167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                       EllipsisLoc, NumExpansions);
22127a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      if (Result.isInvalid())
22137a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor        return TemplateArgumentLoc();
22147a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor
22157a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      return TemplateArgumentLoc(Result.get(), Result.get());
22167a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    }
2217dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
22188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Template:
2219a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor      return TemplateArgumentLoc(TemplateArgument(
2220a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                          Pattern.getArgument().getAsTemplate(),
22212be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor                                                  NumExpansions),
2222a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 Pattern.getTemplateQualifierRange(),
2223a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 Pattern.getTemplateNameLoc(),
2224a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 EllipsisLoc);
22258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
22268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Null:
22278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Integral:
22288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Declaration:
22298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Pack:
2230a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    case TemplateArgument::TemplateExpansion:
22318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm_unreachable("Pack expansion pattern has no parameter packs");
22328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
22338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Type:
22348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (TypeSourceInfo *Expansion
22358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor            = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2236cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           EllipsisLoc,
2237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           NumExpansions))
22388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
22398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                   Expansion);
22408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      break;
22418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
22428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
22438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return TemplateArgumentLoc();
22448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
22458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
2246dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// \brief Build a new expression pack expansion.
2247dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  ///
2248dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
2249dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// for an expression. Subclasses may override this routine to provide
2250dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// different behavior.
225167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
225267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                  llvm::Optional<unsigned> NumExpansions) {
225367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2254dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  }
2255dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
225643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate:
225743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformTypeInObjectScope(QualType T,
225843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      QualType ObjectType,
225943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      NamedDecl *FirstQualifierInScope,
226043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      NestedNameSpecifier *Prefix);
226143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
226243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
226343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             QualType ObjectType,
226443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             NamedDecl *FirstQualifierInScope,
226543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             NestedNameSpecifier *Prefix);
2266577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor};
2267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
226843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
226960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
227043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!S)
227143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return SemaRef.Owned(S);
22721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
227343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  switch (S->getStmtClass()) {
227443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::NoStmtClass: break;
22751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
227643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform individual statement nodes
227743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                                              \
227843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
227963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node)
228043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent)
22814bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
22821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
228343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform expressions by calling TransformExpr.
228443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)
22857381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
228643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class:
22874bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
228843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    {
228960d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
229043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      if (E.isInvalid())
2291f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
22921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
229443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    }
22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
22961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
229843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2301670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived>
230260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!E)
2304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(E);
2305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  switch (E->getStmtClass()) {
2307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::NoStmtClass: break;
2308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break;
23097381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
2310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                                              \
2311454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall    case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
23124bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
23131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
23141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
2316657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor}
2317657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor
2318657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived>
2319aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2320aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            unsigned NumInputs,
2321aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool IsCall,
2322aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                      llvm::SmallVectorImpl<Expr *> &Outputs,
2323aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool *ArgChanged) {
2324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  for (unsigned I = 0; I != NumInputs; ++I) {
2325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    // If requested, drop call arguments that need to be dropped.
2326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      if (ArgChanged)
2328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor        *ArgChanged = true;
2329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      break;
2331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    }
2332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2333dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2334dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      Expr *Pattern = Expansion->getPattern();
2335dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2336dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2337dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2338dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2339dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2340dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
2341dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // be expanded.
2342dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      bool Expand = true;
2343d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
234467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> OrigNumExpansions
234567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = Expansion->getNumExpansions();
234667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
2347dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2348dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Pattern->getSourceRange(),
2349dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Unexpanded.data(),
2350dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Unexpanded.size(),
2351d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand, RetainExpansion,
2352d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
2353dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        return true;
2354dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2355dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (!Expand) {
2356dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // The transform has determined that we should perform a simple
2357dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // transformation on the pack expansion, producing another pack
2358dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // expansion.
2359dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2360dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2361dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (OutPattern.isInvalid())
2362dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2363dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2364dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
236567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                Expansion->getEllipsisLoc(),
236667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                           NumExpansions);
2367dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2368dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2369dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2370dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (ArgChanged)
2371dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          *ArgChanged = true;
2372dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2373dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        continue;
2374dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2375dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2376dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // The transform has determined that we should perform an elementwise
2377dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // expansion of the pattern. Do so.
2378cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
2379dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2380dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().TransformExpr(Pattern);
2381dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2382dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2383dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
238477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.get()->containsUnexpandedParameterPack()) {
238567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor          Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
238667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                     OrigNumExpansions);
238777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.isInvalid())
238877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
238977d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
239077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
2391dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (ArgChanged)
2392dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          *ArgChanged = true;
2393dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2394dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2395dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2396dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      continue;
2397dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    }
2398dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2399aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2400aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.isInvalid())
2401aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return true;
2402aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2403aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.get() != Inputs[I] && ArgChanged)
2404aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      *ArgChanged = true;
2405aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2406aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    Outputs.push_back(Result.get());
2407aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
2408aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2409aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  return false;
2410aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor}
2411aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2412aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived>
2413dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
2414dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
2415a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     SourceRange Range,
2416c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                     QualType ObjectType,
2417c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                             NamedDecl *FirstQualifierInScope) {
241843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  NestedNameSpecifier *Prefix = NNS->getPrefix();
24191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
242043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the prefix of this nested name specifier.
2421dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  if (Prefix) {
24221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
2423c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                       ObjectType,
2424c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                       FirstQualifierInScope);
2425dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    if (!Prefix)
2426dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return 0;
2427dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
24281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2429dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  switch (NNS->getKind()) {
2430dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Identifier:
243143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (Prefix) {
243243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // The object type and qualifier-in-scope really apply to the
243343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // leftmost entity.
243443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      ObjectType = QualType();
243543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      FirstQualifierInScope = 0;
243643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
243743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
24381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert((Prefix || !ObjectType.isNull()) &&
2439a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor            "Identifier nested-name-specifier with no prefix or object type");
2440a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2441a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor        ObjectType.isNull())
2442dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2445a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                   *NNS->getAsIdentifier(),
2446c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   ObjectType,
2447c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   FirstQualifierInScope);
24481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2449dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Namespace: {
24501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NamespaceDecl *NS
2451dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      = cast_or_null<NamespaceDecl>(
24527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                    getDerived().TransformDecl(Range.getBegin(),
24537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       NNS->getAsNamespace()));
24541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (!getDerived().AlwaysRebuild() &&
2455dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        Prefix == NNS->getPrefix() &&
2456dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        NS == NNS->getAsNamespace())
2457dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
24581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2459dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2460dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
24611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2462dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Global:
2463dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    // There is no meaningful transformation that one could perform on the
2464dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    // global scope.
2465dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return NNS;
24661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2467dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::TypeSpecWithTemplate:
2468dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::TypeSpec: {
2469fbf2c945f8f8bbfe0459d45c03f9ff34bb445c81Douglas Gregor    TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
247043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
247143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            ObjectType,
247243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            FirstQualifierInScope,
247343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            Prefix);
2474d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (T.isNull())
2475d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return 0;
24761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2477dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
2478dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        Prefix == NNS->getPrefix() &&
2479dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        T == QualType(NNS->getAsType(), 0))
2480dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
24811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
24831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
2484edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                   T);
2485dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
2486dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
24871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2488dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  // Required to silence a GCC warning
24891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return 0;
2490dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
2491dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
2492dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
24932577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo
24942577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived>
249543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
24962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name = NameInfo.getName();
249781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  if (!Name)
24982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo();
249981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
250081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  switch (Name.getNameKind()) {
250181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::Identifier:
250281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCZeroArgSelector:
250381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCOneArgSelector:
250481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCMultiArgSelector:
250581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXOperatorName:
25063e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  case DeclarationName::CXXLiteralOperatorName:
250781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXUsingDirective:
25082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NameInfo;
25091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
251081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConstructorName:
251181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXDestructorName:
251281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConversionFunctionName: {
25132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *NewTInfo;
25142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CanQualType NewCanTy;
25152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
251643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewTInfo = getDerived().TransformType(OldTInfo);
251743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NewTInfo)
251843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall        return DeclarationNameInfo();
251943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
25202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
25212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    else {
25222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewTInfo = 0;
25232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
252443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      QualType NewT = getDerived().TransformType(Name.getCXXNameType());
25252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      if (NewT.isNull())
25262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        return DeclarationNameInfo();
25272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewCanTy = SemaRef.Context.getCanonicalType(NewT);
25282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
25291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationName NewName
25312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
25322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                           NewCanTy);
25332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NewNameInfo(NameInfo);
25342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setName(NewName);
25352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setNamedTypeInfo(NewTInfo);
25362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NewNameInfo;
253781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  }
25381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
25391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  assert(0 && "Unknown name kind.");
25412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return DeclarationNameInfo();
254281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor}
254381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
254481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived>
25451eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
25463b6afbb99a1c44b4076f8e15fb7311405941b306Douglas GregorTreeTransform<Derived>::TransformTemplateName(TemplateName Name,
254743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              QualType ObjectType,
254843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              NamedDecl *FirstQualifierInScope) {
25497c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  SourceLocation Loc = getDerived().getBaseLocation();
25507c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor
2551d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
25521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NestedNameSpecifier *NNS
2553d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
255443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  /*FIXME*/ SourceRange(Loc),
255543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  ObjectType,
255643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  FirstQualifierInScope);
2557d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!NNS)
2558d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return TemplateName();
25591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2560d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (TemplateDecl *Template = QTN->getTemplateDecl()) {
25611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      TemplateDecl *TransTemplate
25627c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor        = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2563d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      if (!TransTemplate)
2564d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        return TemplateName();
25651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2566d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      if (!getDerived().AlwaysRebuild() &&
2567d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor          NNS == QTN->getQualifier() &&
2568d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor          TransTemplate == Template)
2569d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        return Name;
25701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2571d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2572d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                              TransTemplate);
2573d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    }
25741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2575f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // These should be getting filtered out before they make it into the AST.
257643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    llvm_unreachable("overloaded template name survived to here");
2577d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
25781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2579d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
258043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    NestedNameSpecifier *NNS = DTN->getQualifier();
258143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (NNS) {
258243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NNS = getDerived().TransformNestedNameSpecifier(NNS,
258343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  /*FIXME:*/SourceRange(Loc),
258443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ObjectType,
258543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      FirstQualifierInScope);
258643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NNS) return TemplateName();
258743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
258843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // These apply to the scope specifier, not the template.
258943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      ObjectType = QualType();
259043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      FirstQualifierInScope = 0;
259143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
25921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2593d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2594dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor        NNS == DTN->getQualifier() &&
2595dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor        ObjectType.isNull())
2596d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return Name;
25971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25981efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    if (DTN->isIdentifier()) {
25991efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      // FIXME: Bad range
26001efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      SourceRange QualifierRange(getDerived().getBaseLocation());
26011efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      return getDerived().RebuildTemplateName(NNS, QualifierRange,
26021efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                              *DTN->getIdentifier(),
260343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              ObjectType,
260443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              FirstQualifierInScope);
26051efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    }
2606c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2607c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2608ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            ObjectType);
2609d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
26101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2611d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
26121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TemplateDecl *TransTemplate
26137c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2614d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!TransTemplate)
2615d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return TemplateName();
26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2617d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2618d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        TransTemplate == Template)
2619d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return Name;
26201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2621d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    return TemplateName(TransTemplate);
2622d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
26231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26241aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  if (SubstTemplateTemplateParmPackStorage *SubstPack
26251aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                 = Name.getAsSubstTemplateTemplateParmPack()) {
26261aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    TemplateTemplateParmDecl *TransParam
26271aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor      = cast_or_null<TemplateTemplateParmDecl>(
26281aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor               getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
26291aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    if (!TransParam)
26301aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor      return TemplateName();
26311aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
26321aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
26331aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor        TransParam == SubstPack->getParameterPack())
26341aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor      return Name;
26351aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
26361aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    return getDerived().RebuildTemplateName(TransParam,
26371aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                            SubstPack->getArgumentPack());
26381aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  }
26391aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
2640f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // These should be getting filtered out before they reach the AST.
264143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  llvm_unreachable("overloaded function decl survived to here");
2642f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return TemplateName();
2643d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
2644d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
2645d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
2646833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc(
2647833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgument &Arg,
2648833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2649833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation Loc = getDerived().getBaseLocation();
2650670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  switch (Arg.getKind()) {
2651670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Null:
26529f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("null template argument in TreeTransform");
2653833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2654833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2655833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
2656833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg,
2657a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall               SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2658c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2659833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2660833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2661788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
2662788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2663788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    break;
2664a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2665a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor  case TemplateArgument::TemplateExpansion:
2666a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2667a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    break;
2668a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2669833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
2670833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2671833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2672833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2673833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
2674670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Integral:
2675833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
2676828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2677833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2678833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
2679833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
2680833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2681833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived>
2682833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument(
2683833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgumentLoc &Input,
2684833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2685833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgument &Arg = Input.getArgument();
2686833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
2687833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
2688833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
2689833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = Input;
2690833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
26911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2692670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Type: {
2693a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *DI = Input.getTypeSourceInfo();
2694833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (DI == NULL)
2695a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall      DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2696833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2697833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    DI = getDerived().TransformType(DI);
2698833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!DI) return true;
2699833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2700833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2701833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2702670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
27031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2704670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Declaration: {
2705833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // FIXME: we should never have to transform one of these.
2706972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    DeclarationName Name;
2707972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2708972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor      Name = ND->getDeclName();
2709788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemporaryBase Rebase(*this, Input.getLocation(), Name);
27107c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2711833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!D) return true;
2712833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2713828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Expr *SourceExpr = Input.getSourceDeclExpression();
2714828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    if (SourceExpr) {
2715828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      EnterExpressionEvaluationContext Unevaluated(getSema(),
2716f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Sema::Unevaluated);
271760d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(SourceExpr);
27189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      SourceExpr = (E.isInvalid() ? 0 : E.take());
2719828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    }
2720828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
2721828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2722833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2723670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
27241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2725788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template: {
2726c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2727788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemplateName Template
2728788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      = getDerived().TransformTemplateName(Arg.getAsTemplate());
2729788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    if (Template.isNull())
2730788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      return true;
2731c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2732788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(Template),
2733788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateQualifierRange(),
2734788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateNameLoc());
2735788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return false;
2736788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  }
2737a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2738a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor  case TemplateArgument::TemplateExpansion:
2739a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    llvm_unreachable("Caller should expand pack expansions");
2740a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2741670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Expression: {
2742670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    // Template argument expressions are not potentially evaluated.
27431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EnterExpressionEvaluationContext Unevaluated(getSema(),
2744f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                 Sema::Unevaluated);
27451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2746833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Expr *InputExpr = Input.getSourceExpression();
2747833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2748833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
274960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult E
2750833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = getDerived().TransformExpr(InputExpr);
2751833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (E.isInvalid()) return true;
27529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2753833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2754670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2756670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Pack: {
2757670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2758670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    TransformedArgs.reserve(Arg.pack_size());
27591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2760670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor                                      AEnd = Arg.pack_end();
2761670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor         A != AEnd; ++A) {
27621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2763833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // FIXME: preserve source information here when we start
2764833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // caring about parameter packs.
2765833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2766828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc InputArg;
2767828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc OutputArg;
2768828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      getDerived().InventTemplateArgumentLoc(*A, InputArg);
2769828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2770833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall        return true;
2771833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2772828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TransformedArgs.push_back(OutputArg.getArgument());
2773670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    }
2774910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
2775910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    TemplateArgument *TransformedArgsPtr
2776910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2777910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2778910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor              TransformedArgsPtr);
2779910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2780910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                                  TransformedArgs.size()),
2781910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                 Input.getLocInfo());
2782833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2783670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
2784670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
27851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2786670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Work around bogus GCC warning
2787833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return true;
2788670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor}
2789670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
27907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information
27917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator.
27927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator>
27937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator {
27947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TreeTransform<Derived> &Self;
27957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  InputIterator Iter;
27967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
27977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic:
27987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc value_type;
27997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc reference;
28007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef typename std::iterator_traits<InputIterator>::difference_type
28017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    difference_type;
28027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef std::input_iterator_tag iterator_category;
28037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class pointer {
28057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Arg;
2806fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
28077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
28087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
28097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    const TemplateArgumentLoc *operator->() const { return &Arg; }
28117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
28127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator() { }
28147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
28167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                             InputIterator Iter)
28177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    : Self(Self), Iter(Iter) { }
28187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator &operator++() {
28207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++Iter;
28217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return *this;
2822fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  }
2823fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
28247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator operator++(int) {
28257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocInventIterator Old(*this);
28267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++(*this);
28277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Old;
28287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
28297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  reference operator*() const {
28317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Result;
28327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    Self.InventTemplateArgumentLoc(*Iter, Result);
28337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Result;
28347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
28357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  pointer operator->() const { return pointer(**this); }
28377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator==(const TemplateArgumentLocInventIterator &X,
28397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
28407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter == Y.Iter;
28417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
2842fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
28437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator!=(const TemplateArgumentLocInventIterator &X,
28447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
28457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter != Y.Iter;
28467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
28477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor};
28487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
28497f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived>
28507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator>
28517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
28527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                        InputIterator Last,
28537f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor                                            TemplateArgumentListInfo &Outputs) {
28547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  for (; First != Last; ++First) {
28557f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    TemplateArgumentLoc Out;
28567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc In = *First;
28578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().getKind() == TemplateArgument::Pack) {
28598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Unpack argument packs, which we translate them into separate
28608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // arguments.
28617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // FIXME: We could do much better if we could guarantee that the
28627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // TemplateArgumentLocInfo for the pack expansion would be usable for
28637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // all of the template arguments in the argument pack.
28647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      typedef TemplateArgumentLocInventIterator<Derived,
28657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                TemplateArgument::pack_iterator>
28667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        PackLocIterator;
28677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      if (TransformTemplateArguments(PackLocIterator(*this,
28687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                 In.getArgument().pack_begin()),
28697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     PackLocIterator(*this,
28707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                   In.getArgument().pack_end()),
28717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     Outputs))
28727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return true;
28738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
28758491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
28768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().isPackExpansion()) {
28788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // We have a pack expansion, for which we will be substituting into
28798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // the pattern.
28808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      SourceLocation Ellipsis;
2881cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> OrigNumExpansions;
28828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      TemplateArgumentLoc Pattern
2883cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2884cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                     getSema().Context);
28858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
28878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
28888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
28898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
28908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
28918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // be expanded.
28928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      bool Expand = true;
2893d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
2894cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
28958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (getDerived().TryExpandParameterPacks(Ellipsis,
28968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Pattern.getSourceRange(),
28978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.data(),
28988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.size(),
2899d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand,
2900d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
2901d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
29028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return true;
29038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (!Expand) {
29058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // The transform has determined that we should perform a simple
29068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // transformation on the pack expansion, producing another pack
29078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // expansion.
29088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        TemplateArgumentLoc OutPattern;
29098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
29108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
29118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
29128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
2913cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2914cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                NumExpansions);
29158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (Out.getArgument().isNull())
29168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
29178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
29198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        continue;
29208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
29218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // The transform has determined that we should perform an elementwise
29238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // expansion of the pattern. Do so.
2924cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
29258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
29268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
29288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
29298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
293077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.getArgument().containsUnexpandedParameterPack()) {
2931cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2932cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                  OrigNumExpansions);
293377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.getArgument().isNull())
293477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
293577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
293677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
29378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
29388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
29398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29403cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
29413cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
29423cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
29433cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
29443cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
29453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
29463cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
29473cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
2948cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2949cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                OrigNumExpansions);
29503cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (Out.getArgument().isNull())
29513cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
29523cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
29533cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        Outputs.addArgument(Out);
29543cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
2955d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
29568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
29578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
29588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
29598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    // The simple case:
29608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (getDerived().TransformTemplateArgument(In, Out))
29617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor      return true;
29627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
29637f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    Outputs.addArgument(Out);
29647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  }
29657f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
29667f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  return false;
29677f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
29687f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor}
29697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
2970577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
2971577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation
2972577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
2973577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2974577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
297543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) {
2976577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (getDerived().AlreadyTransformed(T))
2977577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T;
29781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2979a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Temporary workaround.  All of these transformations should
2980a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // eventually turn into transformations on TypeLocs.
2981c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2982c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor                                                getDerived().getBaseLocation());
2983c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
298443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
29851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2986a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (!NewDI)
2987a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
29881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2989a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return NewDI->getType();
2990577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
29911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2992577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
299343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
2994a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlreadyTransformed(DI->getType()))
2995a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return DI;
29961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2997a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLocBuilder TLB;
29981bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
2999a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLoc TL = DI->getTypeLoc();
3000a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TLB.reserve(TL.getFullDataSize());
30011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
300243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, TL);
3003a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3004a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return 0;
30051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3006a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3007577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
30081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3010a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
301143fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3012a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  switch (T.getTypeLocClass()) {
3013a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
3014a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \
3015a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  case TypeLoc::CLASS: \
301643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3017a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
3018a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3019577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
30209f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("unhandled type loc!");
3021a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return QualType();
3022577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
30231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3024a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types
3025a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers
3026a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function
3027a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but
3028a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients.
30291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
30301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3031a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
303243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               QualifiedTypeLoc T) {
3033a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers Quals = T.getType().getLocalQualifiers();
3034a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
303543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3036a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3037577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
30381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3039a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Silently suppress qualifiers if the result type can't be qualified.
3040a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: this is the right thing for template instantiation, but
3041a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // probably not for other clients.
3042a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result->isFunctionType() || Result->isReferenceType())
3043a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return Result;
30441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30452865474261a608c7873b87ba4af110d17907896dJohn McCall  if (!Quals.empty()) {
30462865474261a608c7873b87ba4af110d17907896dJohn McCall    Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
30472865474261a608c7873b87ba4af110d17907896dJohn McCall    TLB.push<QualifiedTypeLoc>(Result);
30482865474261a608c7873b87ba4af110d17907896dJohn McCall    // No location information to preserve.
30492865474261a608c7873b87ba4af110d17907896dJohn McCall  }
3050a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3051a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3052a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3053a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
305443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// \brief Transforms a type that was written in a scope specifier,
305543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// given an object type, the results of unqualified lookup, and
305643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// an already-instantiated prefix.
305743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall///
305843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// The object type is provided iff the scope specifier qualifies the
305943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// member of a dependent member-access expression.  The prefix is
306043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// provided iff the the scope specifier in which this appears has a
306143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// prefix.
306243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall///
306343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// This is private to TreeTransform.
306443fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
306543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType
306643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
306743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
306843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
306943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *Prefix) {
307043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
307143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return T;
307243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
307343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TSI =
3074c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor    SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
307543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
307643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
307743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                UnqualLookup, Prefix);
307843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (!TSI) return QualType();
307943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TSI->getType();
308043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
308143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
308243fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
308343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *
308443fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
308543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
308643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
308743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *Prefix) {
308843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: in some cases, we might be some verification to do here.
308943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (ObjectType.isNull())
309043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().TransformType(TSI);
309143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
309243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType T = TSI->getType();
309343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
309443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return TSI;
309543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
309643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeLocBuilder TLB;
309743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result;
309843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
309943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (isa<TemplateSpecializationType>(T)) {
310043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateSpecializationTypeLoc TL
310143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
310243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
310343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateName Template =
310443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
310543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         ObjectType, UnqualLookup);
310643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (Template.isNull()) return 0;
310743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
310843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived()
310943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      .TransformTemplateSpecializationType(TLB, TL, Template);
311043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else if (isa<DependentTemplateSpecializationType>(T)) {
311143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    DependentTemplateSpecializationTypeLoc TL
311243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
311343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
311443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived()
311543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
311643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else {
311743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    // Nothing special needs to be done for these.
311843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
311943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
312043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
312143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Result.isNull()) return 0;
312243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
312343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
312443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
3125a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline
3126a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TyLoc NewT = TLB.push<TyLoc>(T.getType());
3128a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewT.setNameLoc(T.getNameLoc());
3129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return T.getType();
3130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
313443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      BuiltinTypeLoc T) {
3135ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3136ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  NewT.setBuiltinLoc(T.getBuiltinLoc());
3137ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (T.needsExtraLocalData())
3138ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3139ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  return T.getType();
3140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
31421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
314443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ComplexTypeLoc T) {
3145a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: recurse?
3146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, T);
3147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
31481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
315143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      PointerTypeLoc TL) {
3152c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType PointeeType
3153c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
315492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (PointeeType.isNull())
315592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return QualType();
315692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
315792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  QualType Result = TL.getType();
3158c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (PointeeType->getAs<ObjCObjectType>()) {
315992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // A dependent pointer type 'T *' has is being transformed such
316092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // that an Objective-C class type is being replaced for 'T'. The
316192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // resulting pointer type is an ObjCObjectPointerType, not a
316292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // PointerType.
3163c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3164c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3165c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NewT.setStarLoc(TL.getStarLoc());
316792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return Result;
316892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
316943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
317092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (getDerived().AlwaysRebuild() ||
317192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      PointeeType != TL.getPointeeLoc().getType()) {
317292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
317392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Result.isNull())
317492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      return QualType();
317592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
3176c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
317792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
317892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3179c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Result;
3180577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3181577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
31821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
31831eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3184a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
318543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  BlockPointerTypeLoc TL) {
3186db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  QualType PointeeType
3187c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
3188c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (PointeeType.isNull())
3189c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return QualType();
3190c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3191c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType Result = TL.getType();
3192c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (getDerived().AlwaysRebuild() ||
3193c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      PointeeType != TL.getPointeeLoc().getType()) {
3194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Result = getDerived().RebuildBlockPointerType(PointeeType,
3195db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor                                                  TL.getSigilLoc());
3196db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor    if (Result.isNull())
3197db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor      return QualType();
3198db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  }
3199db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor
320039968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3201db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3202db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  return Result;
3203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
32041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
320585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type.  Note that somewhat paradoxically we
320685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value
320785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type;  we only care if the type was *written* as an l-value type
320885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type.
320985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived>
321085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType
321185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
321243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ReferenceTypeLoc TL) {
321385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  const ReferenceType *T = TL.getTypePtr();
321485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
321585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // Note that this works with the pointee-as-written.
321685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
321785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (PointeeType.isNull())
321885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return QualType();
321985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
322085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType Result = TL.getType();
322185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (getDerived().AlwaysRebuild() ||
322285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      PointeeType != T->getPointeeTypeAsWritten()) {
322385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildReferenceType(PointeeType,
322485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               T->isSpelledAsLValue(),
322585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               TL.getSigilLoc());
322685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    if (Result.isNull())
322785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      return QualType();
322885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
322985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
323085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // r-value references can be rebuilt as l-value references.
323185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  ReferenceTypeLoc NewTL;
323285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (isa<LValueReferenceType>(Result))
323385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
323485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  else
323585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
323685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
323785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
323885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  return Result;
323985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall}
324085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3241a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3242a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3243a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
324443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 LValueReferenceTypeLoc TL) {
324543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3246a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
32471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3249a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3250a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
325143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 RValueReferenceTypeLoc TL) {
325243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3253577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
32541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3255577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
32561eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3257a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
325843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   MemberPointerTypeLoc TL) {
3259f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const MemberPointerType *T = TL.getTypePtr();
3260a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3261a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3262577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (PointeeType.isNull())
3263577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3265a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // TODO: preserve source information for this.
3266a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ClassType
3267a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformType(QualType(T->getClass(), 0));
3268577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ClassType.isNull())
3269577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3271a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3272a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3273a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      PointeeType != T->getPointeeType() ||
3274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ClassType != QualType(T->getClass(), 0)) {
327585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
327685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getStarLoc());
3277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3280577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
3283a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
32871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
32881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
329043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ConstantArrayTypeLoc TL) {
3291f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ConstantArrayType *T = TL.getTypePtr();
3292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3293577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3294577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildConstantArrayType(ElementType,
3300a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
3301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSize(),
330285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             T->getIndexTypeCVRQualifiers(),
330385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3304a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3305a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3306a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3307c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3309a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3310a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
33111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3312a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = TL.getSizeExpr();
3313a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Size) {
3314f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3315a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3316a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3317a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
3318a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3319a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3320577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3322577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3323577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType(
3324a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                              TypeLocBuilder &TLB,
332543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              IncompleteArrayTypeLoc TL) {
3326f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const IncompleteArrayType *T = TL.getTypePtr();
3327a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3328577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3332a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3333a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3334a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildIncompleteArrayType(ElementType,
3335a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                     T->getSizeModifier(),
333685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                           T->getIndexTypeCVRQualifiers(),
333785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                     TL.getBracketsRange());
3338a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3339a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3340a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3341c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3342a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3344a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3345a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(0);
3346577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3348577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3351a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3352a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
335343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   VariableArrayTypeLoc TL) {
3354f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VariableArrayType *T = TL.getTypePtr();
3355a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3356577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3357577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3359670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3360f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3361670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
336260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
3363a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
3364a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
3365577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Size = SizeResult.take();
3368a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3369a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3370a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3371a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
3372a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
3373a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildVariableArrayType(ElementType,
3374a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
33759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Size,
3376a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                             T->getIndexTypeCVRQualifiers(),
337785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3378a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3379a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3380577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3381c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3382a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3383a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3384a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3385a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
33861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3387a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3388577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3391a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3392a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
339343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             DependentSizedArrayTypeLoc TL) {
3394f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedArrayType *T = TL.getTypePtr();
3395a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3397577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3399670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3400f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
34011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // Prefer the expression from the TypeLoc;  the other may have been uniqued.
34033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *origSize = TL.getSizeExpr();
34043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!origSize) origSize = T->getSizeExpr();
34053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
34063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExprResult sizeResult
34073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    = getDerived().TransformExpr(origSize);
34083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (sizeResult.isInvalid())
3409577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *size = sizeResult.get();
3412a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3413a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3414a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3415a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
34163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      size != origSize) {
3417a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3418a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                         T->getSizeModifier(),
34193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                                                         size,
3420a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                T->getIndexTypeCVRQualifiers(),
342185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                        TL.getBracketsRange());
3422a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3424577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
34251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3426a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // We might have any sort of array type now, but fortunately they
3427a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // all have the same location layout.
3428a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3429a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3430a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
34313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  NewTL.setSizeExpr(size);
3432a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3433a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3434577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3437577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3438a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                      TypeLocBuilder &TLB,
343943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentSizedExtVectorTypeLoc TL) {
3440f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedExtVectorType *T = TL.getTypePtr();
3441a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3442a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: ext vector locs should be nested
3443577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3444577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3445577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3447670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Vector sizes are not potentially evaluated contexts
3448f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3449670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
345060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3451577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (Size.isInvalid())
3452577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3454a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3455a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3456eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      ElementType != T->getElementType() ||
3457eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      Size.get() != T->getSizeExpr()) {
3458a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
34599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                             Size.take(),
3460577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                         T->getAttributeLoc());
3461a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3462a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3463a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3464a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3465a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Result might be dependent or not.
3466a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (isa<DependentSizedExtVectorType>(Result)) {
3467a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    DependentSizedExtVectorTypeLoc NewTL
3468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3469a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  } else {
3471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3472a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3473a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3474a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3475a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3476577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3479a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
348043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     VectorTypeLoc TL) {
3481f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3482577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3483577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3484577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3485577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3486a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3487a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3488a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
348982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3490e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                            T->getVectorKind());
3491a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3493a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3494c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3496a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
34971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3498a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3499577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3502a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
350343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        ExtVectorTypeLoc TL) {
3504f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3505577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3506577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3507577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3509a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3510a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3511a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildExtVectorType(ElementType,
3513a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               T->getNumElements(),
3514a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               /*FIXME*/ SourceLocation());
3515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3516a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3517a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3518c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3519a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
35211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3522a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3523577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3524577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
35251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
352621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl *
35276a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
35286a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
352921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
35306a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  TypeSourceInfo *NewDI = 0;
35316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35326a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
35336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    // If we're substituting into a pack expansion type and we know the
35346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc OldTL = OldDI->getTypeLoc();
35356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
35366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLocBuilder TLB;
35386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc NewTL = OldDI->getTypeLoc();
35396a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TLB.reserve(NewTL.getFullDataSize());
35406a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35416a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    QualType Result = getDerived().TransformType(TLB,
35426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                               OldExpansionTL.getPatternLoc());
35436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
35446a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
35456a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35466a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    Result = RebuildPackExpansionType(Result,
35476a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                OldExpansionTL.getPatternLoc().getSourceRange(),
35486a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      OldExpansionTL.getEllipsisLoc(),
35496a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      NumExpansions);
35506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
35516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
35526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
35536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc NewExpansionTL
35546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      = TLB.push<PackExpansionTypeLoc>(Result);
35556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
35566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
35576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  } else
35586a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = getDerived().TransformType(OldDI);
355921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (!NewDI)
356021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return 0;
356121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
356221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (NewDI == OldDI)
356321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return OldParm;
356421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  else
356521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return ParmVarDecl::Create(SemaRef.Context,
356621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getDeclContext(),
356721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getLocation(),
356821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getIdentifier(),
356921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               NewDI->getType(),
357021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               NewDI,
357121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getStorageClass(),
357216573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor                               OldParm->getStorageClassAsWritten(),
357321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               /* DefArg */ NULL);
357421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
357521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
357621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
357721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>::
3578a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  TransformFunctionTypeParams(SourceLocation Loc,
3579a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              ParmVarDecl **Params, unsigned NumParams,
3580a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              const QualType *ParamTypes,
3581a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              llvm::SmallVectorImpl<QualType> &OutParamTypes,
3582a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3583a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  for (unsigned i = 0; i != NumParams; ++i) {
3584a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (ParmVarDecl *OldParm = Params[i]) {
35856a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      llvm::Optional<unsigned> NumExpansions;
3586603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (OldParm->isParameterPack()) {
3587603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We have a function parameter pack that may need to be expanded.
3588603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3589603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3590603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Find the parameter packs that could be expanded.
3591c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3592c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3593c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc Pattern = ExpansionTL.getPatternLoc();
3594c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3595603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3596603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Determine whether we should expand the parameter packs.
3597603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        bool ShouldExpand = false;
3598d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor        bool RetainExpansion = false;
35996a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        llvm::Optional<unsigned> OrigNumExpansions
36006a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor          = ExpansionTL.getTypePtr()->getNumExpansions();
36016a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        NumExpansions = OrigNumExpansions;
3602c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3603c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor                                                 Pattern.getSourceRange(),
3604603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.data(),
3605603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.size(),
3606d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 ShouldExpand,
3607d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 RetainExpansion,
3608d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 NumExpansions)) {
3609603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          return true;
3610603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3611603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3612603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        if (ShouldExpand) {
3613603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // Expand the function parameter pack into multiple, separate
3614603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // parameters.
361512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor          getDerived().ExpandingFunctionParameterPack(OldParm);
3616cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          for (unsigned I = 0; I != *NumExpansions; ++I) {
3617603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3618603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            ParmVarDecl *NewParm
36196a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
36206a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3621603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            if (!NewParm)
3622603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor              return true;
3623603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3624a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            OutParamTypes.push_back(NewParm->getType());
3625a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            if (PVars)
3626a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor              PVars->push_back(NewParm);
3627603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          }
3628d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3629d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // If we're supposed to retain a pack expansion, do so by temporarily
3630d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // forgetting the partially-substituted parameter pack.
3631d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          if (RetainExpansion) {
3632d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3633d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ParmVarDecl *NewParm
36346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
36356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3636d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (!NewParm)
3637d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              return true;
3638d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3639d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            OutParamTypes.push_back(NewParm->getType());
3640d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (PVars)
3641d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              PVars->push_back(NewParm);
3642d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          }
3643d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3644603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // We're done with the pack expansion.
3645603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          continue;
3646603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3647603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3648603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We'll substitute the parameter now without expanding the pack
3649603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // expansion.
3650603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3651603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3652603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
36536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
36546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                                 NumExpansions);
365521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      if (!NewParm)
365621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3657603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3658a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      OutParamTypes.push_back(NewParm->getType());
3659a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (PVars)
3660a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor        PVars->push_back(NewParm);
3661603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      continue;
3662603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    }
3663a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3664a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // Deal with the possibility that we don't have a parameter
3665a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // declaration for this parameter.
3666a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    QualType OldType = ParamTypes[i];
3667603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    bool IsPackExpansion = false;
3668cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    llvm::Optional<unsigned> NumExpansions;
3669603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (const PackExpansionType *Expansion
3670603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                       = dyn_cast<PackExpansionType>(OldType)) {
3671603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We have a function parameter pack that may need to be expanded.
3672603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      QualType Pattern = Expansion->getPattern();
3673603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3674603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3675603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3676603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // Determine whether we should expand the parameter packs.
3677603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      bool ShouldExpand = false;
3678d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3679a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
3680603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.data(),
3681603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.size(),
3682d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               ShouldExpand,
3683d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3684d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions)) {
368521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3686603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3687603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3688603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (ShouldExpand) {
3689603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Expand the function parameter pack into multiple, separate
3690603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // parameters.
3691cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        for (unsigned I = 0; I != *NumExpansions; ++I) {
3692603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3693603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          QualType NewType = getDerived().TransformType(Pattern);
3694603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          if (NewType.isNull())
3695603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            return true;
3696603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3697a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          OutParamTypes.push_back(NewType);
3698a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          if (PVars)
3699a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            PVars->push_back(0);
3700603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3701603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3702603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We're done with the pack expansion.
3703603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        continue;
3704603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3705603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
37063cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
37073cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
37083cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
37093cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
37103cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        QualType NewType = getDerived().TransformType(Pattern);
37113cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (NewType.isNull())
37123cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
37133cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
37143cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        OutParamTypes.push_back(NewType);
37153cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (PVars)
37163cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          PVars->push_back(0);
37173cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
3718d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3719603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We'll substitute the parameter now without expanding the pack
3720603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // expansion.
3721603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      OldType = Expansion->getPattern();
3722603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      IsPackExpansion = true;
3723a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    }
3724603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3725603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3726603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    QualType NewType = getDerived().TransformType(OldType);
3727603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (NewType.isNull())
3728603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      return true;
37291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3730603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (IsPackExpansion)
3731cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NewType = getSema().Context.getPackExpansionType(NewType,
3732cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                       NumExpansions);
3733603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3734a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    OutParamTypes.push_back(NewType);
3735a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (PVars)
3736a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      PVars->push_back(0);
3737577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
37381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
373921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  return false;
3740603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor  }
374121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
374221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
374321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType
374421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
374543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   FunctionProtoTypeLoc TL) {
37467e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // Transform the parameters and return type.
37477e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
37487e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // We instantiate in source order, with the return type first followed by
37497e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // the parameters, because users tend to expect this (even if they shouldn't
37507e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // rely on it!).
37517e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
3752dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // When the function has a trailing return type, we instantiate the
3753dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // parameters before the return type,  since the return type can then refer
3754dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // to the parameters themselves (via decltype, sizeof, etc.).
3755dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
375621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<QualType, 4> ParamTypes;
375721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
3758f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionProtoType *T = TL.getTypePtr();
37597e010a04fef171049291d8cb3047f118566da090Douglas Gregor
3760dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  QualType ResultType;
3761dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3762dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  if (TL.getTrailingReturn()) {
3763a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3764a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
3765a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
3766a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
3767a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
3768dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3769dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3770dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3771dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
3772dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3773dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
3774dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  else {
3775dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3776dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
3777dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3778dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3779a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3780a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
3781a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
3782a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
3783a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
3784dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3785dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
3786dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3787a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3788a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3789a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType() ||
3790bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor      T->getNumArgs() != ParamTypes.size() ||
3791a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3792a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionProtoType(ResultType,
3793a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.data(),
3794a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.size(),
3795a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->isVariadic(),
3796fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getTypeQuals(),
3797c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                   T->getRefQualifier(),
3798fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getExtInfo());
3799a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3800a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3801a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
38021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3804a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3805a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3806dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(TL.getTrailingReturn());
3807a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3808a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setArg(i, ParamDecls[i]);
3809a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3810a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3811577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3813577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3814577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType(
3815a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                 TypeLocBuilder &TLB,
381643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 FunctionNoProtoTypeLoc TL) {
3817f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionNoProtoType *T = TL.getTypePtr();
3818a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3819a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (ResultType.isNull())
3820a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
3821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3822a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3823a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3824a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType())
3825a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3826a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3827a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3828a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3829a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3830dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(false);
3831a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3832a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3833577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3835ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType
3836ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
383743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 UnresolvedUsingTypeLoc TL) {
3838f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const UnresolvedUsingType *T = TL.getTypePtr();
38397c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
3840ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (!D)
3841ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return QualType();
3842ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3843ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType Result = TL.getType();
3844ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3845ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Result = getDerived().RebuildUnresolvedUsingType(D);
3846ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    if (Result.isNull())
3847ed97649e9574b9d854fa4d6109c9333ae0993554John McCall      return QualType();
3848ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3849ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3850ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // We might get an arbitrary type spec type back.  We should at
3851ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // least always get a type spec type, though.
3852ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3853ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  NewTL.setNameLoc(TL.getNameLoc());
3854ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3855ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return Result;
3856ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
3857ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3858577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3859a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
386043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypedefTypeLoc TL) {
3861f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypedefType *T = TL.getTypePtr();
3862577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  TypedefDecl *Typedef
38637c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
38647c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           T->getDecl()));
3865577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Typedef)
3866577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
38671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3868a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3869a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3870a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Typedef != T->getDecl()) {
3871a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildTypedefType(Typedef);
3872a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3873a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3874a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3875a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3876a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3877a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
38781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3879a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3880577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3882577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3883a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
388443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypeOfExprTypeLoc TL) {
3885670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // typeof expressions are not potentially evaluated contexts
3886f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
38871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
388860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
3889577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
3890577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3891577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3892a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3893a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3894cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      E.get() != TL.getUnderlyingExpr()) {
38952a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
3896a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3897a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3898577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3899a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
39001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3901a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
3902cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
3903cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3904cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3905a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3906a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3907577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
39081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3910a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
391143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     TypeOfTypeLoc TL) {
3912cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3913cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3914cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (!New_Under_TI)
3915577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
39161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3917a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3918cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3919cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
3920a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3921a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3922a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
39231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3924a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
3925cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
3926cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3927cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3928cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setUnderlyingTInfo(New_Under_TI);
3929a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3930a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3931577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
39321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3934a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
393543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                       DecltypeTypeLoc TL) {
3936f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DecltypeType *T = TL.getTypePtr();
3937a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3938670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // decltype expressions are not potentially evaluated contexts
3939f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
39401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
394160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3942577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
3943577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
39441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3945a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3946a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3947a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      E.get() != T->getUnderlyingExpr()) {
39482a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
3949a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3950a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3951577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3952a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
3953a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3954a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3955a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
39561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3957a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3958577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3959577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3960577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
396134b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
396234b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                   AutoTypeLoc TL) {
396334b41d939a1328f484511c6002ba2456db879a29Richard Smith  const AutoType *T = TL.getTypePtr();
396434b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType OldDeduced = T->getDeducedType();
396534b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType NewDeduced;
396634b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (!OldDeduced.isNull()) {
396734b41d939a1328f484511c6002ba2456db879a29Richard Smith    NewDeduced = getDerived().TransformType(OldDeduced);
396834b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (NewDeduced.isNull())
396934b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
397034b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
397134b41d939a1328f484511c6002ba2456db879a29Richard Smith
397234b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType Result = TL.getType();
397334b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
397434b41d939a1328f484511c6002ba2456db879a29Richard Smith    Result = getDerived().RebuildAutoType(NewDeduced);
397534b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (Result.isNull())
397634b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
397734b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
397834b41d939a1328f484511c6002ba2456db879a29Richard Smith
397934b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
398034b41d939a1328f484511c6002ba2456db879a29Richard Smith  NewTL.setNameLoc(TL.getNameLoc());
398134b41d939a1328f484511c6002ba2456db879a29Richard Smith
398234b41d939a1328f484511c6002ba2456db879a29Richard Smith  return Result;
398334b41d939a1328f484511c6002ba2456db879a29Richard Smith}
398434b41d939a1328f484511c6002ba2456db879a29Richard Smith
398534b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived>
3986a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
398743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     RecordTypeLoc TL) {
3988f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const RecordType *T = TL.getTypePtr();
3989577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  RecordDecl *Record
39907c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
39917c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                          T->getDecl()));
3992577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Record)
3993577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
39941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3995a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3996a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3997a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Record != T->getDecl()) {
3998a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildRecordType(Record);
3999a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4000a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4001a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
40021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4003a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4004a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
4005a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4006a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4007577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
40081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4010a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
401143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   EnumTypeLoc TL) {
4012f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const EnumType *T = TL.getTypePtr();
4013577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  EnumDecl *Enum
40147c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
40157c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                        T->getDecl()));
4016577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Enum)
4017577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
40181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4019a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4020a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4021a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Enum != T->getDecl()) {
4022a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildEnumType(Enum);
4023a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4024a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4025a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4026a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4027a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4028a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
40291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4030a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4031577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
40327da2431c23ef1ee8acb114e39692246e1801afc2John McCall
40333cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived>
40343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType(
40353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         TypeLocBuilder &TLB,
403643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         InjectedClassNameTypeLoc TL) {
40373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
40383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                       TL.getTypePtr()->getDecl());
40393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  if (!D) return QualType();
40403cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
40413cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
40423cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
40433cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  return T;
40443cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
40453cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
4046577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4047577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4048a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                TypeLocBuilder &TLB,
404943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TemplateTypeParmTypeLoc TL) {
4050a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
4051577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4052577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
40531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
405449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4055a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                         TypeLocBuilder &TLB,
405643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         SubstTemplateTypeParmTypeLoc TL) {
4057a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
405849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
405949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
406049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived>
4061c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4062c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          TypeLocBuilder &TLB,
4063c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          SubstTemplateTypeParmPackTypeLoc TL) {
4064c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  return TransformTypeSpecType(TLB, TL);
4065c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}
4066c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
4067c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived>
4068833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
406943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        TypeLocBuilder &TLB,
407043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                           TemplateSpecializationTypeLoc TL) {
407143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
4072828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
407343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TemplateName Template
407443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformTemplateName(T->getTemplateName());
407543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Template.isNull())
407643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4077833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
407843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4079dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor}
408043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
40817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace {
40827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \brief Simple iterator that traverses the template arguments in a
40837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// container that provides a \c getArgLoc() member function.
40847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
40857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// This iterator is intended to be used with the iterator form of
40867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \c TreeTransform<Derived>::TransformTemplateArguments().
40877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename ArgLocContainer>
40887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class TemplateArgumentLocContainerIterator {
40897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgLocContainer *Container;
40907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    unsigned Index;
40917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
40937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc value_type;
40947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc reference;
40957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef int difference_type;
40967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef std::input_iterator_tag iterator_category;
40977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
40987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    class pointer {
40997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLoc Arg;
41007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    public:
41027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
41037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      const TemplateArgumentLoc *operator->() const {
41057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return &Arg;
41067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      }
41077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    };
41087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator() {}
41117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
41137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                 unsigned Index)
41147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      : Container(&Container), Index(Index) { }
41157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator &operator++() {
41177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++Index;
41187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return *this;
41197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator operator++(int) {
41227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLocContainerIterator Old(*this);
41237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++(*this);
41247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Old;
41257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc operator*() const {
41287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Container->getArgLoc(Index);
41297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    pointer operator->() const {
41327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return pointer(Container->getArgLoc(Index));
41337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4136f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
41377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return X.Container == Y.Container && X.Index == Y.Index;
41387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4141f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
41427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return !(X == Y);
41437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
41447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
41457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}
41467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
41477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
414843fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived>
4149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4150833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                        TypeLocBuilder &TLB,
4151833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                           TemplateSpecializationTypeLoc TL,
415243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TemplateName Template) {
4153d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo NewTemplateArgs;
4154d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4155d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
41567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
41577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgIterator;
41587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
41597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
41607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              NewTemplateArgs))
41617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    return QualType();
41621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4163833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  // FIXME: maybe don't rebuild if all the template arguments are the same.
4164833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
4165833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType Result =
4166833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getDerived().RebuildTemplateSpecializationType(Template,
4167833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                   TL.getTemplateNameLoc(),
4168d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NewTemplateArgs);
41691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4170833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  if (!Result.isNull()) {
4171833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TemplateSpecializationTypeLoc NewTL
4172833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4173833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4174833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setLAngleLoc(TL.getLAngleLoc());
4175833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setRAngleLoc(TL.getRAngleLoc());
4176833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4177833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4178833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
41791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4180833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return Result;
4181577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4184a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4185465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
418643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ElaboratedTypeLoc TL) {
4187f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ElaboratedType *T = TL.getTypePtr();
4188465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
4189465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  NestedNameSpecifier *NNS = 0;
4190465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // NOTE: the qualifier in an ElaboratedType is optional.
4191465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  if (T->getQualifier() != 0) {
4192465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
419343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                    TL.getQualifierRange());
4194465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (!NNS)
4195465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      return QualType();
4196465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
41971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
419843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
419943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (NamedT.isNull())
420043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4201a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar
4202a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NNS != T->getQualifier() ||
4205e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      NamedT != T->getNamedType()) {
420621e413fe6305a198564d436ac515497716c47844John McCall    Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
420721e413fe6305a198564d436ac515497716c47844John McCall                                                T->getKeyword(), NNS, NamedT);
4208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4211577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4212465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4213e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setKeywordLoc(TL.getKeywordLoc());
4214e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setQualifierRange(TL.getQualifierRange());
4215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4217577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
42181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
42209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType(
42219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                TypeLocBuilder &TLB,
42229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                AttributedTypeLoc TL) {
42239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  const AttributedType *oldType = TL.getTypePtr();
42249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
42259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (modifiedType.isNull())
42269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return QualType();
42279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType result = TL.getType();
42299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // FIXME: dependent operand expressions?
42319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (getDerived().AlwaysRebuild() ||
42329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      modifiedType != oldType->getModifiedType()) {
42339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // TODO: this is really lame; we should really be rebuilding the
42349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // equivalent type from first principles.
42359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    QualType equivalentType
42369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      = getDerived().TransformType(oldType->getEquivalentType());
42379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (equivalentType.isNull())
42389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      return QualType();
42399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
42409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               modifiedType,
42419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               equivalentType);
42429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
42439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
42459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  newTL.setAttrNameLoc(TL.getAttrNameLoc());
42469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrOperand())
42479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
42489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrExprOperand())
42499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrExprOperand(TL.getAttrExprOperand());
42509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  else if (TL.hasAttrEnumOperand())
42519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
42529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  return result;
42549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
42559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
42569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived>
4257075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType
4258075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4259075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                                           ParenTypeLoc TL) {
4260075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4261075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (Inner.isNull())
4262075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType();
4263075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4264075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Result = TL.getType();
4265075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (getDerived().AlwaysRebuild() ||
4266075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      Inner != TL.getInnerLoc().getType()) {
4267075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Result = getDerived().RebuildParenType(Inner);
4268075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    if (Result.isNull())
4269075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      return QualType();
4270075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
4271075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4272075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4273075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setLParenLoc(TL.getLParenLoc());
4274075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setRParenLoc(TL.getRParenLoc());
4275075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  return Result;
4276075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
4277075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4278075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived>
42794714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
428043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      DependentNameTypeLoc TL) {
4281f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentNameType *T = TL.getTypePtr();
4282833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
4283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  NestedNameSpecifier *NNS
4284e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
428543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TL.getQualifierRange());
4286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!NNS)
4287577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
42881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
428933500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType Result
429033500955d731c73717af52088b7fc0e7a85681e7John McCall    = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
429133500955d731c73717af52088b7fc0e7a85681e7John McCall                                            T->getIdentifier(),
429233500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getKeywordLoc(),
429333500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getQualifierRange(),
429433500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getNameLoc());
4295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
4296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4298e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4299e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    QualType NamedT = ElabT->getNamedType();
430033500955d731c73717af52088b7fc0e7a85681e7John McCall    TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
430133500955d731c73717af52088b7fc0e7a85681e7John McCall
4302e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4303e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
4304e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setQualifierRange(TL.getQualifierRange());
430533500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
4306e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4307e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
4308e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setQualifierRange(TL.getQualifierRange());
4309e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setNameLoc(TL.getNameLoc());
4310e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
4311a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4312577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4314577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
431533500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>::
431633500955d731c73717af52088b7fc0e7a85681e7John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
431743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL) {
4318f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentTemplateSpecializationType *T = TL.getTypePtr();
431933500955d731c73717af52088b7fc0e7a85681e7John McCall
432033500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS
432133500955d731c73717af52088b7fc0e7a85681e7John McCall    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
432243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TL.getQualifierRange());
432333500955d731c73717af52088b7fc0e7a85681e7John McCall  if (!NNS)
432433500955d731c73717af52088b7fc0e7a85681e7John McCall    return QualType();
432533500955d731c73717af52088b7fc0e7a85681e7John McCall
432643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived()
432743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall           .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
432843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
432943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
433043fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
433143fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::
433243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
433343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL,
433443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *NNS) {
4335f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentTemplateSpecializationType *T = TL.getTypePtr();
433643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
433733500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentListInfo NewTemplateArgs;
433833500955d731c73717af52088b7fc0e7a85681e7John McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
433933500955d731c73717af52088b7fc0e7a85681e7John McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
43407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
43417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLocContainerIterator<
43427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                            DependentTemplateSpecializationTypeLoc> ArgIterator;
43437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
43447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
43457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              NewTemplateArgs))
43467f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    return QualType();
434733500955d731c73717af52088b7fc0e7a85681e7John McCall
43481efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor  QualType Result
43491efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
43501efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              NNS,
43511efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                        TL.getQualifierRange(),
43521efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                            T->getIdentifier(),
43531efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              TL.getNameLoc(),
43541efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              NewTemplateArgs);
435533500955d731c73717af52088b7fc0e7a85681e7John McCall  if (Result.isNull())
435633500955d731c73717af52088b7fc0e7a85681e7John McCall    return QualType();
435733500955d731c73717af52088b7fc0e7a85681e7John McCall
435833500955d731c73717af52088b7fc0e7a85681e7John McCall  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
435933500955d731c73717af52088b7fc0e7a85681e7John McCall    QualType NamedT = ElabT->getNamedType();
436033500955d731c73717af52088b7fc0e7a85681e7John McCall
436133500955d731c73717af52088b7fc0e7a85681e7John McCall    // Copy information relevant to the template specialization.
436233500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateSpecializationTypeLoc NamedTL
436333500955d731c73717af52088b7fc0e7a85681e7John McCall      = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
436433500955d731c73717af52088b7fc0e7a85681e7John McCall    NamedTL.setLAngleLoc(TL.getLAngleLoc());
436533500955d731c73717af52088b7fc0e7a85681e7John McCall    NamedTL.setRAngleLoc(TL.getRAngleLoc());
436633500955d731c73717af52088b7fc0e7a85681e7John McCall    for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
436733500955d731c73717af52088b7fc0e7a85681e7John McCall      NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
436833500955d731c73717af52088b7fc0e7a85681e7John McCall
436933500955d731c73717af52088b7fc0e7a85681e7John McCall    // Copy information relevant to the elaborated type.
437033500955d731c73717af52088b7fc0e7a85681e7John McCall    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
437133500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTL.setKeywordLoc(TL.getKeywordLoc());
437233500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTL.setQualifierRange(TL.getQualifierRange());
437333500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
4374e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor    TypeLoc NewTL(Result, TL.getOpaqueData());
4375e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor    TLB.pushFullCopy(NewTL);
437633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
437733500955d731c73717af52088b7fc0e7a85681e7John McCall  return Result;
437833500955d731c73717af52088b7fc0e7a85681e7John McCall}
437933500955d731c73717af52088b7fc0e7a85681e7John McCall
438033500955d731c73717af52088b7fc0e7a85681e7John McCalltemplate<typename Derived>
43817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
43827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor                                                      PackExpansionTypeLoc TL) {
43832fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Pattern
43842fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    = getDerived().TransformType(TLB, TL.getPatternLoc());
43852fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (Pattern.isNull())
43862fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    return QualType();
43872fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
43882fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Result = TL.getType();
43892fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (getDerived().AlwaysRebuild() ||
43902fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      Pattern != TL.getPatternLoc().getType()) {
43912fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    Result = getDerived().RebuildPackExpansionType(Pattern,
43922fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                           TL.getPatternLoc().getSourceRange(),
4393cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                   TL.getEllipsisLoc(),
4394cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           TL.getTypePtr()->getNumExpansions());
43952fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    if (Result.isNull())
43962fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      return QualType();
43972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
43982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
43992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
44002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  NewT.setEllipsisLoc(TL.getEllipsisLoc());
44012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  return Result;
44027536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}
44037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
44047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived>
4405a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4406a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
440743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ObjCInterfaceTypeLoc TL) {
4408ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCInterfaceType is never dependent.
4409c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4410c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return TL.getType();
4411c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4412c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4413c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived>
4414c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType
4415c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
441643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjCObjectTypeLoc TL) {
4417c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // ObjCObjectType is never dependent.
4418c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4419ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
4420577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
44211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4424a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
442543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ObjCObjectPointerTypeLoc TL) {
4426ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCObjectPointerType is never dependent.
4427c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4428ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
442924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}
443024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis
4431577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
443243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation
443343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
443443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
443560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
44361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
44373fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
443843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
443943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
444043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
444160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
444243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
444343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().TransformCompoundStmt(S, false);
444443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
444543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
444643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
444760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
44481eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
444943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              bool IsStmtExpr) {
44507114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  bool SubStmtInvalid = false;
445143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool SubStmtChanged = false;
4452ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Statements(getSema());
445343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
445443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       B != BEnd; ++B) {
445560d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Result = getDerived().TransformStmt(*B);
44567114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    if (Result.isInvalid()) {
44577114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Immediately fail if this was a DeclStmt, since it's very
44587114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // likely that this will cause problems for future statements.
44597114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      if (isa<DeclStmt>(*B))
44607114cbab7eb6e8b714eb22f014327daf2c741c08John McCall        return StmtError();
44617114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
44627114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Otherwise, just keep processing substatements and fail later.
44637114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      SubStmtInvalid = true;
44647114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      continue;
44657114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
44661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
446743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    SubStmtChanged = SubStmtChanged || Result.get() != *B;
446843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Statements.push_back(Result.takeAs<Stmt>());
446943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
44701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44717114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  if (SubStmtInvalid)
44727114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    return StmtError();
44737114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
447443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
447543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !SubStmtChanged)
44763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
447743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
447843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
447943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          move_arg(Statements),
448043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          S->getRBracLoc(),
448143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          IsStmtExpr);
448243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
44831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
448443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
448560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
44861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
448760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS, RHS;
4488264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  {
4489264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // The case value expressions are not potentially evaluated.
4490f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
44911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4492264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the left-hand case value.
4493264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    LHS = getDerived().TransformExpr(S->getLHS());
4494264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (LHS.isInvalid())
4495f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
44961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4497264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the right-hand case value (for the GNU case-range extension).
4498264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    RHS = getDerived().TransformExpr(S->getRHS());
4499264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (RHS.isInvalid())
4500f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4501264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  }
45021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
450343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Build the case statement.
450443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Case statements are always rebuilt so that they will attached to their
450543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transformed switch statement.
450660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
45079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       LHS.get(),
450843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getEllipsisLoc(),
45099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       RHS.get(),
451043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getColonLoc());
451143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Case.isInvalid())
4512f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
451443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the case
451560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
451643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4517f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
451943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Attach the body to the case statement
45209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
452143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
452243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
452343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
452460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
45251eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
452643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the default case
452760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
452843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4529f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
453143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Default statements are always rebuilt
453243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
45339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubStmt.get());
453443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
45351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
453643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
453760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
45381eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
453960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
454043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4541f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
454357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
454457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getDecl());
454557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
454657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
454757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
454857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
454943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // FIXME: Pass the real colon location in.
4550ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  return getDerived().RebuildLabelStmt(S->getIdentLoc(),
455157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       cast<LabelDecl>(LD), SourceLocation(),
455257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       SubStmt.get());
455343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
45541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
455543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
455660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
45571eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
455843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
455960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
45608cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  VarDecl *ConditionVar = 0;
45618cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  if (S->getConditionVariable()) {
4562c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
45638cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor      = cast_or_null<VarDecl>(
4564aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4565aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4566aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
45678cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    if (!ConditionVar)
4568f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
456999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
45708cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4571c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
457299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4573f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4574eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
4575eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor    // Convert the condition to a boolean value.
4576afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
45778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
45788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
4579afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
4580f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4581eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
45829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
4583afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
458499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
4585c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
45869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
45879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
4588f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4589eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
459043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "then" branch.
459160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Then = getDerived().TransformStmt(S->getThen());
459243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Then.isInvalid())
4593f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
459543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "else" branch.
459660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Else = getDerived().TransformStmt(S->getElse());
459743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Else.isInvalid())
4598f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
45991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
460043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
46019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
460299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
460343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Then.get() == S->getThen() &&
460443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Else.get() == S->getElse())
46053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
46061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4607eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
460844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                    Then.get(),
46099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    S->getElseLoc(), Else.get());
461043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
461143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
461243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
461360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
46141eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
461543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition.
461660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
4617d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  VarDecl *ConditionVar = 0;
4618d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  if (S->getConditionVariable()) {
4619c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
4620d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor      = cast_or_null<VarDecl>(
4621aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4622aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4623aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
4624d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    if (!ConditionVar)
4625f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
462699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
4627d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4628c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
462999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4630f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
463199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
46321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
463343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Rebuild the switch statement.
463460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Switch
46359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
4636586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                          ConditionVar);
463743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Switch.isInvalid())
4638f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
46391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
464043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body of the switch statement.
464160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
464243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
4643f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
46441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
464543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Complete the switch statement.
46469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
46479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Body.get());
464843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
46491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
465043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
465160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
46521eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
465343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
465460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
46555656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  VarDecl *ConditionVar = 0;
46565656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  if (S->getConditionVariable()) {
4657c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
46585656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      = cast_or_null<VarDecl>(
4659aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4660aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4661aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
46625656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    if (!ConditionVar)
4663f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
466499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
46655656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4666c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
466799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4668f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4669afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
4670afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
4671afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
46728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
46738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
4674afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
4675f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
46769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE;
4677afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
467899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
46791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
46819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
4682f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4683eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
468443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
468560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
468643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
4687f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
46881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
468943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
46909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
469199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
469243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
46939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(S);
46941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4695eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
46969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       ConditionVar, Body.get());
469743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
46981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
469943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
470060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
470143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
470243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
470360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
470443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
4705f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
47061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4707eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  // Transform the condition
470860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(S->getCond());
4709eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  if (Cond.isInvalid())
4710f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4711eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
471243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
471343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Cond.get() == S->getCond() &&
471443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
47153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
47161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
47189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    /*FIXME:*/S->getWhileLoc(), Cond.get(),
471943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    S->getRParenLoc());
472043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
47211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
472243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
472360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
47241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) {
472543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the initialization statement
472660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Init = getDerived().TransformStmt(S->getInit());
472743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Init.isInvalid())
4728f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
47291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
473043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
473160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
473299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  VarDecl *ConditionVar = 0;
473399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  if (S->getConditionVariable()) {
4734c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
473599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      = cast_or_null<VarDecl>(
4736aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4737aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4738aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
473999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (!ConditionVar)
4740f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
474199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
474299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4743c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
474499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4745f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4746afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
4747afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
4748afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
47498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
47508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
4751afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
4752f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4753afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
47549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
4755afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
475699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
47571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
47599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
4760f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4761eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
476243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the increment
476360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Inc = getDerived().TransformExpr(S->getInc());
476443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Inc.isInvalid())
4765f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
47661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
47689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (S->getInc() && !FullInc.get())
4769f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4770eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
477143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
477260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
477343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
4774f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
47751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
477643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
477743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Init.get() == S->getInit() &&
47789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
477943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Inc.get() == S->getInc() &&
478043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
47813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
47821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
478343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
47849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Init.get(), FullCond, ConditionVar,
47859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     FullInc, S->getRParenLoc(), Body.get());
478643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
478743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
478843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
478960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
47901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
479157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
479257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getLabel());
479357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
479457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
479557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
479643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Goto statements must always be rebuilt, to resolve the label.
47971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
479857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                      cast<LabelDecl>(LD));
479943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
480043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
480143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
480260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48031eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
480460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Target = getDerived().TransformExpr(S->getTarget());
480543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Target.isInvalid())
4806f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
48071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
480843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
480943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Target.get() == S->getTarget())
48103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
481143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
481243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
48139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Target.get());
481443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
481543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
481643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
481760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
48193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
482043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
48211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
482243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
482360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
48253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
482643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
48271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
482843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
482960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
483160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = getDerived().TransformExpr(S->getRetValue());
483243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Result.isInvalid())
4833f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
483443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
48351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: We always rebuild the return statement because there is no way
483643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // to tell whether the return type of the function has changed.
48379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
483843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
48391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
484043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
484160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
484343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool DeclChanged = false;
484443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  llvm::SmallVector<Decl *, 4> Decls;
484543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
484643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       D != DEnd; ++D) {
4847aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor    Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4848aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                         *D);
484943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (!Transformed)
4850f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
48511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
485243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Transformed != *D)
485343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      DeclChanged = true;
48541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
485543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Decls.push_back(Transformed);
485643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
48571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
485843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() && !DeclChanged)
48593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
48601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
486243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getStartLoc(), S->getEndLoc());
486343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
48641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
486543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
486660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
486743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
4868c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4869ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Constraints(getSema());
4870ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Exprs(getSema());
4871ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  llvm::SmallVector<IdentifierInfo *, 4> Names;
4872a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson
487360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AsmString;
4874ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Clobbers(getSema());
4875703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4876703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  bool ExprsChanged = false;
4877c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4878703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the outputs.
4879703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
4880ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getOutputIdentifier(I));
4881c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4882703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
48833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getOutputConstraintLiteral(I));
4884c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4885703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the output expr.
4886703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *OutputExpr = S->getOutputExpr(I);
488760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(OutputExpr);
4888703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
4889f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4890c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4891703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != OutputExpr;
4892c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
48939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
4894703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
4895c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4896703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the inputs.
4897703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
4898ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getInputIdentifier(I));
4899c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4900703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
49013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getInputConstraintLiteral(I));
4902c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4903703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the input expr.
4904703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *InputExpr = S->getInputExpr(I);
490560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(InputExpr);
4906703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
4907f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4908c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4909703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != InputExpr;
4910c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
4912703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
4913c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4914703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
49153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4916703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4917703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the clobbers.
4918703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
49193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Clobbers.push_back(S->getClobber(I));
4920703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4921703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // No need to transform the asm string literal.
4922703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  AsmString = SemaRef.Owned(S->getAsmString());
4923703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4924703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4925703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isSimple(),
4926703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isVolatile(),
4927703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumOutputs(),
4928703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumInputs(),
4929a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson                                     Names.data(),
4930703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Constraints),
4931703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Exprs),
49329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     AsmString.get(),
4933703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Clobbers),
4934703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getRParenLoc(),
4935703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isMSAsm());
493643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
493743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
493843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
493943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
494060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
49424dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body of the @try.
494360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
49444dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (TryBody.isInvalid())
4945f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4946c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49478f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  // Transform the @catch statements (if present).
49488f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  bool AnyCatchChanged = false;
4949ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> CatchStmts(SemaRef);
49508f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
495160d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
49524dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Catch.isInvalid())
4953f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
49548f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    if (Catch.get() != S->getCatchStmt(I))
49558f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      AnyCatchChanged = true;
49568f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    CatchStmts.push_back(Catch.release());
49574dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
4958c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49594dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the @finally statement (if present).
496060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Finally;
49614dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (S->getFinallyStmt()) {
49624dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    Finally = getDerived().TransformStmt(S->getFinallyStmt());
49634dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Finally.isInvalid())
4964f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
49654dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
49664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
49674dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
49684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
49694dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      TryBody.get() == S->getTryBody() &&
49708f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      !AnyCatchChanged &&
49714dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Finally.get() == S->getFinallyStmt())
49723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4973c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
49744dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
49759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
49769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           move_arg(CatchStmts), Finally.get());
497743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
497943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
498060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49811eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
4982be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  // Transform the @catch parameter, if there is one.
4983be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *Var = 0;
4984be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (VarDecl *FromVar = S->getCatchParamDecl()) {
4985be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    TypeSourceInfo *TSInfo = 0;
4986be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (FromVar->getTypeSourceInfo()) {
4987be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4988be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (!TSInfo)
4989f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4990be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
4991c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4992be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    QualType T;
4993be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (TSInfo)
4994be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = TSInfo->getType();
4995be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    else {
4996be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = getDerived().TransformType(FromVar->getType());
4997be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (T.isNull())
4998f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4999be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
5000c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5001be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5002be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (!Var)
5003f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5004be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
5005c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
500660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5007be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (Body.isInvalid())
5008f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5009c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5010c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5011be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                             S->getRParenLoc(),
50129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Var, Body.get());
501343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
50141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
501543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
501660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
50184dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body.
501960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
50204dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (Body.isInvalid())
5021f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5022c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50234dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
50244dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
50254dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Body.get() == S->getFinallyBody())
50263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
50274dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
50284dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
50294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
50309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                               Body.get());
503143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
50321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
503343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
503460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
503660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand;
5037d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (S->getThrowExpr()) {
5038d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    Operand = getDerived().TransformExpr(S->getThrowExpr());
5039d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    if (Operand.isInvalid())
5040f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5041d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
5042c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5043d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5044d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor      Operand.get() == S->getThrowExpr())
50453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return getSema().Owned(S);
5046c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
504843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
50491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
505043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
505160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
505243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
50531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCAtSynchronizedStmt *S) {
50548fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the object we are locking.
505560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
50568fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Object.isInvalid())
5057f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5058c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50598fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the body.
506060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
50618fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Body.isInvalid())
5062f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5063c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50648fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // If nothing change, just retain the current statement.
50658fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
50668fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Object.get() == S->getSynchExpr() &&
50678fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Body.get() == S->getSynchBody())
50683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
50698fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor
50708fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Build a new statement.
50718fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
50729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    Object.get(), Body.get());
507343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
507443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
507543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
507660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
507743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt(
50781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCForCollectionStmt *S) {
5079c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the element statement.
508060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Element = getDerived().TransformStmt(S->getElement());
5081c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Element.isInvalid())
5082f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5083c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5084c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the collection expression.
508560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5086c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Collection.isInvalid())
5087f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5088c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5089c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the body.
509060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
5091c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Body.isInvalid())
5092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5093c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5094c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // If nothing changed, just retain this statement.
5095c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
5096c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Element.get() == S->getElement() &&
5097c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Collection.get() == S->getCollection() &&
5098c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Body.get() == S->getBody())
50993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5100c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5101c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Build a new statement.
5102c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5103c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   /*FIXME:*/S->getForLoc(),
51049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Element.get(),
51059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Collection.get(),
5106c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   S->getRParenLoc(),
51079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Body.get());
510843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
510943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
511043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
511143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
511260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
511443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the exception declaration, if any.
511543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  VarDecl *Var = 0;
511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (S->getExceptionDecl()) {
511743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    VarDecl *ExceptionDecl = S->getExceptionDecl();
511883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    TypeSourceInfo *T = getDerived().TransformType(
511983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getTypeSourceInfo());
512083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    if (!T)
5121f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
51221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
512383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
512443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                            ExceptionDecl->getIdentifier(),
512583cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getLocation());
5126ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor    if (!Var || Var->isInvalidDecl())
5127f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
512843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
51291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the actual exception handler.
513160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5132ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor  if (Handler.isInvalid())
5133f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
513643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !Var &&
513743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Handler.get() == S->getHandlerBlock())
51383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
513943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
514043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
514143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          Var,
51429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Handler.get());
514343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
514543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
514660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
514743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
514843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the try block itself.
514960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBlock
515043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    = getDerived().TransformCompoundStmt(S->getTryBlock());
515143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (TryBlock.isInvalid())
5152f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
515443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the handlers.
515543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool HandlerChanged = false;
5156ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Handlers(SemaRef);
515743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
515860d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Handler
515943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      = getDerived().TransformCXXCatchStmt(S->getHandler(I));
516043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Handler.isInvalid())
5161f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
51621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
516343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
516443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Handlers.push_back(Handler.takeAs<Stmt>());
516543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
51661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
516743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
516843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      TryBlock.get() == S->getTryBlock() &&
516943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !HandlerChanged)
51703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
517143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
51729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
51731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        move_arg(Handlers));
517443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
517643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
5177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation
5178577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
51791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
518060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5181454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
51823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
51831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
51841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
518660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5187454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
5188a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *Qualifier = 0;
5189a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (E->getQualifier()) {
5190a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5191edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                       E->getQualifierRange());
5192a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!Qualifier)
5193f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5194a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5195dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5196dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *ND
51977c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
51987c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getDecl()));
5199b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!ND)
5200f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5202ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  DeclarationNameInfo NameInfo = E->getNameInfo();
5203ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  if (NameInfo.getName()) {
5204ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5205ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    if (!NameInfo.getName())
5206f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5207ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  }
52082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
52092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!getDerived().AlwaysRebuild() &&
5210a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      Qualifier == E->getQualifier() &&
5211a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ND == E->getDecl() &&
52122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NameInfo.getName() == E->getDecl()->getDeclName() &&
5213096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
52141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5215dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // Mark it referenced in the new context regardless.
5216dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: this is a bit instantiation-specific.
5217dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5218a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
52193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5220a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5221dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5222dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
5223096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
5224dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TemplateArgs = &TransArgs;
5225dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
5226dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
5227fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5228fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
5229fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
5230fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
5231dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
5232dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5233a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
52342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, TemplateArgs);
5235577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
52361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5237b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
523860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5239454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
52403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5241577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
52421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5243b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
524460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5245454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
52463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
525060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5251454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
52523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5253b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
525660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5257454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
52583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
526260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5263454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
52643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
526860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5269454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
527060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5272f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5274b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
52753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
52761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
5278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       E->getRParen());
5279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
52811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
528260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5283454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
528460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5286f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
52893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
52901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getOpcode(),
52939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get());
5294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
529760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
52988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
52998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform the type.
53008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
53018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!Type)
5302f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5303c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform all of the components into components similar to what the
53058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // parser uses.
5306c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // FIXME: It would be slightly more efficient in the non-dependent case to
5307c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // just map FieldDecls, rather than requiring the rebuilder to look for
5308c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // the fields again. However, __builtin_offsetof is rare enough in
53098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // template code that we don't care.
53108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool ExprChanged = false;
5311f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::OffsetOfComponent Component;
53128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef OffsetOfExpr::OffsetOfNode Node;
53138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  llvm::SmallVector<Component, 4> Components;
53148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
53158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const Node &ON = E->getComponent(I);
53168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Component Comp;
531772be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor    Comp.isBrackets = true;
53188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Comp.LocStart = ON.getRange().getBegin();
53198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Comp.LocEnd = ON.getRange().getEnd();
53208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    switch (ON.getKind()) {
53218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Array: {
53228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
532360d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(FromIndex);
53248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (Index.isInvalid())
5325f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
5326c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      ExprChanged = ExprChanged || Index.get() != FromIndex;
53288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = true;
53299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Comp.U.E = Index.get();
53308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
53318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5332c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Field:
53348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Identifier:
53358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = false;
53368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.U.IdentInfo = ON.getFieldName();
533729d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor      if (!Comp.U.IdentInfo)
533829d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor        continue;
5339c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
5341c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5342cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    case Node::Base:
5343cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      // Will be recomputed during the rebuild.
5344cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      continue;
53458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5346c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Components.push_back(Comp);
53488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
5349c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // If nothing changed, retain the existing expression.
53518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
53528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Type == E->getTypeSourceInfo() &&
53538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      !ExprChanged)
53543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5355c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Build a new offsetof expression.
53578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
53588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          Components.data(), Components.size(),
53598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          E->getRParenLoc());
53607cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}
53617cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
53627cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived>
53637cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult
53647cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
53657cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  assert(getDerived().AlreadyTransformed(E->getType()) &&
53667cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall         "opaque value expression requires transformation");
53677cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  return SemaRef.Owned(E);
53688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
53698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
53708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived>
537160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5372454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
5373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isArgumentType()) {
5374a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *OldT = E->getArgumentTypeInfo();
53755557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor
5376a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *NewT = getDerived().TransformType(OldT);
53775ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!NewT)
5378f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53805ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!getDerived().AlwaysRebuild() && OldT == NewT)
53813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
53821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53835ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
53841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             E->isSizeOf(),
5385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getSourceRange());
5386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
53871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
538860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr;
53891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  {
5390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // C++0x [expr.sizeof]p1:
5391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   The operand is either an expression, which is an unevaluated operand
5392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   [...]
5393f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
53941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
5397f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
54003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
5401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
54021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
5404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isSizeOf(),
5405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getSourceRange());
5406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
540960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5410454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
541160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5413f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
541560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5417f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
54233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
54241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
5426b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           /*FIXME:*/E->getLHS()->getLocStart(),
54279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                RHS.get(),
5428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getRBracketLoc());
5429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
543260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5433454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
5434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the callee.
543560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
5437f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform arguments.
5440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgChanged = false;
5441ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
5442aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5443aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
5444aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
5445aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
5446b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5447b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
5448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgChanged)
54493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
54501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5451b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Wrong source location information for the '('.
54521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLParenLoc
5453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = ((Expr *)Callee.get())->getSourceRange().getBegin();
54549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
5455b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      move_arg(Args),
5456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
5457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
546060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5461454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
546260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
5463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
5464f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
546683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  NestedNameSpecifier *Qualifier = 0;
546783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (E->hasQualifier()) {
54681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Qualifier
546983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5470edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  E->getQualifierRange());
5471c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (Qualifier == 0)
5472f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
547383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
54741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5475f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *Member
54767c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
54777c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getMemberDecl()));
5478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Member)
5479f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54816bb8017bb9e828d118e15e59d71c66bba323c364John McCall  NamedDecl *FoundDecl = E->getFoundDecl();
54826bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (FoundDecl == E->getMemberDecl()) {
54836bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = Member;
54846bb8017bb9e828d118e15e59d71c66bba323c364John McCall  } else {
54856bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = cast_or_null<NamedDecl>(
54866bb8017bb9e828d118e15e59d71c66bba323c364John McCall                   getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
54876bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!FoundDecl)
5488f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
54896bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
54906bb8017bb9e828d118e15e59d71c66bba323c364John McCall
5491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase() &&
549383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      Qualifier == E->getQualifier() &&
54948a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor      Member == E->getMemberDecl() &&
54956bb8017bb9e828d118e15e59d71c66bba323c364John McCall      FoundDecl == E->getFoundDecl() &&
5496096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
5497c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54981f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // Mark it referenced in the new context regardless.
54991f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // FIXME: this is a bit instantiation-specific.
55001f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
55013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
55021f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson  }
5503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5504d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs;
5505096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
5506d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
5507d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
5508fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5509fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
5510fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
5511fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
55128a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor  }
5513c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bogus source location for the operator
5515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeOperatorLoc
5516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5518c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
5519c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
5520c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
5521c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
5522c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
5523c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
55249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
5525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isArrow(),
552683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                        Qualifier,
552783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                        E->getQualifierRange(),
55282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                        E->getMemberNameInfo(),
55298a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor                                        Member,
55306bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        FoundDecl,
5531096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                        (E->hasExplicitTemplateArgs()
5532d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                           ? &TransArgs : 0),
5533c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                        FirstQualifierInScope);
5534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
55351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
553760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5538454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
553960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5541f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
554360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5545f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
55503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
55511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
55539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            LHS.get(), RHS.get());
5554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
55561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
555760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator(
5559454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CompoundAssignOperator *E) {
5560454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformBinaryOperator(E);
5561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
55621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
556456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>::
556556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
556656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // Just rebuild the common and RHS expressions and see whether we
556756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // get any changes.
556856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
556956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
557056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (commonExpr.isInvalid())
557156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
557256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
557356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
557456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (rhs.isInvalid())
557556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
557656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
557756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (!getDerived().AlwaysRebuild() &&
557856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      commonExpr.get() == e->getCommon() &&
557956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      rhs.get() == e->getFalseExpr())
558056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return SemaRef.Owned(e);
558156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
558256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  return getDerived().RebuildConditionalOperator(commonExpr.take(),
558356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getQuestionLoc(),
558456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 0,
558556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getColonLoc(),
558656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 rhs.get());
558756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}
558856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
558956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived>
559060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5591454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
559260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
5593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
5594f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
559660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5598f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
560060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
5606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
56083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
56091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildConditionalOperator(Cond.get(),
561147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getQuestionLoc(),
56129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 LHS.get(),
561347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getColonLoc(),
56149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 RHS.get());
5615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
561860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5619454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
5620a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // Implicit casts are eliminated during transformation, since they
5621a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // will be recomputed by semantic analysis after transformation.
56226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return getDerived().TransformExpr(E->getSubExprAsWritten());
5623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
562660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5627454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
5628ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5629ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
5630ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
5631ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
563260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
56336eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
5634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5635f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5638ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
5639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
56403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
56411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56429d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
5643ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                            Type,
5644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc(),
56459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            SubExpr.get());
5646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
564960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5650454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
565142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *OldT = E->getTypeSourceInfo();
565242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
565342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  if (!NewT)
5654f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
565660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
5657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
5658f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
566142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      OldT == NewT &&
5662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInitializer())
56633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
56651d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // Note: the expression type doesn't necessarily match the
56661d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // type-as-written, but that's okay, because it should always be
56671d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // derivable from the initializer.
56681d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
566942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
5670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   /*FIXME:*/E->getInitializer()->getLocEnd(),
56719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Init.get());
5672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
567560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5676454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
567760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
5678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
5679f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase())
56833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
56841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bad source location
56861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeOperatorLoc
5687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
56889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
5689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessorLoc(),
5690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessor());
5691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
569460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5695454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
5696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool InitChanged = false;
56971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5698ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
5699aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5700aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  Inits, &InitChanged))
5701aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
5702aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
5703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && !InitChanged)
57043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
57051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
5707e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                      E->getRBraceLoc(), E->getType());
5708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
571160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5712454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
5713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Designation Desig;
57141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
571543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the initializer value
571660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInit());
5717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
5718f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
572043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the designators.
5721ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
5722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ExprChanged = false;
5723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             DEnd = E->designators_end();
5725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       D != DEnd; ++D) {
5726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isFieldDesignator()) {
5727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Desig.AddDesignator(Designator::getField(D->getFieldName(),
5728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getDotLoc(),
5729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getFieldLoc()));
5730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
5731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
57321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isArrayDesignator()) {
573460d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
5735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Index.isInvalid())
5736f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
57371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Desig.AddDesignator(Designator::getArray(Index.get(),
5739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getLBracketLoc()));
57401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArrayExprs.push_back(Index.release());
5743b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
5744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
57451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(D->isArrayRangeDesignator() && "New kind of designator?");
574760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Start
5748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Start.isInvalid())
5750f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
57511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
575260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
5753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (End.isInvalid())
5754f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
57551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Desig.AddDesignator(Designator::getArrayRange(Start.get(),
5757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  End.get(),
5758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getLBracketLoc(),
5759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getEllipsisLoc()));
57601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      End.get() != E->getArrayRangeEnd(*D);
57631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(Start.release());
5765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(End.release());
5766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
57671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInit() &&
5770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ExprChanged)
57713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
57721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getEqualOrColonLoc(),
57759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                E->usesGNUSyntax(), Init.get());
5776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
577960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr(
5781454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     ImplicitValueInitExpr *E) {
57825557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5783c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
57845557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // FIXME: Will we ever have proper type location here? Will we actually
57855557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // need to transform the type?
5786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
5787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
5788f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType())
57923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
57931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildImplicitValueInitExpr(T);
5795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
579860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5799454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
58009bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
58019bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo)
5802f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
580460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5806f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
58092cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      TInfo == E->getWrittenTypeInfo() &&
5810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
58113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
58142cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                       TInfo, E->getRParenLoc());
5815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
581860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5819454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
5820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5821ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
5822aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5823aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
5824aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
5825aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
5826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           move_arg(Inits),
5828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getRParenLoc());
5829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression.
5832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
5833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always
5834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to
5835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis.
5836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
583760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5838454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
583957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
584057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        E->getLabel());
584157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
584257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return ExprError();
584357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
5844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
584557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                           cast<LabelDecl>(LD));
5846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
584960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5850454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
585160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt
5852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubStmt.isInvalid())
5854f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubStmt.get() == E->getSubStmt())
58583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
58619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      SubStmt.get(),
5862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
5863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
586660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5867454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
586860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
5869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
5870f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
587260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
5873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
5874f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
587660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
5877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
5878f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5880b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
5882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
5883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
58843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
58879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Cond.get(), LHS.get(), RHS.get(),
5888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->getRParenLoc());
5889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
589260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5893454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
58943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
589860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5899454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
5900668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  switch (E->getOperator()) {
5901668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_New:
5902668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Delete:
5903668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_New:
5904668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_Delete:
5905668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
5906f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5907c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5908668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Call: {
5909668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // This is a call to an object's operator().
5910668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5911668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5912668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the object itself.
591360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Object = getDerived().TransformExpr(E->getArg(0));
5914668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    if (Object.isInvalid())
5915f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5916668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5917668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // FIXME: Poor location information
5918668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    SourceLocation FakeLParenLoc
5919668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      = SemaRef.PP.getLocForEndOfToken(
5920668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                              static_cast<Expr *>(Object.get())->getLocEnd());
5921668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5922668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the call arguments.
5923ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> Args(SemaRef);
5924aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5925aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                    Args))
5926aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return ExprError();
5927668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
59289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
5929668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        move_arg(Args),
5930668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        E->getLocEnd());
5931668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
5932668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5933668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5934668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_##Name:
5935668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5936668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def"
5937668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Subscript:
5938668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Handled below.
5939668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    break;
5940668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5941668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Conditional:
5942668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("conditional operator is not actually overloadable");
5943f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5944668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5945668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_None:
5946668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case NUM_OVERLOADED_OPERATORS:
5947668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("not an overloaded operator?");
5948f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5949668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
5950668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
595160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
5953f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
595560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult First = getDerived().TransformExpr(E->getArg(0));
5956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (First.isInvalid())
5957f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
595960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Second;
5960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->getNumArgs() == 2) {
5961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Second = getDerived().TransformExpr(E->getArg(1));
5962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Second.isInvalid())
5963f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
59651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
5968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      First.get() == E->getArg(0) &&
59691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
59703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
59711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 E->getOperatorLoc(),
59749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Callee.get(),
59759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 First.get(),
59769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Second.get());
5977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
598060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5981454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5982454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCallExpr(E);
5983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
5986e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult
5987e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
5988e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform the callee.
5989e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5990e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (Callee.isInvalid())
5991e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
5992e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
5993e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform exec config.
5994e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
5995e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (EC.isInvalid())
5996e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
5997e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
5998e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform arguments.
5999e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  bool ArgChanged = false;
6000e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ASTOwningVector<Expr*> Args(SemaRef);
6001e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6002e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                  &ArgChanged))
6003e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6004e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6005e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (!getDerived().AlwaysRebuild() &&
6006e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      Callee.get() == E->getCallee() &&
6007e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      !ArgChanged)
6008e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return SemaRef.Owned(E);
6009e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6010e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // FIXME: Wrong source location information for the '('.
6011e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  SourceLocation FakeLParenLoc
6012e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    = ((Expr *)Callee.get())->getSourceRange().getBegin();
6013e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6014e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      move_arg(Args),
6015e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      E->getRParenLoc(), EC.get());
6016e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}
6017e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6018e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived>
601960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6020454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
6021ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6022ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6023ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
6024ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
602560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
60266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6028f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6031ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
60333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Poor source location information here.
60361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLAngleLoc
6037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRParenLoc
6040b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(
6041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  E->getSubExpr()->getSourceRange().getEnd());
6042b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
60431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              E->getStmtClass(),
6044b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeLAngleLoc,
6045ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                              Type,
6046b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
6047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
60489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              SubExpr.get(),
6049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRParenLoc);
6050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
605360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6054454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6055454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
605960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6060454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6061454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6062b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
606560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr(
6067454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CXXReinterpretCastExpr *E) {
6068454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6071b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
607260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6073454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6074454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6075b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6077b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
607860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr(
6080454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXFunctionalCastExpr *E) {
6081ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6082ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6083ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
60841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
608560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
60866eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6088f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6091ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
60933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6095ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  return getDerived().RebuildCXXFunctionalCastExpr(Type,
6096b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      /*FIXME:*/E->getSubExpr()->getLocStart(),
60979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr.get(),
6098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   E->getRParenLoc());
6099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
610260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6103454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
6104b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isTypeOperand()) {
610557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    TypeSourceInfo *TInfo
610657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      = getDerived().TransformType(E->getTypeOperandSourceInfo());
610757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    if (!TInfo)
6108f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
61091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
611157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        TInfo == E->getTypeOperandSourceInfo())
61123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
61131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
611457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return getDerived().RebuildCXXTypeidExpr(E->getType(),
611557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             E->getLocStart(),
611657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             TInfo,
6117b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getLocEnd());
6118b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
61191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // We don't know whether the expression is potentially evaluated until
6121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // after we perform semantic analysis, so the expression is potentially
6122b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // potentially evaluated.
61231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  EnterExpressionEvaluationContext Unevaluated(SemaRef,
6124f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      Sema::PotentiallyPotentiallyEvaluated);
61251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
612660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6128f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getExprOperand())
61323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
613457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  return getDerived().RebuildCXXTypeidExpr(E->getType(),
613557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                           E->getLocStart(),
61369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get(),
6137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLocEnd());
6138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
614160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
614201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
614301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (E->isTypeOperand()) {
614401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    TypeSourceInfo *TInfo
614501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      = getDerived().TransformType(E->getTypeOperandSourceInfo());
614601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!TInfo)
614701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      return ExprError();
614801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
614901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!getDerived().AlwaysRebuild() &&
615001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet        TInfo == E->getTypeOperandSourceInfo())
61513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
615201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
615301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getDerived().RebuildCXXTypeidExpr(E->getType(),
615401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocStart(),
615501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             TInfo,
615601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocEnd());
615701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
615801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
615901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // We don't know whether the expression is potentially evaluated until
616001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // after we perform semantic analysis, so the expression is potentially
616101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // potentially evaluated.
616201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
616301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
616401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
616501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (SubExpr.isInvalid())
616601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return ExprError();
616701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
616801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (!getDerived().AlwaysRebuild() &&
616901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      SubExpr.get() == E->getExprOperand())
61703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
617101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
617201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  return getDerived().RebuildCXXUuidofExpr(E->getType(),
617301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocStart(),
617401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           SubExpr.get(),
617501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocEnd());
617601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}
617701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
617801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived>
617901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult
6180454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
61813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
618560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
6187454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXNullPtrLiteralExpr *E) {
61883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
619260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6193454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
6194ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  DeclContext *DC = getSema().getFunctionLevelDeclContext();
6195ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6196ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  QualType T = MD->getThisType(getSema().Context);
61971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6198ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!getDerived().AlwaysRebuild() && T == E->getType())
61993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6201828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
6202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6204b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
620560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6206454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
620760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6208b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6209f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6212b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
62133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
6216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6218b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
621960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6220454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
62211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParmVarDecl *Param
62227c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
62237c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           E->getParam()));
6224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Param)
6225f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
622753cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth  if (!getDerived().AlwaysRebuild() &&
6228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Param == E->getParam())
62293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6231036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
6232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
623560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6236ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6237ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXScalarValueInitExpr *E) {
6238ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6239ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6240f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6241ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
6242b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6243ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo())
62443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6246ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXScalarValueInitExpr(T,
6247ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
6248ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor                                                    E->getRParenLoc());
6249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6251b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
625260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6253454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
6254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the type that we're allocating
62551bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocTypeInfo
62561bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
62571bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  if (!AllocTypeInfo)
6258f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the size of the array we're allocating (if any).
626160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
6262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (ArraySize.isInvalid())
6263f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the placement arguments (if any).
6266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6267ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> PlacementArgs(SemaRef);
6268aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getPlacementArgs(),
6269aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  E->getNumPlacementArgs(), true,
6270aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  PlacementArgs, &ArgumentChanged))
6271aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
62721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
627343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the constructor arguments (if any).
6274ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
6275aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6276aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     ConstructorArgs, &ArgumentChanged))
6277aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
62781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform constructor, new operator, and delete operator.
62801af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  CXXConstructorDecl *Constructor = 0;
62811af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getConstructor()) {
62821af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    Constructor = cast_or_null<CXXConstructorDecl>(
62837c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
62847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
62851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!Constructor)
6286f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
62871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
62881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
62891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorNew = 0;
62901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorNew()) {
62911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorNew = cast_or_null<FunctionDecl>(
62927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(E->getLocStart(),
62937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getOperatorNew()));
62941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorNew)
6295f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
62961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
62971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
62981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
62991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
63001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
63017c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
63027c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
63031af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6304f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63051af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6306c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
63081bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor      AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
6309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArraySize.get() == E->getArraySize() &&
63101af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Constructor == E->getConstructor() &&
63111af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorNew == E->getOperatorNew() &&
63121af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete() &&
63131af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      !ArgumentChanged) {
63141af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
63151af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
63161af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (Constructor)
63171af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
63181af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorNew)
63191af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
63201af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
63211af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
63223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63231af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
63241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63251bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  QualType AllocType = AllocTypeInfo->getType();
63265b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  if (!ArraySize.get()) {
63275b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // If no array size was specified, but the new expression was
63285b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with an array type (e.g., "new T" where T is
63295b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with "int[4]"), extract the outer bound from the
63305b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // array type as our array size. We do this with constant and
63315b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // dependently-sized array types.
63325b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
63335b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    if (!ArrayT) {
63345b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      // Do nothing
63355b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const ConstantArrayType *ConsArrayT
63365b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                                     = dyn_cast<ConstantArrayType>(ArrayT)) {
6337c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      ArraySize
63389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
63399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               ConsArrayT->getSize(),
63409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               SemaRef.Context.getSizeType(),
63419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               /*FIXME:*/E->getLocStart()));
63425b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      AllocType = ConsArrayT->getElementType();
63435b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const DependentSizedArrayType *DepArrayT
63445b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                              = dyn_cast<DependentSizedArrayType>(ArrayT)) {
63455b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      if (DepArrayT->getSizeExpr()) {
63463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall        ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
63475b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor        AllocType = DepArrayT->getElementType();
63485b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      }
63495b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    }
63505b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  }
63511bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
6352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isGlobalNew(),
6354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
6355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(PlacementArgs),
6356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
63574bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                        E->getTypeIdParens(),
6358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        AllocType,
63591bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                        AllocTypeInfo,
63609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        ArraySize.get(),
6361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
6362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(ConstructorArgs),
63631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        E->getLocEnd());
6364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
636760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6368454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
636960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
6370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Operand.isInvalid())
6371f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform the delete operator, if known.
63741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
63751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
63761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
63777c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
63787c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
63791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6380f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63811af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6382c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
63841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Operand.get() == E->getArgument() &&
63851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete()) {
63861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
63871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
63881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
63891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
63905833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
63915833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    if (!E->getArgument()->isTypeDependent()) {
63925833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      QualType Destroyed = SemaRef.Context.getBaseElementType(
63935833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                                         E->getDestroyedType());
63945833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
63955833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
63965833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        SemaRef.MarkDeclarationReferenced(E->getLocStart(),
63975833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                          SemaRef.LookupDestructor(Record));
63985833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      }
63995833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    }
64005833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
64013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
64031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isGlobalDelete(),
6406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isArrayForm(),
64079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Operand.get());
6408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
641160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6412a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
6413454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXPseudoDestructorExpr *E) {
641460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6415a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  if (Base.isInvalid())
6416f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6418b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ObjectTypePtr;
6419a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  bool MayBePseudoDestructor = false;
64209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
6421a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              E->getOperatorLoc(),
6422a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        E->isArrow()? tok::arrow : tok::period,
6423a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              ObjectTypePtr,
6424a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              MayBePseudoDestructor);
6425a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (Base.isInvalid())
6426f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6427c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6428b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  QualType ObjectType = ObjectTypePtr.get();
642943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  NestedNameSpecifier *Qualifier = E->getQualifier();
643043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Qualifier) {
643143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Qualifier
643243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
643343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  E->getQualifierRange(),
643443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  ObjectType);
643543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (!Qualifier)
643643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      return ExprError();
643743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
64381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6439a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage Destroyed;
6440a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (E->getDestroyedTypeInfo()) {
6441a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    TypeSourceInfo *DestroyedTypeInfo
644243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
644343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjectType, 0, Qualifier);
6444a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!DestroyedTypeInfo)
6445f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6446a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = DestroyedTypeInfo;
6447a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else if (ObjectType->isDependentType()) {
6448a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // We aren't likely to be able to resolve the identifier down to a type
6449a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // now anyway, so just retain the identifier.
6450a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6451a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                            E->getDestroyedTypeLoc());
6452a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else {
6453a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // Look for a destructor known with the given name.
6454a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    CXXScopeSpec SS;
6455a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (Qualifier) {
6456a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      SS.setScopeRep(Qualifier);
6457a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      SS.setRange(E->getQualifierRange());
6458a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    }
6459c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6460b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
6461a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              *E->getDestroyedTypeIdentifier(),
6462a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                E->getDestroyedTypeLoc(),
6463a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                /*Scope=*/0,
6464a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                SS, ObjectTypePtr,
6465a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                false);
6466a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!T)
6467f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6468c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6469a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed
6470a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6471a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                 E->getDestroyedTypeLoc());
6472a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
647326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
647426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *ScopeTypeInfo = 0;
647526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (E->getScopeTypeInfo()) {
647643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
647726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    if (!ScopeTypeInfo)
6478f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6479a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
6480c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
64819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
6482a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->getOperatorLoc(),
6483a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->isArrow(),
6484a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     Qualifier,
648526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getQualifierRange(),
648626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     ScopeTypeInfo,
648726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getColonColonLoc(),
6488fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                     E->getTildeLoc(),
6489a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                     Destroyed);
6490a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}
64911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6492a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived>
649360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6494ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr(
6495454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  UnresolvedLookupExpr *Old) {
6496f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6497f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6498f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6499f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                 Sema::LookupOrdinaryName);
6500f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6501f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Transform all the decls.
6502f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6503f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall         E = Old->decls_end(); I != E; ++I) {
65047c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
65057c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(Old->getNameLoc(),
65067c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                            *I));
65079f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
65089f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
65099f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
65109f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
65119f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
65129f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
6513f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
65149f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
6515f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6516f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // Expand using declarations.
6517f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (isa<UsingDecl>(InstD)) {
6518f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
6519f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6520f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall             E = UD->shadow_end(); I != E; ++I)
6521f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        R.addDecl(*I);
6522f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      continue;
6523f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    }
6524f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6525f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    R.addDecl(InstD);
6526f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
6527f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6528f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Resolve a kind, but don't do any further analysis.  If it's
6529f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // ambiguous, the callee needs to deal with it.
6530f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  R.resolveKind();
6531f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6532f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Rebuild the nested-name qualifier, if present.
6533f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  CXXScopeSpec SS;
6534f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  NestedNameSpecifier *Qualifier = 0;
6535f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (Old->getQualifier()) {
6536f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
6537edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                    Old->getQualifierRange());
6538f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!Qualifier)
6539f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6540c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6541f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SS.setScopeRep(Qualifier);
6542f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SS.setRange(Old->getQualifierRange());
6543c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
6544c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6545c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (Old->getNamingClass()) {
654666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    CXXRecordDecl *NamingClass
654766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
654866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                            Old->getNameLoc(),
654966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
655066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
6551f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6552c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
655366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
6554f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
6555f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6556f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have no template arguments, it's a normal declaration name.
6557f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!Old->hasExplicitTemplateArgs())
6558f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6559f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6560f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have template arguments, rebuild them, then rebuild the
6561f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // templateid expression.
6562f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
6563fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6564fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              Old->getNumTemplateArgs(),
6565fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
6566fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
6567f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
6568f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6569f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                            TransArgs);
6570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
657360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6574454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
65753d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
65763d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  if (!T)
6577f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
65803d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      T == E->getQueriedTypeSourceInfo())
65813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
65821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
65831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
6584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocStart(),
6585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            T,
6586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocEnd());
6587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
659060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
65916ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
65926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
65936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!LhsT)
65946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
65956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
65966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
65976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!RhsT)
65986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
65996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
66006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!getDerived().AlwaysRebuild() &&
66016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
66026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SemaRef.Owned(E);
66036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
66046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
66056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocStart(),
66066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            LhsT, RhsT,
66076ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocEnd());
66086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}
66096ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
66106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived>
66116ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult
6612865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
66132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                               DependentScopeDeclRefExpr *E) {
6614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  NestedNameSpecifier *NNS
6615f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor    = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6616edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                E->getQualifierRange());
6617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!NNS)
6618f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
662043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
662143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
662243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
662343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
66242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
66252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
66262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
6627f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6629f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!E->hasExplicitTemplateArgs()) {
6630f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!getDerived().AlwaysRebuild() &&
6631f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        NNS == E->getQualifier() &&
66322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // Note: it is sufficient to compare the Name component of NameInfo:
66332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // if name has not changed, DNLoc has not changed either.
66342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getDeclName())
66353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
66361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6637f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6638f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         E->getQualifierRange(),
66392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                         NameInfo,
6640f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         /*TemplateArgs*/ 0);
6641f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor  }
6642d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
6643d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
6644fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6645fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
6646fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
6647fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
6648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6649f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6650f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       E->getQualifierRange(),
66512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
6652f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       &TransArgs);
6653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
665660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6657454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
6658321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // CXXConstructExprs are always implicit, so when we have a
6659321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // 1-argument construction we just transform that argument.
6660321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  if (E->getNumArgs() == 1 ||
6661321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor      (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6662321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor    return getDerived().TransformExpr(E->getArg(0));
6663321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor
6664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
6667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
6668f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
6671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
66727c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(E->getLocStart(),
66737c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
6674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
6675f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6678ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6679aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6680aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
6681aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6682aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType() &&
6685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
6686c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor      !ArgumentChanged) {
66871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark the constructor as referenced.
66881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: Instantiation-specific
6689c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
66903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6691c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor  }
66921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66934411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
66944411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                              Constructor, E->isElidable(),
66958c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              move_arg(Args),
66968c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              E->requiresZeroInitialization(),
6697428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getConstructionKind(),
6698428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getParenRange());
6699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression.
6702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
67035132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
67045132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that.
6705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
670660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6707454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
67085132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
6709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67114765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should
67124765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated.
6713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
67144765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we
67155132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that.
6716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
671760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
67184765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
67195132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
6720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
672360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
6725ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXTemporaryObjectExpr *E) {
6726ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6727ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6728f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
6731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
6732c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                  getDerived().TransformDecl(E->getLocStart(),
67337c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
6734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
6735f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6738ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Args.reserve(E->getNumArgs());
6740aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6741aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
6742aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
67431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6745ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
6746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
674791be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      !ArgumentChanged) {
674891be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    // FIXME: Instantiation-specific
6749ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
67503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.MaybeBindToTemporary(E);
675191be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor  }
6752ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
6753ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXTemporaryObjectExpr(T,
6754ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
6755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    move_arg(Args),
6756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    E->getLocEnd());
6757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
676060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
6762454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  CXXUnresolvedConstructExpr *E) {
6763ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6764ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6765f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6768ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6769aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->arg_size());
6770aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6771aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
6772aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6773aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6775ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
6776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
67773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: we're faking the locations of the commas
6780ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
6781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getLParenLoc(),
6782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        move_arg(Args),
6783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getRParenLoc());
6784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
678760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6788865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
67892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                             CXXDependentScopeMemberExpr *E) {
6790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the base of the expression.
679160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
6792aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *OldBase;
6793aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
6794aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType ObjectType;
6795aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->isImplicitAccess()) {
6796aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = E->getBase();
6797aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(OldBase);
6798aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
6799f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6801aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    // Start the member reference and compute the object's type.
6802b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ObjectTy;
6803d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor    bool MayBePseudoDestructor = false;
68049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
6805aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                E->getOperatorLoc(),
6806a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                      E->isArrow()? tok::arrow : tok::period,
6807d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                ObjectTy,
6808d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                MayBePseudoDestructor);
6809aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
6810f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6811aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
6812b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ObjectType = ObjectTy.get();
6813aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
6814aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
6815aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = 0;
6816aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(E->getBaseType());
6817aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6818aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
68191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68206cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // Transform the first part of the nested-name-specifier that qualifies
68216cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // the member name.
6822c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierInScope
68236cd219879ffce00920189ec1dcea927a42602961Douglas Gregor    = getDerived().TransformFirstQualifierInScope(
68246cd219879ffce00920189ec1dcea927a42602961Douglas Gregor                                          E->getFirstQualifierFoundInScope(),
68256cd219879ffce00920189ec1dcea927a42602961Douglas Gregor                                          E->getQualifierRange().getBegin());
68261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6827a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  NestedNameSpecifier *Qualifier = 0;
6828a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  if (E->getQualifier()) {
6829a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6830a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                      E->getQualifierRange(),
6831aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                      ObjectType,
6832aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                      FirstQualifierInScope);
6833a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    if (!Qualifier)
6834f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6835a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  }
68361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
683743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
683843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
683943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
684043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
68412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
684243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
68432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
6844f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6846aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->hasExplicitTemplateArgs()) {
68473b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // This is a reference to a member without an explicitly-specified
68483b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // template argument list. Optimize for this common case.
68493b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
6850aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        Base.get() == OldBase &&
6851aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        BaseType == E->getBaseType() &&
68523b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        Qualifier == E->getQualifier() &&
68532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getMember() &&
68543b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        FirstQualifierInScope == E->getFirstQualifierFoundInScope())
68553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
68561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
6858aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                       BaseType,
68593b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->isArrow(),
68603b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getOperatorLoc(),
68613b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       Qualifier,
68623b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getQualifierRange(),
6863129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       FirstQualifierInScope,
68642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
6865129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       /*TemplateArgs*/ 0);
68663b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
68673b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor
6868d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
6869fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6870fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
6871fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
6872fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
68731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
6875aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                     BaseType,
6876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->isArrow(),
6877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->getOperatorLoc(),
6878a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     Qualifier,
6879a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     E->getQualifierRange(),
68803b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                     FirstQualifierInScope,
68812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                     NameInfo,
6882129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                     &TransArgs);
6883129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}
6884129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6885129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived>
688660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6887454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
6888129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform the base of the expression.
688960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
6890aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
6891aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!Old->isImplicitAccess()) {
6892aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(Old->getBase());
6893aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
6894f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6895aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
6896aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
6897aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(Old->getBaseType());
6898aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
6899129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6900129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  NestedNameSpecifier *Qualifier = 0;
6901129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->getQualifier()) {
6902129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    Qualifier
6903129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
6904edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  Old->getQualifierRange());
6905129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (Qualifier == 0)
6906f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6907129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6908129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
69092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  LookupResult R(SemaRef, Old->getMemberNameInfo(),
6910129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                 Sema::LookupOrdinaryName);
6911129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6912129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform all the decls.
6913129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6914129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         E = Old->decls_end(); I != E; ++I) {
69157c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
69167c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(Old->getMemberLoc(),
69177c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           *I));
69189f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
69199f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
69209f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
69219f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
69229f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
69239f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
6924f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
69259f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
6926129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6927129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    // Expand using declarations.
6928129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (isa<UsingDecl>(InstD)) {
6929129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
6930129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6931129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall             E = UD->shadow_end(); I != E; ++I)
6932129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall        R.addDecl(*I);
6933129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      continue;
6934129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
6935129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6936129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    R.addDecl(InstD);
6937129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6938129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6939129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  R.resolveKind();
6940129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6941c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  // Determine the naming class.
6942042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth  if (Old->getNamingClass()) {
6943c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    CXXRecordDecl *NamingClass
6944c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
694566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                          Old->getMemberLoc(),
694666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
694766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
6948f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6949c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
695066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
6951c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  }
6952c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6953129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  TemplateArgumentListInfo TransArgs;
6954129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->hasExplicitTemplateArgs()) {
6955129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setLAngleLoc(Old->getLAngleLoc());
6956129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setRAngleLoc(Old->getRAngleLoc());
6957fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6958fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                Old->getNumTemplateArgs(),
6959fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
6960fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
6961129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6962c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
6963c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
6964c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
6965c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
6966c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
6967c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
6968c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
69699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
6970aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  BaseType,
6971129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getOperatorLoc(),
6972129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->isArrow(),
6973129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Qualifier,
6974129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getQualifierRange(),
6975c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                                  FirstQualifierInScope,
6976129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  R,
6977129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              (Old->hasExplicitTemplateArgs()
6978129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  ? &TransArgs : 0));
6979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
698260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
69832e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
69842e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
69852e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (SubExpr.isInvalid())
69862e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return ExprError();
69872e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
69882e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
69893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
69902e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
69912e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
69922e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}
69932e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
69942e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived>
69952e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult
6996be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
69974f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
69984f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (Pattern.isInvalid())
69994f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return ExprError();
70004f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
70014f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
70024f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return SemaRef.Owned(E);
70034f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
700467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
700567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                           E->getNumExpansions());
7006be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}
7007ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7008ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived>
7009ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult
7010ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7011ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // If E is not value-dependent, then nothing will change when we transform it.
7012ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: This is an instantiation-centric view.
7013ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (!E->isValueDependent())
7014ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
7015ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7016ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: None of the implementations of TryExpandParameterPacks can ever
7017ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // produce a diagnostic when given only a single unexpanded parameter pack,
7018ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // so
7019ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7020ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  bool ShouldExpand = false;
7021d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  bool RetainExpansion = false;
7022cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> NumExpansions;
7023ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7024ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                           &Unexpanded, 1,
7025d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           ShouldExpand, RetainExpansion,
7026d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           NumExpansions))
7027ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return ExprError();
7028ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7029d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  if (!ShouldExpand || RetainExpansion)
7030ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
7031be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
7032ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // We now know the length of the parameter pack, so build a new expression
7033ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // that stores that length.
7034ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7035ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                            E->getPackLoc(), E->getRParenLoc(),
7036cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                            *NumExpansions);
7037ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}
7038ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7039be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived>
7040be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult
7041c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7042c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                          SubstNonTypeTemplateParmPackExpr *E) {
7043c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Default behavior is to do nothing with this transformation.
7044c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  return SemaRef.Owned(E);
7045c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}
7046c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
7047c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived>
7048c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult
7049454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
70503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7051b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
70531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
705460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7055454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
705681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  TypeSourceInfo *EncodedTypeInfo
705781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
705881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  if (!EncodedTypeInfo)
7059f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
70601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
706281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
70633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7065b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
706681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                            EncodedTypeInfo,
7067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc());
7068b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
70691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
707160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7072454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
707392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Transform arguments.
707492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  bool ArgChanged = false;
7075ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7076aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->getNumArgs());
7077aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7078aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
7079aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7080aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
708192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
708292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Class message: transform the receiver type.
708392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    TypeSourceInfo *ReceiverTypeInfo
708492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      = getDerived().TransformType(E->getClassReceiverTypeInfo());
708592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!ReceiverTypeInfo)
7086f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7087c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
708892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // If nothing changed, just retain the existing message send.
708992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
709092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor        ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
70913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
709292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
709392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Build a new class message send.
709492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
709592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getSelector(),
7096f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                               E->getSelectorLoc(),
709792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getMethodDecl(),
709892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getLeftLoc(),
709992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               move_arg(Args),
710092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getRightLoc());
710192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
710292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
710392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Instance message: transform the receiver
710492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
710592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         "Only class and instance messages may be instantiated");
710660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Receiver
710792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    = getDerived().TransformExpr(E->getInstanceReceiver());
710892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (Receiver.isInvalid())
7109f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
711092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
711192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // If nothing changed, just retain the existing message send.
711292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
711392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
71143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7115c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
711692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Build a new instance message send.
71179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
711892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getSelector(),
7119f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                             E->getSelectorLoc(),
712092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getMethodDecl(),
712192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getLeftLoc(),
712292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             move_arg(Args),
712392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getRightLoc());
7124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
71261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
712760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7128454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
71293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
71321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
713360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7134454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
71353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
71381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
713960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7140454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
7141f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
714260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7143f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7144f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7145f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor
7146f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // We don't need to transform the ivar; it will never change.
7147c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7148f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7149f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7150f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
71513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7152c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
71539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
7154f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->getLocation(),
7155f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->isArrow(), E->isFreeIvar());
7156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
71581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
715960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7160454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
716112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // 'super' and types never change. Property never changes. Just
716212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // retain the existing expression.
716312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (!E->isObjectReceiver())
71643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
71658ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian
7166e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // Transform the base expression.
716760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7168e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (Base.isInvalid())
7169f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7170c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7171e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // We don't need to transform the property; it will never change.
7172c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7173e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // If nothing changed, just retain the existing expression.
7174e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7175e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      Base.get() == E->getBase())
71763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
717812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (E->isExplicitProperty())
717912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
718012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getExplicitProperty(),
718112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getLocation());
718212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall
718312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
718412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getType(),
718512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertyGetter(),
718612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertySetter(),
718712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getLocation());
7188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
71901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
719160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7192454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
7193f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
719460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7195f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7196f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7197c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7198f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7199f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7200f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
72013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7202c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
72039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
7204f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                         E->isArrow());
7205b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
72071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
720860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7209454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
7210b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7211ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> SubExprs(SemaRef);
7212aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  SubExprs.reserve(E->getNumSubExprs());
7213aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7214aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  SubExprs, &ArgumentChanged))
7215aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
72161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7218b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
72193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
72201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7222b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move_arg(SubExprs),
7223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               E->getRParenLoc());
7224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
72261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
722760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7228454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
7229c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockDecl *oldBlock = E->getBlockDecl();
7230a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7231c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7232c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7233c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7234c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7235c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  llvm::SmallVector<ParmVarDecl*, 4> params;
7236c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  llvm::SmallVector<QualType, 4> paramTypes;
7237a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7238a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Parameter substitution.
7239c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7240c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_begin(),
7241c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_size(),
7242c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               0, paramTypes, &params))
7243a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return true;
7244c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7245c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  const FunctionType *exprFunctionType = E->getFunctionType();
7246c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType exprResultType = exprFunctionType->getResultType();
7247c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!exprResultType.isNull()) {
7248c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    if (!exprResultType->isDependentType())
7249c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      blockScope->ReturnType = exprResultType;
7250c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    else if (exprResultType != getSema().Context.DependentTy)
7251c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      blockScope->ReturnType = getDerived().TransformType(exprResultType);
7252a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7253a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7254a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type has not been determined yet, leave it as a dependent
7255a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // type; it'll get set when we process the body.
7256c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType.isNull())
7257c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->ReturnType = getSema().Context.DependentTy;
7258a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7259a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // Don't allow returning a objc interface by value.
7260c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType->isObjCObjectType()) {
7261c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    getSema().Diag(E->getCaretLocation(),
7262a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                   diag::err_object_cannot_be_passed_returned_by_value)
7263c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      << 0 << blockScope->ReturnType;
7264a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return ExprError();
7265a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  }
7266711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7267c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType functionType = getDerived().RebuildFunctionProtoType(
7268c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        blockScope->ReturnType,
7269c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.data(),
7270c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.size(),
7271c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        oldBlock->isVariadic(),
7272c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                        0, RQ_None,
7273c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               exprFunctionType->getExtInfo());
7274c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->FunctionType = functionType;
7275711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7276711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Set the parameters on the block decl.
7277c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!params.empty())
7278c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->TheDecl->setParams(params.data(), params.size());
7279a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7280a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type wasn't explicitly set, it will have been marked as a
7281a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // dependent type (DependentTy); clear out the return type setting so
7282a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // we will deduce the return type when type-checking the block's body.
7283c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType == getSema().Context.DependentTy)
7284c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->ReturnType = QualType();
7285a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7286711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Transform the body
7287c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  StmtResult body = getDerived().TransformStmt(E->getBody());
7288c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (body.isInvalid())
7289711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    return ExprError();
7290711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7291c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG
7292c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // In builds with assertions, make sure that we captured everything we
7293c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // captured before.
7294c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7295c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7296c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7297c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7298c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall         e = oldBlock->capture_end(); i != e; ++i) {
72996b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    VarDecl *oldCapture = i->getVariable();
7300c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7301c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    // Ignore parameter packs.
7302c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    if (isa<ParmVarDecl>(oldCapture) &&
7303c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall        cast<ParmVarDecl>(oldCapture)->isParameterPack())
7304c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      continue;
7305c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7306c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    VarDecl *newCapture =
7307c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7308c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldCapture));
73096b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    assert(blockScope->CaptureMap.count(newCapture));
7310c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  }
7311c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif
7312c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7313c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7314c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                    /*Scope=*/0);
7315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
73171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
731860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7319454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
7320a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  NestedNameSpecifier *Qualifier = 0;
7321a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7322a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  ValueDecl *ND
7323a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7324a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                       E->getDecl()));
7325a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!ND)
7326f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
7328a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!getDerived().AlwaysRebuild() &&
7329a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      ND == E->getDecl()) {
7330a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // Mark it referenced in the new context regardless.
7331a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // FIXME: this is a bit instantiation-specific.
7332a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7333a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
73343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7335a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7336a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
73372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
7338a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
73392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, 0);
7340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
7343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction
7344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
7345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
73461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
734785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
734885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                    SourceLocation Star) {
73492865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildPointerType(PointeeType, Star,
7350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  getDerived().getBaseEntity());
7351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
73531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
735485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
735585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                         SourceLocation Star) {
73562865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildBlockPointerType(PointeeType, Star,
7357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       getDerived().getBaseEntity());
7358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
73601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
73611eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
736285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
736385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             bool WrittenAsLValue,
736485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             SourceLocation Sigil) {
73652865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
736685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    Sigil, getDerived().getBaseEntity());
7367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
73691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
73701eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
737185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
737285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 QualType ClassType,
737385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceLocation Sigil) {
73742865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
737585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        Sigil, getDerived().getBaseEntity());
7376577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7377577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
73791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
7380577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7381577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         ArrayType::ArraySizeModifier SizeMod,
7382577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         const llvm::APInt *Size,
7383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         Expr *SizeExpr,
7384577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         unsigned IndexTypeQuals,
7385577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         SourceRange BracketsRange) {
7386577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (SizeExpr || !Size)
7387577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7388577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  IndexTypeQuals, BracketsRange,
7389577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  getDerived().getBaseEntity());
73901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType Types[] = {
73921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
73931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
73941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
7395577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  };
7396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7397577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType SizeType;
7398577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  for (unsigned I = 0; I != NumTypes; ++I)
7399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7400577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      SizeType = Types[I];
7401577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      break;
7402577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    }
74031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
74059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                           /*FIXME*/BracketsRange.getBegin());
74061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
7407577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                IndexTypeQuals, BracketsRange,
74081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                getDerived().getBaseEntity());
7409577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
74101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7411577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
74121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
74131eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
7414577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 ArrayType::ArraySizeModifier SizeMod,
7415577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 const llvm::APInt &Size,
741685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
741785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceRange BracketsRange) {
74181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
741985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        IndexTypeQuals, BracketsRange);
7420577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7422577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
74231eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
74241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
7425577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
742685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
742785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   SourceRange BracketsRange) {
74281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
742985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                       IndexTypeQuals, BracketsRange);
7430577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
74311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7432577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
74331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
74341eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
7435577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
74369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SizeExpr,
7437577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 unsigned IndexTypeQuals,
7438577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceRange BracketsRange) {
74391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
74409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
7441577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
7442577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7443577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7444577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
74451eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
74461eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
7447577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
74489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Expr *SizeExpr,
7449577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                       unsigned IndexTypeQuals,
7450577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                   SourceRange BracketsRange) {
74511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
74529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
7453577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
7454577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7455577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7456577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7457577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
7458e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               unsigned NumElements,
7459e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               VectorType::VectorKind VecKind) {
7460577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  // FIXME: semantic checking!
7461e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
7462577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
74631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7464577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7465577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                      unsigned NumElements,
7467577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceLocation AttributeLoc) {
7468577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7469577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                          NumElements, true);
7470577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  IntegerLiteral *VectorSize
74719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
74729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             AttributeLoc);
74739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
7474577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
74751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7476577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
74771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
74781eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
74799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                           Expr *SizeExpr,
7480577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                  SourceLocation AttributeLoc) {
74819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
7482577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
74831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7484577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7485577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
74861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          QualType *ParamTypes,
7487577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                        unsigned NumParamTypes,
74881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          bool Variadic,
7489fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                          unsigned Quals,
7490c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                  RefQualifierKind RefQualifier,
7491fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                            const FunctionType::ExtInfo &Info) {
74921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
7493c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                   Quals, RefQualifier,
7494577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   getDerived().getBaseLocation(),
7495fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   getDerived().getBaseEntity(),
7496fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   Info);
7497577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
74981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7499577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7500a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return SemaRef.Context.getFunctionNoProtoType(T);
7502a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
7503a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
7504a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
7505ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7506ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  assert(D && "no decl found");
7507ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (D->isInvalidDecl()) return QualType();
7508ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
750992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // FIXME: Doesn't account for ObjCInterfaceDecl!
7510ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeDecl *Ty;
7511ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (isa<UsingDecl>(D)) {
7512ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    UsingDecl *Using = cast<UsingDecl>(D);
7513ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(Using->isTypeName() &&
7514ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-typename using");
7515ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
7516ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    // A valid resolved using typename decl points to exactly one type decl.
7517ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(++Using->shadow_begin() == Using->shadow_end());
7518ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
7519c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7520ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  } else {
7521ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7522ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-using decl");
7523ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<UnresolvedUsingTypenameDecl>(D);
7524ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
7525ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
7526ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return SemaRef.Context.getTypeDeclType(Ty);
7527ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
7528ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
7529ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived>
75302a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
75312a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                       SourceLocation Loc) {
75322a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildTypeofExprType(E, Loc);
7533577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7534577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7535577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7536577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7537577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  return SemaRef.Context.getTypeOfType(Underlying);
7538577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7539577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7540577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
75412a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
75422a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                     SourceLocation Loc) {
75432a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildDecltypeType(E, Loc);
7544577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
7545577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7546577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
7547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
7548833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                      TemplateName Template,
7549833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateNameLoc,
7550d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                               const TemplateArgumentListInfo &TemplateArgs) {
7551d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
7552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
75531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7554dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
7555dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
7556dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7557dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
7558a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                   IdentifierInfo &II,
7559c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   QualType ObjectType,
7560d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NamedDecl *FirstQualifierInScope) {
7561dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  CXXScopeSpec SS;
7562dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  // FIXME: The source location information is all wrong.
7563dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SS.setRange(Range);
7564dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SS.setScopeRep(Prefix);
7565dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return static_cast<NestedNameSpecifier *>(
75661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
7567495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor                                                        Range.getEnd(), II,
7568c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                        ObjectType,
7569c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                        FirstQualifierInScope,
757046646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner                                                        false, false));
7571dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
7572dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
7573dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
7574dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
7575dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7576dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
7577dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   NamespaceDecl *NS) {
7578dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7579dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
7580dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
7581dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
7582dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
7583dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7584dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
7585dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   bool TemplateKW,
7586edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                   QualType T) {
7587edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor  if (T->isDependentType() || T->isRecordType() ||
7588dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
7589a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
7590dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7591dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                       T.getTypePtr());
7592dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
75931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7594dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7595dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return 0;
7596dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
75971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7598d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
75991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
7600d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7601d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            bool TemplateKW,
7602d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            TemplateDecl *Template) {
76031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
7604d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                                  Template);
7605d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
7606d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
7607d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
76081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
7609d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
76101efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                            SourceRange QualifierRange,
76113b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                            const IdentifierInfo &II,
761243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            QualType ObjectType,
761343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            NamedDecl *FirstQualifierInScope) {
7614d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  CXXScopeSpec SS;
76151efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor  SS.setRange(QualifierRange);
76161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SS.setScopeRep(Qualifier);
7617014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  UnqualifiedId Name;
7618014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
7619d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
7620d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
7621d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*FIXME:*/getDerived().getBaseLocation(),
7622d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
7623d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
7624b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
7625d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
7626d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
762743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return Template.get();
7628d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
76291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
7631ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName
7632ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7633ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            OverloadedOperatorKind Operator,
7634ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            QualType ObjectType) {
7635ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  CXXScopeSpec SS;
7636ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SS.setRange(SourceRange(getDerived().getBaseLocation()));
7637ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SS.setScopeRep(Qualifier);
7638ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  UnqualifiedId Name;
7639ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7640ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7641ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                             Operator, SymbolLocations);
7642d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
7643d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
7644ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                       /*FIXME:*/getDerived().getBaseLocation(),
7645d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
7646d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
7647b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
7648d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
7649d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
7650d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  return Template.template getAsVal<TemplateName>();
7651ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor}
7652c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7653ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived>
765460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   SourceLocation OpLoc,
76579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *OrigCallee,
76589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *First,
76599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *Second) {
76609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Callee = OrigCallee->IgnoreParenCasts();
76619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
76621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Determine whether this should be a builtin operation.
7664f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript) {
76659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
76669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType())
76679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinArraySubscriptExpr(First,
76689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Callee->getLocStart(),
76699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Second, OpLoc);
76701a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman  } else if (Op == OO_Arrow) {
76711a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman    // -> is never a builtin operation.
76729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
76739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  } else if (Second == 0 || isPostIncDec) {
76749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType()) {
7675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // The argument is not of overloadable type, so try to create a
7676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // built-in unary operation.
76772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      UnaryOperatorKind Opc
7678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor        = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
76791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
7681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
7682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  } else {
76839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
76849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType()) {
7685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // Neither of the arguments is an overloadable type, so try to
7686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // create a built-in binary operation.
76872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
768860d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Result
76899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
7690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Result.isInvalid())
7691f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
76921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      return move(Result);
7694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
7695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
76961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Compute the transformed set of functions (and function templates) to be
7698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // used during overload resolution.
76996e26689f5d513e24ad7783a4493201930fdeccc0John McCall  UnresolvedSet<16> Functions;
77001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
7702ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    assert(ULE->requiresADL());
7703ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
7704ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // FIXME: Do we have to check
7705ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // IsAcceptableNonMemberOperatorCandidate for each of these?
77066e26689f5d513e24ad7783a4493201930fdeccc0John McCall    Functions.append(ULE->decls_begin(), ULE->decls_end());
7707ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  } else {
77089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
7709ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
77101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Add any functions found via argument-dependent lookup.
77129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Args[2] = { First, Second };
77139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  unsigned NumArgs = 1 + (Second != 0);
77141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for unary operators.
7716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (NumArgs == 1 || isPostIncDec) {
77172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    UnaryOperatorKind Opc
7718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
77199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
7720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
77211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7722f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript)
77239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
7724ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                                      OpLoc,
77259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      First,
77269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Second);
7727f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl
7728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for binary operators.
77292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
773060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result
7731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Result.isInvalid())
7733f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
77341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return move(Result);
7736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
77371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
773826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived>
773960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
77409ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
774126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceLocation OperatorLoc,
774226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       bool isArrow,
774326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                 NestedNameSpecifier *Qualifier,
774426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceRange QualifierRange,
774526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     TypeSourceInfo *ScopeType,
774626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       SourceLocation CCLoc,
7747fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                       SourceLocation TildeLoc,
7748a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed) {
774926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  CXXScopeSpec SS;
775026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (Qualifier) {
775126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    SS.setRange(QualifierRange);
775226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    SS.setScopeRep(Qualifier);
775326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
775426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
77559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  QualType BaseType = Base->getType();
77569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
775726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      (!isArrow && !BaseType->getAs<RecordType>()) ||
7758c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      (isArrow && BaseType->getAs<PointerType>() &&
7759bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif       !BaseType->getAs<PointerType>()->getPointeeType()
7760bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif                                              ->template getAs<RecordType>())){
776126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    // This pseudo-destructor expression is still a pseudo-destructor.
77629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
776326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             isArrow? tok::arrow : tok::period,
7764fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                             SS, ScopeType, CCLoc, TildeLoc,
7765a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                             Destroyed,
776626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             /*FIXME?*/true);
776726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
77682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
7769a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
77702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
77712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
77722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
77732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  NameInfo.setNamedTypeInfo(DestroyedType);
77742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
777526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  // FIXME: the ScopeType should be tacked onto SS.
77762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
77779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getSema().BuildMemberReferenceExpr(Base, BaseType,
777826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            OperatorLoc, isArrow,
777926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            SS, /*FIXME: FirstQualifier*/ 0,
77802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            NameInfo,
778126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            /*TemplateArgs*/ 0);
778226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor}
778326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
7784577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang
7785577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7786577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
7787