TreeTransform.h revision 6ad6f2848d7652ab2991286eb48be440d3493b28
1a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
2577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
3577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//                     The LLVM Compiler Infrastructure
4577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
5577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file is distributed under the University of Illinois Open Source
6577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// License. See LICENSE.TXT for details.
7577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===/
8577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
9577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//  This file implements a semantic tree transformation that takes a given
10577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//  AST and rebuilds it, possibly transforming some nodes in the process.
11577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
12577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===/
13577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
162d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h"
17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h"
18dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h"
19781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h"
20c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h"
217cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h"
22657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h"
23b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h"
24b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h"
2543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h"
2643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h"
2743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h"
2819510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h"
2919510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h"
30b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h"
31a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h"
327e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h"
33577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm>
34577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
35577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang {
36781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema;
371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one
39577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another.
40577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of
421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide
431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template
44577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the
45577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the
46577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar
47577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and
48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters.
49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow
511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can
52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an
53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The
54577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual.
55577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which
57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node
58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions,
59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST
60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation
61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g.,
62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes
63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create
64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node.
65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The
67670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(),
68577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
69577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely
70577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations.
71577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
72577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the
73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
7443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation
761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template
77577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX
78577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change.
79577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild
80577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may
81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps.
82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one
841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation
85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the
87577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking
88577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()).
89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform {
91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected:
92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &SemaRef;
931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
95577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Initializes a new tree transformer.
96577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
99577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Derived &getDerived() { return static_cast<Derived&>(*this); }
100577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
101577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Derived &getDerived() const {
1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return static_cast<const Derived&>(*this);
104577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
105577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
10660d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline ExprResult Owned(Expr *E) { return E; }
10760d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline StmtResult Owned(Stmt *S) { return S; }
1089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall
109577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the semantic analysis object used for
110577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// this tree transform.
111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &getSema() const { return SemaRef; }
1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Whether the transformation should always rebuild AST nodes, even
114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// if none of the children have changed.
115577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this function to specify when the transformation
117577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// should rebuild all AST nodes.
118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlwaysRebuild() { return false; }
1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the location of the entity being transformed, if that
121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, returns no source-location information. Subclasses can
124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// provide an alternative implementation that provides better location
125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information.
126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  SourceLocation getBaseLocation() { return SourceLocation(); }
1271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the name of the entity being transformed, if that
129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, returns an empty name. Subclasses can provide an alternative
132577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// implementation with a more precise name.
133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  DeclarationName getBaseEntity() { return DeclarationName(); }
134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Sets the "base" location and entity when that
136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// information is known based on another transformation.
137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, the source location and entity are ignored. Subclasses can
139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// override this function to provide a customized implementation.
140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  void setBase(SourceLocation Loc, DeclarationName Entity) { }
1411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief RAII object that temporarily sets the base location and entity
143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// used for reporting diagnostics in types.
144b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  class TemporaryBase {
145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TreeTransform &Self;
146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SourceLocation OldLocation;
147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclarationName OldEntity;
1481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  public:
150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TemporaryBase(TreeTransform &Self, SourceLocation Location,
1511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  DeclarationName Entity) : Self(Self) {
152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldLocation = Self.getDerived().getBaseLocation();
153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldEntity = Self.getDerived().getBaseEntity();
154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Self.getDerived().setBase(Location, Entity);
155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
1561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ~TemporaryBase() {
158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Self.getDerived().setBase(OldLocation, OldEntity);
159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  };
1611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determine whether the given type \p T has already been
163577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// transformed.
164577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
165577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses can provide an alternative implementation of this routine
1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// to short-circuit evaluation when it is known that a given type will
167577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// not change. For example, template instantiation need not traverse
168577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// non-dependent types.
169577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlreadyTransformed(QualType T) {
170577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T.isNull();
171577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
172577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
1736eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether the given call argument should be dropped, e.g.,
1746eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// because it is a default argument.
1756eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
1766eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Subclasses can provide an alternative implementation of this routine to
1776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// determine which kinds of call arguments get dropped. By default,
1786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// CXXDefaultArgument nodes are dropped (prior to transformation).
1796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool DropCallArgument(Expr *E) {
1806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return E->isDefaultArgument();
1816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
182c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
183577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transforms the given type into another type.
184577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by creating a
186a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// TypeSourceInfo for it and delegating to the appropriate
187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// function.  This is expensive, but we don't mind, because
188a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// this method is deprecated anyway;  all users should be
189a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// switched to storing TypeSourceInfos.
190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \returns the transformed type.
19243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(QualType T);
1931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transforms the given type-with-location into a new
195a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type-with-location.
196a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ///
197a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by delegating to the
198a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// appropriate TransformXXXType to build a new type.  Subclasses
199a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// may override this function (to take over all type
200a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// transformations) or some set of the TransformXXXType functions
201a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// to alter the transformation.
20243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transform the given type-with-location into a new
205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type, collecting location information in the given builder
206a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// as necessary.
207577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
20843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
2091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
210657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given statement.
211577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this routine transforms a statement by delegating to the
21343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// appropriate TransformXXXStmt function to transform a specific kind of
21443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// statement or the TransformExpr() function to transform an expression.
21543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to transform statements using some
21643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// other mechanism.
21743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
21843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \returns the transformed statement.
21960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformStmt(Stmt *S);
2201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
221657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given expression.
222657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  ///
223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine transforms an expression by delegating to the
224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// appropriate TransformXXXExpr function to build a new expression.
225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this function to transform expressions using some
226b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// other mechanism.
227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \returns the transformed expression.
22960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformExpr(Expr *E);
2301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
231577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given declaration, which is referenced from a type
232577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// or expression.
233577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
234dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, acts as the identity function on declarations. Subclasses
235dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// may override this function to provide alternate behavior.
2367c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
23743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
23843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Transform the definition of the given declaration.
23943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, invokes TransformDecl() to transform the declaration.
24143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
243c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().TransformDecl(Loc, D);
2447c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  }
2451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2466cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// \brief Transform the given declaration, which was the first part of a
2476cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// nested-name-specifier in a member access expression.
2486cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
249c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// This specific declaration transformation only applies to the first
2506cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// identifier in a nested-name-specifier of a member access expression, e.g.,
2516cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// the \c T in \c x->T::member
2526cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
2536cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// By default, invokes TransformDecl() to transform the declaration.
2546cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// Subclasses may override this function to provide alternate behavior.
255c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
2576cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  }
258c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
259577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given nested-name-specifier.
260577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
2611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, transforms all of the types and declarations within the
262dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this function to provide
263dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// alternate behavior.
264577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
265a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                    SourceRange Range,
266c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                              QualType ObjectType = QualType(),
267c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                          NamedDecl *FirstQualifierInScope = 0);
2681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// \brief Transform the given declaration name.
27081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  ///
27181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// By default, transforms the types of conversion function, constructor,
27281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// and destructor names and then (if needed) rebuilds the declaration name.
27381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// Identifiers and selectors are returned unmodified. Sublcasses may
27481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// override this function to provide alternate behavior.
2752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo
27643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
2771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
278577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template name.
2791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
280d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, transforms the template name by transforming the declarations
2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// and nested-name-specifiers that occur within the template name.
282d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
2833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  TemplateName TransformTemplateName(TemplateName Name,
28443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                     QualType ObjectType = QualType(),
28543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                     NamedDecl *FirstQualifierInScope = 0);
2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
287577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template argument.
288577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
2891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this operation transforms the type, expression, or
2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// declaration stored within the template argument and constructs a
291670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// new template argument from the transformed result. Subclasses may
292670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// override this function to provide alternate behavior.
293833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  ///
294833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// Returns true if there was an error.
295833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &Output);
297833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
298833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &ArgLoc);
301833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
302a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// \brief Fakes up a TypeSourceInfo for a type.
303a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return SemaRef.Context.getTrivialTypeSourceInfo(T,
305833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                       getDerived().getBaseLocation());
306833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
3071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
309a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT)                                   \
31043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
311a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
312577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
31343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
31443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
31543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateSpecializationTypeLoc TL,
31643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateName Template);
31743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
31843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
31943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
32043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentTemplateSpecializationTypeLoc TL,
32143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               NestedNameSpecifier *Prefix);
32243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
32321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms the parameters of a function type into the
32421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// given vectors.
32521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
32621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// The result vectors should be kept in sync; null entries in the
32721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// variables vector are acceptable.
32821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
32921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// Return true on error.
33021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
33121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                                   llvm::SmallVectorImpl<QualType> &PTypes,
33221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                                   llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
33321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
33421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms a single function-type parameter.  Return null
33521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// on error.
33621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
33721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
33843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
339833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
34060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
34160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
3421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                        \
34460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Transform##Node(Node *S);
345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                        \
34660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Transform##Node(Node *E);
3477381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
3484bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new pointer type given its pointee type.
351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the pointer type.
353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
35485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
355577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
356577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new block pointer type given its pointee type.
357577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis when building the block pointer
359577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
36085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
361577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
36285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \brief Build a new reference type given the type it references.
363577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
36485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// By default, performs semantic analysis when building the
36585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// reference type. Subclasses may override this routine to provide
36685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// different behavior.
367577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
36885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \param LValue whether the type was written with an lvalue sigil
36985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// or an rvalue sigil.
37085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildReferenceType(QualType ReferentType,
37185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                bool LValue,
37285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                SourceLocation Sigil);
3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
374577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new member pointer type given the pointee type and the
375577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// class type it refers into.
376577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
377577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the member pointer
378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
37985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
38085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceLocation Sigil);
3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
382577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new array type given the element type, size
383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, size of the array (if known), size expression, and index type
384577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// qualifiers.
385577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
386577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
387577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Also by default, all of the other Rebuild*Array
389577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildArrayType(QualType ElementType,
390577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            ArrayType::ArraySizeModifier SizeMod,
391577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            const llvm::APInt *Size,
392577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            Expr *SizeExpr,
393577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            unsigned IndexTypeQuals,
394577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            SourceRange BracketsRange);
3951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new constant array type given the element type, size
397577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, (known) size of the array, and index type qualifiers.
398577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
400577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
4011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildConstantArrayType(QualType ElementType,
402577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
403577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    const llvm::APInt &Size,
40485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    unsigned IndexTypeQuals,
40585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceRange BracketsRange);
406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
407577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new incomplete array type given the element type, size
408577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, and index type qualifiers.
409577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
410577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
411577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildIncompleteArrayType(QualType ElementType,
413577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                      ArrayType::ArraySizeModifier SizeMod,
41485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      unsigned IndexTypeQuals,
41585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      SourceRange BracketsRange);
416577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new variable-length array type given the element type,
418577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
419577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
420577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildVariableArrayType(QualType ElementType,
423577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
4249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SizeExpr,
425577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned IndexTypeQuals,
426577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    SourceRange BracketsRange);
427577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new dependent-sized array type given the element type,
429577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
430577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
431577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
432577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedArrayType(QualType ElementType,
434577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
4359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *SizeExpr,
436577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          unsigned IndexTypeQuals,
437577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          SourceRange BracketsRange);
438577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
439577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new vector type given the element type and
440577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
441577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
442577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
443577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
44482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                             VectorType::VectorKind VecKind);
4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
447577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new extended vector type given the element type and
448577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
449577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
450577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
451577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
452577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                SourceLocation AttributeLoc);
4541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new potentially dependently-sized extended vector type
456577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// given the element type and number of elements.
457577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
458577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
459577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
4619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *SizeExpr,
462577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                              SourceLocation AttributeLoc);
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
464577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new function type.
465577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the function type.
467577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
468577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildFunctionProtoType(QualType T,
4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    QualType *ParamTypes,
470577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned NumParamTypes,
471fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    bool Variadic, unsigned Quals,
472fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    const FunctionType::ExtInfo &Info);
4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
474a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Build a new unprototyped function type.
475a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType RebuildFunctionNoProtoType(QualType ResultType);
476a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
477ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// \brief Rebuild an unresolved typename type, given the decl that
478ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// the UnresolvedUsingTypenameDecl was transformed to.
479ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType RebuildUnresolvedUsingType(Decl *D);
480ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
481577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typedef type.
482577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypedefType(TypedefDecl *Typedef) {
483577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Typedef);
484577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
485577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
486577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new class/struct/union type.
487577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildRecordType(RecordDecl *Record) {
488577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Record);
489577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
490577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
491577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new Enum type.
492577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildEnumType(EnumDecl *Enum) {
493577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Enum);
494577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4957da2431c23ef1ee8acb114e39692246e1801afc2John McCall
4961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(expr) type.
497577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
498577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typeof type.
499577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5002a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
501577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
5021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(type) type.
503577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
504577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, builds a new TypeOfType with the given underlying type.
505577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypeOfType(QualType Underlying);
506577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
5071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++0x decltype type.
508577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
509577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the decltype type.
510577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5112a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
5121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new template specialization type.
514577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
515577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the template
516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// specialization type. Subclasses may override this routine to provide
517577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
518577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTemplateSpecializationType(TemplateName Template,
519833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateLoc,
520d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                       const TemplateArgumentListInfo &Args);
5211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
522577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new qualified name type.
523577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
524465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// By default, builds a new ElaboratedType type from the keyword,
525465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// the nested-name-specifier and the named type.
526465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
52721e413fe6305a198564d436ac515497716c47844John McCall  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
52821e413fe6305a198564d436ac515497716c47844John McCall                                 ElaboratedTypeKeyword Keyword,
529465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                                 NestedNameSpecifier *NNS, QualType Named) {
530465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
533577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to a template-id.
534577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
535e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// By default, builds a new DependentNameType type from the
536e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// nested-name-specifier and the given type. Subclasses may override
537e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// this routine to provide different behavior.
53833500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType RebuildDependentTemplateSpecializationType(
53933500955d731c73717af52088b7fc0e7a85681e7John McCall                                    ElaboratedTypeKeyword Keyword,
5401efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                    NestedNameSpecifier *Qualifier,
5411efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                    SourceRange QualifierRange,
54233500955d731c73717af52088b7fc0e7a85681e7John McCall                                    const IdentifierInfo *Name,
54333500955d731c73717af52088b7fc0e7a85681e7John McCall                                    SourceLocation NameLoc,
54433500955d731c73717af52088b7fc0e7a85681e7John McCall                                    const TemplateArgumentListInfo &Args) {
54533500955d731c73717af52088b7fc0e7a85681e7John McCall    // Rebuild the template name.
54633500955d731c73717af52088b7fc0e7a85681e7John McCall    // TODO: avoid TemplateName abstraction
54733500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateName InstName =
5481efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
54943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                       QualType(), 0);
55033500955d731c73717af52088b7fc0e7a85681e7John McCall
55196fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor    if (InstName.isNull())
55296fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor      return QualType();
55396fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor
55433500955d731c73717af52088b7fc0e7a85681e7John McCall    // If it's still dependent, make a dependent specialization.
55533500955d731c73717af52088b7fc0e7a85681e7John McCall    if (InstName.getAsDependentTemplateName())
55633500955d731c73717af52088b7fc0e7a85681e7John McCall      return SemaRef.Context.getDependentTemplateSpecializationType(
5571efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                          Keyword, Qualifier, Name, Args);
55833500955d731c73717af52088b7fc0e7a85681e7John McCall
55933500955d731c73717af52088b7fc0e7a85681e7John McCall    // Otherwise, make an elaborated type wrapping a non-dependent
56033500955d731c73717af52088b7fc0e7a85681e7John McCall    // specialization.
56133500955d731c73717af52088b7fc0e7a85681e7John McCall    QualType T =
56233500955d731c73717af52088b7fc0e7a85681e7John McCall      getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
56333500955d731c73717af52088b7fc0e7a85681e7John McCall    if (T.isNull()) return QualType();
564465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
56522f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara    // NOTE: NNS is already recorded in template specialization type T.
56622f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
568577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
569577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to an identifier.
570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typename type
572e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// (or elaborated type). Subclasses may override this routine to provide
573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
574e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
5754a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                                    NestedNameSpecifier *NNS,
5764a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                                    const IdentifierInfo *Id,
577e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation KeywordLoc,
578e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceRange NNSRange,
579e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation IdLoc) {
5804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    CXXScopeSpec SS;
5814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SS.setScopeRep(NNS);
582e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    SS.setRange(NNSRange);
583e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
5844033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (NNS->isDependent()) {
5854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      // If the name is still dependent, just build a new dependent name type.
5864033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      if (!SemaRef.computeDeclContext(SS))
5874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
5884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
5894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
590465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (Keyword == ETK_None || Keyword == ETK_Typename)
591e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
592e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                       KeywordLoc, NNSRange, IdLoc);
593465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
594465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
595465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
596e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    // We had a dependent elaborated-type-specifier that has been transformed
5974033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // into a non-dependent elaborated-type-specifier. Find the tag we're
5984033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // referring to.
599e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
6004033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    DeclContext *DC = SemaRef.computeDeclContext(SS, false);
6014033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!DC)
6024033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
6034033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
6045613876991c80a684595fe8de1f039296a0657ffJohn McCall    if (SemaRef.RequireCompleteDeclContext(SS, DC))
6055613876991c80a684595fe8de1f039296a0657ffJohn McCall      return QualType();
6065613876991c80a684595fe8de1f039296a0657ffJohn McCall
6074033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    TagDecl *Tag = 0;
6084033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SemaRef.LookupQualifiedName(Result, DC);
6094033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    switch (Result.getResultKind()) {
6104033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFound:
6114033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFoundInCurrentInstantiation:
6124033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
613c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6144033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Found:
6154033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        Tag = Result.getAsSingle<TagDecl>();
6164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6184033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundOverloaded:
6194033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundUnresolvedValue:
6204033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        llvm_unreachable("Tag lookup cannot find non-tags");
6214033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
622c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6234033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Ambiguous:
6244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        // Let the LookupResult structure handle ambiguities.
6254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
6264033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
6274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
6284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!Tag) {
6291eabb7d0c30f6a876b0fd03ad4656c096c26b8d0Douglas Gregor      // FIXME: Would be nice to highlight just the source range.
630e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
6311eabb7d0c30f6a876b0fd03ad4656c096c26b8d0Douglas Gregor        << Kind << Id << DC;
6324033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
6334033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
634465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
635e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
636e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
6374033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
6384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
6394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
6404033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
6414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // Build the elaborated-type-specifier type.
6424033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    QualType T = SemaRef.Context.getTypeDeclType(Tag);
643465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
644dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
6451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
646dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and an
647dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// identifier that names the next step in the nested-name-specifier.
648dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
649dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
650dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
651dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
652dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
653dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
654a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                  IdentifierInfo &II,
655c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                  QualType ObjectType,
656c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                              NamedDecl *FirstQualifierInScope);
657dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
658dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and the
659dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// namespace named in the next step in the nested-name-specifier.
660dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
661dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
662dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
663dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
664dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
666dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  NamespaceDecl *NS);
667dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
668dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and the
669dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// type named in the next step in the nested-name-specifier.
670dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
671dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
672dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
673dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
674dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
675dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
676dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  bool TemplateKW,
677edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  QualType T);
678d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
679d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier, a flag
680d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// indicating whether the "template" keyword was provided, and the template
681d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// that the template name refers to.
682d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
683d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, builds the new template name directly. Subclasses may override
684d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// this routine to provide different behavior.
685d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
686d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   bool TemplateKW,
687d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   TemplateDecl *Template);
688d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
689d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier and the
690d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// name that is referred to as a template.
691d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
692d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
693d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
694d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// template name. Subclasses may override this routine to provide different
695d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// behavior.
696d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
6971efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                   SourceRange QualifierRange,
6983b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                   const IdentifierInfo &II,
69943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   QualType ObjectType,
70043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   NamedDecl *FirstQualifierInScope);
7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
702ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// \brief Build a new template name given a nested name specifier and the
703ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// overloaded operator name that is referred to as a template.
704ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  ///
705ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// By default, performs semantic analysis to determine whether the name can
706ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
707ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// template name. Subclasses may override this routine to provide different
708ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// behavior.
709ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
710ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   OverloadedOperatorKind Operator,
711ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   QualType ObjectType);
712c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
71343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new compound statement.
71443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
71543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
71643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
71760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
71843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       MultiStmtArg Statements,
71943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       SourceLocation RBraceLoc,
72043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       bool IsStmtExpr) {
7219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
72243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       IsStmtExpr);
72343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
72443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
72543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new case statement.
72643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
72743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
72843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
72960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
7309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *LHS,
73143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EllipsisLoc,
7329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *RHS,
73343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation ColonLoc) {
7349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
73543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   ColonLoc);
73643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to a new case statement.
73943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
74043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
74143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
74260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
7439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().ActOnCaseStmtBody(S, Body);
7449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return S;
74543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new default statement.
74843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
74943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
75043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
75160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
75243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      SourceLocation ColonLoc,
7539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      Stmt *SubStmt) {
7549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
75543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      /*CurScope=*/0);
75643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new label statement.
75943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
76043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
76143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
76260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
76343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    IdentifierInfo *Id,
76443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    SourceLocation ColonLoc,
7651a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                    Stmt *SubStmt, bool HasUnusedAttr) {
7661a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis    return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
7671a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                  HasUnusedAttr);
76843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new "if" statement.
77143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
77243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
77343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
77460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
77544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                 VarDecl *CondVar, Stmt *Then,
7769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 SourceLocation ElseLoc, Stmt *Else) {
77744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis    return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
77843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
78043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Start building a new switch statement.
78143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
78243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
78343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
78460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
7859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Cond, VarDecl *CondVar) {
7869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
787d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                            CondVar);
78843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to the switch statement.
79143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
79243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
79343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
79460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
7959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Stmt *Switch, Stmt *Body) {
7969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
79743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
79843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
79943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new while statement.
80043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
80143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
80243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
80360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
804eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor                                    Sema::FullExprArg Cond,
80599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor                                    VarDecl *CondVar,
8069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Stmt *Body) {
8079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
80843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new do-while statement.
81143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
81243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
81343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
81460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
81543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation WhileLoc,
81643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation LParenLoc,
8179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Expr *Cond,
81843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation RParenLoc) {
8199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
8209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Cond, RParenLoc);
82143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
82243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
82343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new for statement.
82443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
82543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
82643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
82760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildForStmt(SourceLocation ForLoc,
82843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                  SourceLocation LParenLoc,
8299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Stmt *Init, Sema::FullExprArg Cond,
83099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor                                  VarDecl *CondVar, Sema::FullExprArg Inc,
8319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  SourceLocation RParenLoc, Stmt *Body) {
8329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
833d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                  CondVar,
8349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Inc, RParenLoc, Body);
83543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new goto statement.
83843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
83943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
84043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
84160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
84243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation LabelLoc,
84343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   LabelStmt *Label) {
84443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
84543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
84643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
84743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new indirect goto statement.
84843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
84943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
85043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
85160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
85243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                           SourceLocation StarLoc,
8539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *Target) {
8549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
85543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new return statement.
85843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
85943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
86043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
86160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
8629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Result) {
8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnReturnStmt(ReturnLoc, Result);
86543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new declaration statement.
86843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
86943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
87043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
87160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   SourceLocation StartLoc,
87343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EndLoc) {
87443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return getSema().Owned(
87543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor             new (getSema().Context) DeclStmt(
87643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                        DeclGroupRef::Create(getSema().Context,
87743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                             Decls, NumDecls),
87843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              StartLoc, EndLoc));
87943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
881703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// \brief Build a new inline asm statement.
882703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  ///
883703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// By default, performs semantic analysis to build the new statement.
884703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// Subclasses may override this routine to provide different behavior.
88560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
886703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsSimple,
887703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsVolatile,
888703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumOutputs,
889703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumInputs,
890ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                  IdentifierInfo **Names,
891703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Constraints,
892703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Exprs,
8939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Expr *AsmString,
894703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Clobbers,
895703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  SourceLocation RParenLoc,
896703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool MSAsm) {
897c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
898703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  NumInputs, Names, move(Constraints),
8999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Exprs, AsmString, Clobbers,
900703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  RParenLoc, MSAsm);
901703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
9024dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
9034dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @try statement.
9044dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
9054dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
9064dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
90760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
9089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *TryBody,
9098f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                        MultiStmtArg CatchStmts,
9109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *Finally) {
9119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
9129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Finally);
9134dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
9144dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
915be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Rebuild an Objective-C exception declaration.
916be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
917be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new declaration.
918be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
919be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
920be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                    TypeSourceInfo *TInfo, QualType T) {
921c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildObjCExceptionDecl(TInfo, T,
922c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                            ExceptionDecl->getIdentifier(),
923be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                            ExceptionDecl->getLocation());
924be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
925c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
926be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Build a new Objective-C @catch statement.
927be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
928be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
929be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
93060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
931be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          SourceLocation RParenLoc,
932be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          VarDecl *Var,
9339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Stmt *Body) {
934be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
9359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Var, Body);
936be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
937c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
9384dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @finally statement.
9394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
9404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
9414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
94260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
9439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Stmt *Body) {
9449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
9454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
946c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
9478fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @throw statement.
948d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  ///
949d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
950d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
95160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
9529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Operand) {
9539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
954d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
955c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
9568fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @synchronized statement.
9578fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  ///
9588fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
9598fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
96060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
9619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *Object,
9629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Stmt *Body) {
9639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
9649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Body);
9658fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  }
966c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor
967c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// \brief Build a new Objective-C fast enumeration statement.
968c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  ///
969c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
970c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
97160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
972f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation LParenLoc,
973f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Element,
974f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Expr *Collection,
975f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation RParenLoc,
976f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Body) {
977c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor    return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
9789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Element,
9799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Collection,
980c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                RParenLoc,
9819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Body);
982c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  }
983c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
98443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ exception declaration.
98543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
98643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new decaration.
98743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
98883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
989a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                                TypeSourceInfo *Declarator,
99043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                IdentifierInfo *Name,
99183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                SourceLocation Loc) {
99283cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
99343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
99543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ catch statement.
99643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
99960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1000f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 VarDecl *ExceptionDecl,
1001f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 Stmt *Handler) {
10029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
10039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Handler));
100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ try statement.
100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
100843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
101060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1011f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               Stmt *TryBlock,
1012f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               MultiStmtArg Handlers) {
10139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
101443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression that references a declaration.
1017b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
102060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1021f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        LookupResult &R,
1022f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        bool RequiresADL) {
1023f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1024f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1025f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1026f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1027f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Build a new expression that references a declaration.
1028f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  ///
1029f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// By default, performs semantic analysis to build the new expression.
1030f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Subclasses may override this routine to provide different behavior.
103160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1032f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                SourceRange QualifierRange,
1033f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                ValueDecl *VD,
1034f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                const DeclarationNameInfo &NameInfo,
1035f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                TemplateArgumentListInfo *TemplateArgs) {
1036a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    CXXScopeSpec SS;
1037a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    SS.setScopeRep(Qualifier);
1038a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    SS.setRange(QualifierRange);
1039dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
1040dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: loses template args.
10412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
10422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1043b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression in parentheses.
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
104960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                    SourceLocation RParen) {
10519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1053b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1054a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Build a new pseudo-destructor expression.
10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1056a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1057a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
105860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1059a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                  SourceLocation OperatorLoc,
1060a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                  bool isArrow,
1061a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                NestedNameSpecifier *Qualifier,
106226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  SourceRange QualifierRange,
106326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  TypeSourceInfo *ScopeType,
106426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  SourceLocation CCLoc,
1065fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                  SourceLocation TildeLoc,
1066a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed);
10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1068b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary operator expression.
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1071b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
107260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
10732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                        UnaryOperatorKind Opc,
10749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *SubExpr) {
10759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build a new builtin offsetof expression.
10798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
10808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
10818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
108260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
10838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       TypeSourceInfo *Type,
1084f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                       Sema::OffsetOfComponent *Components,
10858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       unsigned NumComponents,
10868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       SourceLocation RParenLoc) {
10878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
10888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          NumComponents, RParenLoc);
10898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1090c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1091b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new sizeof or alignof expression with a type argument.
10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1094b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
109560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
10965ab75172051a6d2ea71a80a79e81c65519fd3462John McCall                                        SourceLocation OpLoc,
1097b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool isSizeOf, SourceRange R) {
1098a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
1099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
11011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new sizeof or alignof expression with an expression
1102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument.
11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1104b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
110660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
1107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool isSizeOf, SourceRange R) {
110860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
11099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
1110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1111f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1113b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1114b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1116b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new array subscript expression.
11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1118b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1119b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
112060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LBracketLoc,
11229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *RHS,
1123b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RBracketLoc) {
11249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
11259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             LBracketLoc, RHS,
1126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             RBracketLoc);
1127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1129b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new call expression.
11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
113360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Args,
1135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
11369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1137a1a04786cea2445759026edacd096abd1fbf4a05Douglas Gregor                                   move(Args), RParenLoc);
1138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member access expression.
11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
114460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1145f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               bool isArrow,
1146f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NestedNameSpecifier *Qualifier,
1147f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               SourceRange QualifierRange,
1148f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               const DeclarationNameInfo &MemberNameInfo,
1149f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               ValueDecl *Member,
1150f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FoundDecl,
1151d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                        const TemplateArgumentListInfo *ExplicitTemplateArgs,
1152f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FirstQualifierInScope) {
1153d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    if (!Member->getDeclName()) {
1154f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // We have a reference to an unnamed field.  This is always the
1155f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // base of an anonymous struct/union member access, i.e. the
1156f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // field is always of record type.
1157d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
1158f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      assert(Member->getType()->isRecordType() &&
1159f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             "unnamed member not of record type?");
11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      if (getSema().PerformObjectMemberConversion(Base, Qualifier,
11626bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                                  FoundDecl, Member))
1163f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
11648aa5f407d9e4787ff08bd66e1a2fe39be174fddcDouglas Gregor
1165f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      MemberExpr *ME =
11679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        new (getSema().Context) MemberExpr(Base, isArrow,
11682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           Member, MemberNameInfo,
1169f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           cast<FieldDecl>(Member)->getType(),
1170f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           VK, OK_Ordinary);
1171d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      return getSema().Owned(ME);
1172d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    }
11731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
117483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    CXXScopeSpec SS;
117583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    if (Qualifier) {
117683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      SS.setRange(QualifierRange);
117783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      SS.setScopeRep(Qualifier);
117883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    }
117983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
11809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().DefaultFunctionArrayConversion(Base);
11819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    QualType BaseType = Base->getType();
1182aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
11836bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // FIXME: this involves duplicating earlier analysis in a lot of
11846bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // cases; we should avoid this when possible.
11852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
11866bb8017bb9e828d118e15e59d71c66bba323c364John McCall    R.addDecl(FoundDecl);
1187c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    R.resolveKind();
1188c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
11899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1190129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, FirstQualifierInScope,
1191c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                              R, ExplicitTemplateArgs);
1192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new binary operator expression.
11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
119860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
11992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                         BinaryOperatorKind Opc,
12009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *LHS, Expr *RHS) {
12019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1204b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new conditional operator expression.
12051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1207b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
120860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildConditionalOperator(Expr *Cond,
1209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation QuestionLoc,
12109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *LHS,
1211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation ColonLoc,
12129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *RHS) {
12139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
12149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        LHS, RHS);
1215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C-style cast expression.
12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
122160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
12229d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                         TypeSourceInfo *TInfo,
1223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc,
12249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *SubExpr) {
1225b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall    return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
12269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubExpr);
1227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1229b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new compound literal expression.
12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1231b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
123360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
123442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall                                              TypeSourceInfo *TInfo,
1235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation RParenLoc,
12369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Init) {
123742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
12389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Init);
1239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1241b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new extended vector element access expression.
12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1243b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1244b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
124560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildExtVectorElementExpr(Expr *Base,
1246b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation OpLoc,
1247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation AccessorLoc,
1248b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               IdentifierInfo &Accessor) {
1249aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
1250129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    CXXScopeSpec SS;
12512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
12529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1253129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              OpLoc, /*IsArrow*/ false,
1254129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, /*FirstQualifierInScope*/ 0,
12552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                              NameInfo,
1256129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              /* TemplateArgs */ 0);
1257b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new initializer list expression.
12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
126360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildInitList(SourceLocation LBraceLoc,
1264b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Inits,
1265e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   SourceLocation RBraceLoc,
1266e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   QualType ResultTy) {
126760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1268e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1269e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    if (Result.isInvalid() || ResultTy->isDependentType())
1270e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      return move(Result);
1271c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1272e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // Patch in the result type we were given, which may have been computed
1273e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // when the initial InitListExpr was built.
1274e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1275e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    ILE->setType(ResultTy);
1276e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    return move(Result);
1277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new designated initializer expression.
12801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
128360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1284b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             MultiExprArg ArrayExprs,
1285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation EqualOrColonLoc,
1286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             bool GNUSyntax,
12879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *Init) {
128860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
12909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Init);
1291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1292f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.release();
1295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new value-initialized expression.
12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds the implicit value initialization without performing
1301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// any semantic analysis. Subclasses may override this routine to provide
1302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
130360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildImplicitValueInitExpr(QualType T) {
1304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new \c va_arg expression.
13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
131160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
13129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SubExpr, TypeSourceInfo *TInfo,
13132cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    SourceLocation RParenLoc) {
13142cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara    return getSema().BuildVAArgExpr(BuiltinLoc,
13159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    SubExpr, TInfo,
13162cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    RParenLoc);
1317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression list in parentheses.
13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
132360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        MultiExprArg SubExprs,
1325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1326c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1327f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian                                               move(SubExprs));
1328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new address-of-label expression.
13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
13321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis, using the name of the label
1333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// rather than attempting to map the label statement itself.
1334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
133560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation LabelLoc,
1337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        LabelStmt *Label) {
1338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new GNU statement 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 RebuildStmtExpr(SourceLocation LParenLoc,
13469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Stmt *SubStmt,
1347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
13489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new __builtin_types_compatible_p expression.
1352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
135560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
13563fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara                                              TypeSourceInfo *TInfo1,
13573fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara                                              TypeSourceInfo *TInfo2,
1358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation RParenLoc) {
13593fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara    return getSema().BuildTypesCompatibleExpr(BuiltinLoc,
13603fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara                                              TInfo1, TInfo2,
1361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              RParenLoc);
1362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new __builtin_choose_expr expression.
1365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
136860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
13699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Cond, Expr *LHS, Expr *RHS,
1370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                     SourceLocation RParenLoc) {
1371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.ActOnChooseExpr(BuiltinLoc,
13729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Cond, LHS, RHS,
1373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   RParenLoc);
1374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1376b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new overloaded operator call expression.
1377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// The semantic analysis provides the behavior of template instantiation,
1380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// copying with transformations that turn what looks like an overloaded
13811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// operator call into a use of a builtin operator, performing
1382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument-dependent lookup, etc. Subclasses may override this routine to
1383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
138460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation OpLoc,
13869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Callee,
13879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *First,
13889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Second);
13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++ "named" cast expression, such as static_cast or
1391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// reinterpret_cast.
1392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine dispatches to one of the more-specific routines
13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
139660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           Stmt::StmtClass Class,
1398b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
13999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
14029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    switch (Class) {
1405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXStaticCastExprClass:
14069d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
14089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
1409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXDynamicCastExprClass:
14119d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                    RAngleLoc, LParenLoc,
14139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    SubExpr, RParenLoc);
14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXReinterpretCastExprClass:
14169d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
14171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                        RAngleLoc, LParenLoc,
14189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                        SubExpr,
1419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        RParenLoc);
14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXConstCastExprClass:
14229d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
14231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
14249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
14251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1426b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    default:
1427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      assert(false && "Invalid C++ named cast");
1428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      break;
1429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
14301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1431f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ static_cast expression.
1435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
143860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LAngleLoc,
14409d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                            TypeSourceInfo *TInfo,
1441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RAngleLoc,
1442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LParenLoc,
14439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Expr *SubExpr,
1444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RParenLoc) {
1445c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
14469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1447c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1448c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1451b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ dynamic_cast expression.
1452b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
145560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LAngleLoc,
14579d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                             TypeSourceInfo *TInfo,
1458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RAngleLoc,
1459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LParenLoc,
14609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *SubExpr,
1461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RParenLoc) {
1462c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
14639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1464c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1465c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1467b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ reinterpret_cast expression.
1469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
147260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LAngleLoc,
14749d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                                 TypeSourceInfo *TInfo,
1475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RAngleLoc,
1476b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LParenLoc,
14779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SubExpr,
1478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RParenLoc) {
1479c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
14809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1481c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1482c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ const_cast expression.
1486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
148960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
14919d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
14949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1496c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
14979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1498c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1499c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1500b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ functional-style cast expression.
1503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1504b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1506ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1507ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation LParenLoc,
1508ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          Expr *Sub,
1509ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation RParenLoc) {
1510ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1511f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                               MultiExprArg(&Sub, 1),
1512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(type) expression.
1516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
151960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
152057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
152157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        TypeSourceInfo *Operand,
1522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1523c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
152457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
1525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
152701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(expr) expression.
1529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
153260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
153357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
15349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand,
1535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
15369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
153757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
15381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
154001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(type) expression.
154101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
154201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
154301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
154401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
154501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
154601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        TypeSourceInfo *Operand,
154701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
154801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
154901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
155001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
155101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
155201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(expr) expression.
155301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
155401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
155501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
155601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
155701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
155801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        Expr *Operand,
155901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
156001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
156101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
156201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
156301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "this" expression.
1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new "this" expression without performing any
15671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// semantic analysis. Subclasses may override this routine to provide
1568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
156960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1570ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                QualType ThisType,
1571ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                bool isImplicit) {
1572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().Owned(
1573828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                      new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1574828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                                                          isImplicit));
1575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ throw expression.
1578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
158160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
15829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXThrow(ThrowLoc, Sub);
1583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ default-argument expression.
1586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new default-argument expression, which does not
1588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// require any semantic analysis. Subclasses may override this routine to
1589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
159060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1591036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                            ParmVarDecl *Param) {
1592036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1593036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                                     Param));
1594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ zero-initialization expression.
1597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1600ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1601ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1602ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1603ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                               MultiExprArg(getSema(), 0, 0),
1605ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               RParenLoc);
1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "new" expression.
1609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
161260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
16131bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               bool UseGlobal,
16141bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementLParen,
16151bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg PlacementArgs,
16161bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementRParen,
16171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceRange TypeIdParens,
16181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               QualType AllocatedType,
16191bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               TypeSourceInfo *AllocatedTypeInfo,
16201bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               Expr *ArraySize,
16211bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorLParen,
16221bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg ConstructorArgs,
16231bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorRParen) {
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getSema().BuildCXXNew(StartLoc, UseGlobal,
1625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementLParen,
1626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(PlacementArgs),
1627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementRParen,
16284bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                 TypeIdParens,
16291bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedType,
16301bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedTypeInfo,
16319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 ArraySize,
1632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorLParen,
1633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(ConstructorArgs),
1634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorRParen);
1635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "delete" expression.
1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
164160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsGlobalDelete,
1643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsArrayForm,
16449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand) {
1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
16469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Operand);
1647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary type trait expression.
1650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
165360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
16543d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation StartLoc,
16553d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   TypeSourceInfo *T,
16563d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation RParenLoc) {
16573d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor    return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
1658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
16606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// \brief Build a new binary type trait expression.
16616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ///
16626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// By default, performs semantic analysis to build the new expression.
16636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Subclasses may override this routine to provide different behavior.
16646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
16656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation StartLoc,
16666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *LhsT,
16676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *RhsT,
16686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation RParenLoc) {
16696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
16706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
16716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
16721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new (previously unresolved) declaration reference
1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// expression.
1674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
167760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
1678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                SourceRange QualifierRange,
16792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                       const DeclarationNameInfo &NameInfo,
1680f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
1682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SS.setRange(QualifierRange);
1683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SS.setScopeRep(NNS);
1684f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1685f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (TemplateArgs)
16862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
1687f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                    *TemplateArgs);
1688f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
16892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
1690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new template-id expression.
1693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
169660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1697f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         LookupResult &R,
1698f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         bool RequiresADL,
1699d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                              const TemplateArgumentListInfo &TemplateArgs) {
1700f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
1701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
170760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstructExpr(QualType T,
17084411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                           SourceLocation Loc,
1709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           CXXConstructorDecl *Constructor,
1710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           bool IsElidable,
17118c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           MultiExprArg Args,
17128c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           bool RequiresZeroInit,
1713428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                             CXXConstructExpr::ConstructionKind ConstructKind,
1714428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           SourceRange ParenRange) {
1715ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
1716c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
17174411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                          ConvertedArgs))
1718f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1719c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
17204411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor    return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
17218c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           move_arg(ConvertedArgs),
1722428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           RequiresZeroInit, ConstructKind,
1723428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           ParenRange);
1724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1730ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1731ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1732ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           MultiExprArg Args,
1733ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1734ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
1735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
1736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
1737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1743b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1744ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1745ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation LParenLoc,
1746ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               MultiExprArg Args,
1747ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation RParenLoc) {
1748ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
1750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
1751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member reference expression.
1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
175860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
1759aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  QualType BaseType,
1760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  bool IsArrow,
1761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  SourceLocation OperatorLoc,
1762a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                              NestedNameSpecifier *Qualifier,
1763a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                  SourceRange QualifierRange,
1764129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            NamedDecl *FirstQualifierInScope,
17652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                   const DeclarationNameInfo &MemberNameInfo,
1766129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
1768a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    SS.setRange(QualifierRange);
1769a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    SS.setScopeRep(Qualifier);
17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1772aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
1773129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            SS, FirstQualifierInScope,
17742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            MemberNameInfo,
17752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            TemplateArgs);
1776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1778129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Build a new member reference expression.
17793b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  ///
17803b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
17813b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
178260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
1783aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                               QualType BaseType,
1784129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceLocation OperatorLoc,
1785129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               bool IsArrow,
1786129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               NestedNameSpecifier *Qualifier,
1787129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceRange QualifierRange,
1788c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                               NamedDecl *FirstQualifierInScope,
1789129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               LookupResult &R,
1790129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                const TemplateArgumentListInfo *TemplateArgs) {
17913b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    CXXScopeSpec SS;
17923b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    SS.setRange(QualifierRange);
17933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    SS.setScopeRep(Qualifier);
17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1796aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
1797c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            SS, FirstQualifierInScope,
1798c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            R, TemplateArgs);
17993b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
18001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// \brief Build a new noexcept expression.
18022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ///
18032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// By default, performs semantic analysis to build the new expression.
18042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// Subclasses may override this routine to provide different behavior.
18052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
18062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
18072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
18082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new Objective-C @encode expression.
1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
181360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
181481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                         TypeSourceInfo *EncodeTypeInfo,
1815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc) {
181681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
1817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                           RParenLoc));
18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
1819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
182092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C class message.
182160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
182292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
182392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
1824c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
182592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
182692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
182792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return SemaRef.BuildClassMessage(ReceiverTypeInfo,
182892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     ReceiverTypeInfo->getType(),
182992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     /*SuperLoc=*/SourceLocation(),
1830f49bb082ebf6413b2d3cb956e9c78dbb8a978c58Douglas Gregor                                     Sel, Method, LBracLoc, RBracLoc,
183192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     move(Args));
183292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
183392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
183492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C instance message.
183560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(Expr *Receiver,
183692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
183792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
1838c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
183992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
184092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
18419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildInstanceMessage(Receiver,
18429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Receiver->getType(),
184392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        /*SuperLoc=*/SourceLocation(),
1844f49bb082ebf6413b2d3cb956e9c78dbb8a978c58Douglas Gregor                                        Sel, Method, LBracLoc, RBracLoc,
184592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        move(Args));
184692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
184792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
1848f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C ivar reference expression.
1849f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
1850f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
1851f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
185260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
1853f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          SourceLocation IvarLoc,
1854f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          bool IsArrow, bool IsFreeIvar) {
1855f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    // FIXME: We lose track of the IsFreeIvar bit.
1856f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
18579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
1858f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1859f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
186060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1861f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IvarLoc,
1862d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0,
1863ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall                                                         false);
1864f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.isInvalid())
1865f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1866c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1867f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
1868f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
1869c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1871c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IvarLoc, IsArrow, SS,
1872f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
1873c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
1874f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
1875f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
1876e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor
1877e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// \brief Build a new Objective-C property reference expression.
1878e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  ///
1879e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1880e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
188160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
1882e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              ObjCPropertyDecl *Property,
1883e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              SourceLocation PropertyLoc) {
1884e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    CXXScopeSpec SS;
18859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
1886e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1887e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                   Sema::LookupMemberName);
1888e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    bool IsArrow = false;
188960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1890e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                                         /*FIME:*/PropertyLoc,
1891d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
1892e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.isInvalid())
1893f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1894c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1895e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.get())
1896e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      return move(Result);
1897c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1899c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/PropertyLoc, IsArrow,
1900c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              SS,
1901e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*FirstQualifierInScope=*/0,
1902c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
1903e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*TemplateArgs=*/0);
1904e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  }
1905c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
190612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// \brief Build a new Objective-C property reference expression.
19079cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  ///
19089cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
190912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// Subclasses may override this routine to provide different behavior.
191012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
191112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Getter,
191212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Setter,
191312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        SourceLocation PropertyLoc) {
191412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // Since these expressions can only be value-dependent, we do not
191512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // need to perform semantic analysis again.
191612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return Owned(
191712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
191812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  VK_LValue, OK_ObjCProperty,
191912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  PropertyLoc, Base));
19209cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  }
19219cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor
1922f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C "isa" expression.
1923f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
1924f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
1925f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
192660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
1927f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                      bool IsArrow) {
1928f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
19299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
1930f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1931f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
193260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1933f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IsaLoc,
1934d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
1935f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.isInvalid())
1936f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1937c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1938f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
1939f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
1940c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
19419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1942c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IsaLoc, IsArrow, SS,
1943f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
1944c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
1945f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
1946f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
1947c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new shuffle vector expression.
1949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
195260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1953f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      MultiExprArg SubExprs,
1954f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      SourceLocation RParenLoc) {
1955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Find the declaration for __builtin_shufflevector
19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const IdentifierInfo &Name
1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.Context.Idents.get("__builtin_shufflevector");
1958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Build a reference to the __builtin_shufflevector builtin
1963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
19641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Expr *Callee
1965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
1966f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                          VK_LValue, BuiltinLoc);
1967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SemaRef.UsualUnaryConversions(Callee);
19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Build the CallExpr
1970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    unsigned NumSubExprs = SubExprs.size();
1971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Expr **Subs = (Expr **)SubExprs.release();
1972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       Subs, NumSubExprs,
19745291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor                                                   Builtin->getCallResultType(),
1975f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            Expr::getValueKindForType(Builtin->getResultType()),
1976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       RParenLoc);
197760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult OwnedCall(SemaRef.Owned(TheCall));
19781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Type-check the __builtin_shufflevector expression.
198060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1982f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    OwnedCall.release();
19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return move(Result);
1986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
198743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
198843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate:
198943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformTypeInObjectScope(QualType T,
199043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      QualType ObjectType,
199143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      NamedDecl *FirstQualifierInScope,
199243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      NestedNameSpecifier *Prefix);
199343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
199443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
199543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             QualType ObjectType,
199643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             NamedDecl *FirstQualifierInScope,
199743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             NestedNameSpecifier *Prefix);
1998577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor};
1999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
200043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
200160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
200243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!S)
200343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return SemaRef.Owned(S);
20041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
200543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  switch (S->getStmtClass()) {
200643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::NoStmtClass: break;
20071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
200843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform individual statement nodes
200943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                                              \
201043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
201143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent)
20124bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
20131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
201443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform expressions by calling TransformExpr.
201543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)
20167381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
201743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class:
20184bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
201943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    {
202060d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
202143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      if (E.isInvalid())
2022f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
20231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
202543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    }
20261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
20271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
202943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
20301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2032670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived>
203360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!E)
2035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(E);
2036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  switch (E->getStmtClass()) {
2038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::NoStmtClass: break;
2039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break;
20407381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
2041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                                              \
2042454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall    case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
20434bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
20441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
2047657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor}
2048657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor
2049657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived>
2050dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
2051dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
2052a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     SourceRange Range,
2053c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                     QualType ObjectType,
2054c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                             NamedDecl *FirstQualifierInScope) {
205543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  NestedNameSpecifier *Prefix = NNS->getPrefix();
20561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
205743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the prefix of this nested name specifier.
2058dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  if (Prefix) {
20591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
2060c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                       ObjectType,
2061c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                       FirstQualifierInScope);
2062dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    if (!Prefix)
2063dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return 0;
2064dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
20651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2066dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  switch (NNS->getKind()) {
2067dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Identifier:
206843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (Prefix) {
206943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // The object type and qualifier-in-scope really apply to the
207043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // leftmost entity.
207143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      ObjectType = QualType();
207243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      FirstQualifierInScope = 0;
207343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
207443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
20751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert((Prefix || !ObjectType.isNull()) &&
2076a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor            "Identifier nested-name-specifier with no prefix or object type");
2077a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2078a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor        ObjectType.isNull())
2079dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2082a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                   *NNS->getAsIdentifier(),
2083c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   ObjectType,
2084c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   FirstQualifierInScope);
20851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2086dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Namespace: {
20871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NamespaceDecl *NS
2088dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      = cast_or_null<NamespaceDecl>(
20897c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                    getDerived().TransformDecl(Range.getBegin(),
20907c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       NNS->getAsNamespace()));
20911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (!getDerived().AlwaysRebuild() &&
2092dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        Prefix == NNS->getPrefix() &&
2093dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        NS == NNS->getAsNamespace())
2094dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
20951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2096dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2097dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2099dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Global:
2100dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    // There is no meaningful transformation that one could perform on the
2101dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    // global scope.
2102dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return NNS;
21031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2104dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::TypeSpecWithTemplate:
2105dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::TypeSpec: {
2106fbf2c945f8f8bbfe0459d45c03f9ff34bb445c81Douglas Gregor    TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
210743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
210843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            ObjectType,
210943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            FirstQualifierInScope,
211043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            Prefix);
2111d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (T.isNull())
2112d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return 0;
21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2114dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
2115dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        Prefix == NNS->getPrefix() &&
2116dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        T == QualType(NNS->getAsType(), 0))
2117dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
2121edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                   T);
2122dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
2123dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
21241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2125dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  // Required to silence a GCC warning
21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return 0;
2127dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
2128dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
2129dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
21302577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo
21312577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived>
213243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
21332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name = NameInfo.getName();
213481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  if (!Name)
21352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo();
213681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
213781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  switch (Name.getNameKind()) {
213881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::Identifier:
213981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCZeroArgSelector:
214081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCOneArgSelector:
214181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCMultiArgSelector:
214281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXOperatorName:
21433e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  case DeclarationName::CXXLiteralOperatorName:
214481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXUsingDirective:
21452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NameInfo;
21461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
214781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConstructorName:
214881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXDestructorName:
214981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConversionFunctionName: {
21502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *NewTInfo;
21512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CanQualType NewCanTy;
21522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
215343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewTInfo = getDerived().TransformType(OldTInfo);
215443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NewTInfo)
215543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall        return DeclarationNameInfo();
215643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
21572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
21582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    else {
21592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewTInfo = 0;
21602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
216143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      QualType NewT = getDerived().TransformType(Name.getCXXNameType());
21622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      if (NewT.isNull())
21632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        return DeclarationNameInfo();
21642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewCanTy = SemaRef.Context.getCanonicalType(NewT);
21652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
21661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationName NewName
21682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
21692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                           NewCanTy);
21702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NewNameInfo(NameInfo);
21712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setName(NewName);
21722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setNamedTypeInfo(NewTInfo);
21732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NewNameInfo;
217481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  }
21751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
21761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  assert(0 && "Unknown name kind.");
21782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return DeclarationNameInfo();
217981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor}
218081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
218181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived>
21821eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
21833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas GregorTreeTransform<Derived>::TransformTemplateName(TemplateName Name,
218443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              QualType ObjectType,
218543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              NamedDecl *FirstQualifierInScope) {
21867c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  SourceLocation Loc = getDerived().getBaseLocation();
21877c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor
2188d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NestedNameSpecifier *NNS
2190d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
219143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  /*FIXME*/ SourceRange(Loc),
219243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  ObjectType,
219343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  FirstQualifierInScope);
2194d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!NNS)
2195d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return TemplateName();
21961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2197d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (TemplateDecl *Template = QTN->getTemplateDecl()) {
21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      TemplateDecl *TransTemplate
21997c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor        = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2200d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      if (!TransTemplate)
2201d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        return TemplateName();
22021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2203d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      if (!getDerived().AlwaysRebuild() &&
2204d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor          NNS == QTN->getQualifier() &&
2205d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor          TransTemplate == Template)
2206d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        return Name;
22071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2208d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2209d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                              TransTemplate);
2210d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    }
22111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2212f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // These should be getting filtered out before they make it into the AST.
221343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    llvm_unreachable("overloaded template name survived to here");
2214d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
22151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2216d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
221743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    NestedNameSpecifier *NNS = DTN->getQualifier();
221843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (NNS) {
221943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NNS = getDerived().TransformNestedNameSpecifier(NNS,
222043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  /*FIXME:*/SourceRange(Loc),
222143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ObjectType,
222243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      FirstQualifierInScope);
222343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NNS) return TemplateName();
222443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
222543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // These apply to the scope specifier, not the template.
222643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      ObjectType = QualType();
222743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      FirstQualifierInScope = 0;
222843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
22291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2230d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2231dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor        NNS == DTN->getQualifier() &&
2232dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor        ObjectType.isNull())
2233d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return Name;
22341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22351efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    if (DTN->isIdentifier()) {
22361efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      // FIXME: Bad range
22371efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      SourceRange QualifierRange(getDerived().getBaseLocation());
22381efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      return getDerived().RebuildTemplateName(NNS, QualifierRange,
22391efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                              *DTN->getIdentifier(),
224043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              ObjectType,
224143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              FirstQualifierInScope);
22421efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    }
2243c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2244c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2245ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            ObjectType);
2246d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
22471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2248d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
22491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TemplateDecl *TransTemplate
22507c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2251d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!TransTemplate)
2252d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return TemplateName();
22531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2254d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2255d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        TransTemplate == Template)
2256d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return Name;
22571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2258d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    return TemplateName(TransTemplate);
2259d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
22601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2261f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // These should be getting filtered out before they reach the AST.
226243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  llvm_unreachable("overloaded function decl survived to here");
2263f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return TemplateName();
2264d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
2265d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
2266d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
2267833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc(
2268833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgument &Arg,
2269833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2270833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation Loc = getDerived().getBaseLocation();
2271670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  switch (Arg.getKind()) {
2272670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Null:
22739f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("null template argument in TreeTransform");
2274833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2275833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2276833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
2277833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg,
2278a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall               SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2279c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2280833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2281833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2282788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
2283788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2284788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    break;
2285c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2286833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
2287833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2288833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2289833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2290833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
2291670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Integral:
2292833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
2293828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2294833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2295833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
2296833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
2297833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2298833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived>
2299833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument(
2300833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgumentLoc &Input,
2301833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2302833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgument &Arg = Input.getArgument();
2303833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
2304833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
2305833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
2306833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = Input;
2307833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2309670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Type: {
2310a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *DI = Input.getTypeSourceInfo();
2311833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (DI == NULL)
2312a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall      DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2313833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2314833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    DI = getDerived().TransformType(DI);
2315833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!DI) return true;
2316833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2317833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2318833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2319670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
23201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2321670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Declaration: {
2322833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // FIXME: we should never have to transform one of these.
2323972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    DeclarationName Name;
2324972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2325972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor      Name = ND->getDeclName();
2326788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemporaryBase Rebase(*this, Input.getLocation(), Name);
23277c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2328833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!D) return true;
2329833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2330828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Expr *SourceExpr = Input.getSourceDeclExpression();
2331828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    if (SourceExpr) {
2332828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      EnterExpressionEvaluationContext Unevaluated(getSema(),
2333f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Sema::Unevaluated);
233460d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(SourceExpr);
23359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      SourceExpr = (E.isInvalid() ? 0 : E.take());
2336828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    }
2337828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
2338828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2339833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2340670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
23411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2342788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template: {
2343c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2344788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemplateName Template
2345788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      = getDerived().TransformTemplateName(Arg.getAsTemplate());
2346788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    if (Template.isNull())
2347788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      return true;
2348c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2349788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(Template),
2350788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateQualifierRange(),
2351788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateNameLoc());
2352788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return false;
2353788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  }
2354c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2355670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Expression: {
2356670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    // Template argument expressions are not potentially evaluated.
23571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EnterExpressionEvaluationContext Unevaluated(getSema(),
2358f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                 Sema::Unevaluated);
23591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2360833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Expr *InputExpr = Input.getSourceExpression();
2361833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2362833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
236360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult E
2364833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = getDerived().TransformExpr(InputExpr);
2365833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (E.isInvalid()) return true;
23669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2367833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2368670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
23691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2370670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Pack: {
2371670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2372670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    TransformedArgs.reserve(Arg.pack_size());
23731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2374670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor                                      AEnd = Arg.pack_end();
2375670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor         A != AEnd; ++A) {
23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2377833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // FIXME: preserve source information here when we start
2378833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // caring about parameter packs.
2379833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2380828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc InputArg;
2381828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc OutputArg;
2382828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      getDerived().InventTemplateArgumentLoc(*A, InputArg);
2383828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2384833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall        return true;
2385833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2386828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TransformedArgs.push_back(OutputArg.getArgument());
2387670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    }
2388910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
2389910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    TemplateArgument *TransformedArgsPtr
2390910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2391910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2392910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor              TransformedArgsPtr);
2393910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2394910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                                  TransformedArgs.size()),
2395910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                 Input.getLocInfo());
2396833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2397670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
2398670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
23991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2400670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Work around bogus GCC warning
2401833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return true;
2402670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor}
2403670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
2404577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
2405577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation
2406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
2407577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2408577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
240943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) {
2410577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (getDerived().AlreadyTransformed(T))
2411577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T;
24121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2413a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Temporary workaround.  All of these transformations should
2414a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // eventually turn into transformations on TypeLocs.
2415a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
24164802a311f402836f1f226a3d7a87e6a3088f9704John McCall  DI->getTypeLoc().initialize(getDerived().getBaseLocation());
2417c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
241843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
24191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2420a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (!NewDI)
2421a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
24221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return NewDI->getType();
2424577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
24251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2426577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
242743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
2428a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlreadyTransformed(DI->getType()))
2429a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return DI;
24301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2431a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLocBuilder TLB;
24321bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
2433a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLoc TL = DI->getTypeLoc();
2434a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TLB.reserve(TL.getFullDataSize());
24351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
243643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, TL);
2437a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
2438a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return 0;
24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2440a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2441577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
24421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2444a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
244543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2446a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  switch (T.getTypeLocClass()) {
2447a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
2448a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \
2449a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  case TypeLoc::CLASS: \
245043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2451a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
2452a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2453577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
24549f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("unhandled type loc!");
2455a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return QualType();
2456577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
24571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2458a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types
2459a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers
2460a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function
2461a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but
2462a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients.
24631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
24641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
2465a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
246643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               QualifiedTypeLoc T) {
2467a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers Quals = T.getType().getLocalQualifiers();
2468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
246943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
2471577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2473a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Silently suppress qualifiers if the result type can't be qualified.
2474a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: this is the right thing for template instantiation, but
2475a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // probably not for other clients.
2476a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result->isFunctionType() || Result->isReferenceType())
2477a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return Result;
24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24792865474261a608c7873b87ba4af110d17907896dJohn McCall  if (!Quals.empty()) {
24802865474261a608c7873b87ba4af110d17907896dJohn McCall    Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
24812865474261a608c7873b87ba4af110d17907896dJohn McCall    TLB.push<QualifiedTypeLoc>(Result);
24822865474261a608c7873b87ba4af110d17907896dJohn McCall    // No location information to preserve.
24832865474261a608c7873b87ba4af110d17907896dJohn McCall  }
2484a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2485a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2486a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
2487a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
248843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// \brief Transforms a type that was written in a scope specifier,
248943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// given an object type, the results of unqualified lookup, and
249043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// an already-instantiated prefix.
249143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall///
249243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// The object type is provided iff the scope specifier qualifies the
249343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// member of a dependent member-access expression.  The prefix is
249443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// provided iff the the scope specifier in which this appears has a
249543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// prefix.
249643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall///
249743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// This is private to TreeTransform.
249843fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
249943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType
250043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
250143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
250243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
250343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *Prefix) {
250443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
250543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return T;
250643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
250743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TSI =
250843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
250943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
251043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
251143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                UnqualLookup, Prefix);
251243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (!TSI) return QualType();
251343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TSI->getType();
251443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
251543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
251643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
251743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *
251843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
251943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
252043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
252143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *Prefix) {
252243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: in some cases, we might be some verification to do here.
252343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (ObjectType.isNull())
252443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().TransformType(TSI);
252543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
252643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType T = TSI->getType();
252743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
252843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return TSI;
252943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
253043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeLocBuilder TLB;
253143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result;
253243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
253343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (isa<TemplateSpecializationType>(T)) {
253443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateSpecializationTypeLoc TL
253543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
253643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
253743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateName Template =
253843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
253943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         ObjectType, UnqualLookup);
254043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (Template.isNull()) return 0;
254143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
254243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived()
254343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      .TransformTemplateSpecializationType(TLB, TL, Template);
254443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else if (isa<DependentTemplateSpecializationType>(T)) {
254543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    DependentTemplateSpecializationTypeLoc TL
254643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
254743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
254843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived()
254943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
255043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else {
255143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    // Nothing special needs to be done for these.
255243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
255343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
255443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
255543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Result.isNull()) return 0;
255643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
255743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
255843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
2559a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline
2560a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2561a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TyLoc NewT = TLB.push<TyLoc>(T.getType());
2562a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewT.setNameLoc(T.getNameLoc());
2563a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return T.getType();
2564a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
2565a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2566a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
2567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
256843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      BuiltinTypeLoc T) {
2569ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2570ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  NewT.setBuiltinLoc(T.getBuiltinLoc());
2571ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (T.needsExtraLocalData())
2572ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2573ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  return T.getType();
2574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
2575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
25761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2577a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
257843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ComplexTypeLoc T) {
2579a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: recurse?
2580a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, T);
2581a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
25821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2583a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
2584a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
258543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      PointerTypeLoc TL) {
2586c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType PointeeType
2587c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
258892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (PointeeType.isNull())
258992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return QualType();
259092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
259192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  QualType Result = TL.getType();
2592c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (PointeeType->getAs<ObjCObjectType>()) {
259392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // A dependent pointer type 'T *' has is being transformed such
259492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // that an Objective-C class type is being replaced for 'T'. The
259592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // resulting pointer type is an ObjCObjectPointerType, not a
259692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // PointerType.
2597c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
2598c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2599c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2600c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NewT.setStarLoc(TL.getStarLoc());
260192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return Result;
260292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
260343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
260492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (getDerived().AlwaysRebuild() ||
260592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      PointeeType != TL.getPointeeLoc().getType()) {
260692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
260792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Result.isNull())
260892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      return QualType();
260992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
2610c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
261192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
261292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
2613c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Result;
2614577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
2615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
26171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
2618a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
261943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  BlockPointerTypeLoc TL) {
2620db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  QualType PointeeType
2621c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
2622c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (PointeeType.isNull())
2623c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return QualType();
2624c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2625c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType Result = TL.getType();
2626c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (getDerived().AlwaysRebuild() ||
2627c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      PointeeType != TL.getPointeeLoc().getType()) {
2628c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Result = getDerived().RebuildBlockPointerType(PointeeType,
2629db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor                                                  TL.getSigilLoc());
2630db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor    if (Result.isNull())
2631db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor      return QualType();
2632db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  }
2633db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor
263439968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
2635db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
2636db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  return Result;
2637a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
26381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
263985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type.  Note that somewhat paradoxically we
264085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value
264185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type;  we only care if the type was *written* as an l-value type
264285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type.
264385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived>
264485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType
264585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
264643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ReferenceTypeLoc TL) {
264785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  const ReferenceType *T = TL.getTypePtr();
264885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
264985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // Note that this works with the pointee-as-written.
265085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
265185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (PointeeType.isNull())
265285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return QualType();
265385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
265485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType Result = TL.getType();
265585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (getDerived().AlwaysRebuild() ||
265685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      PointeeType != T->getPointeeTypeAsWritten()) {
265785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildReferenceType(PointeeType,
265885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               T->isSpelledAsLValue(),
265985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               TL.getSigilLoc());
266085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    if (Result.isNull())
266185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      return QualType();
266285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
266385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
266485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // r-value references can be rebuilt as l-value references.
266585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  ReferenceTypeLoc NewTL;
266685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (isa<LValueReferenceType>(Result))
266785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
266885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  else
266985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
267085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
267185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
267285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  return Result;
267385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall}
267485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
2675a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
2676a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
2677a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
267843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 LValueReferenceTypeLoc TL) {
267943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
2680a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
26811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2682a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
2683a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
2684a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
268543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 RValueReferenceTypeLoc TL) {
268643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
2687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
26881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
26901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
2691a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
269243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   MemberPointerTypeLoc TL) {
2693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerType *T = TL.getTypePtr();
2694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (PointeeType.isNull())
2697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
26981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2699a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // TODO: preserve source information for this.
2700a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ClassType
2701a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformType(QualType(T->getClass(), 0));
2702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ClassType.isNull())
2703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
27041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2705a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      PointeeType != T->getPointeeType() ||
2708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ClassType != QualType(T->getClass(), 0)) {
270985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
271085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getStarLoc());
2711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2714577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2715a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
2717a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
2720577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
27211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
27221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
2723a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
272443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ConstantArrayTypeLoc TL) {
2725a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayType *T = TL.getTypePtr();
2726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
27291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2730a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2731a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2732a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
2733a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildConstantArrayType(ElementType,
2734a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
2735a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSize(),
273685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             T->getIndexTypeCVRQualifiers(),
273785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
2738a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2739a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2740a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2741c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2743a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
2744a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
27451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2746a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = TL.getSizeExpr();
2747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Size) {
2748f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2749a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2750a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2751a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
2752a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2753a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2754577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2756577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
2757577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType(
2758a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                              TypeLocBuilder &TLB,
275943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              IncompleteArrayTypeLoc TL) {
2760a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayType *T = TL.getTypePtr();
2761a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2762577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2763577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
27641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2765a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2766a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2767a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
2768a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildIncompleteArrayType(ElementType,
2769a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                     T->getSizeModifier(),
277085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                           T->getIndexTypeCVRQualifiers(),
277185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                     TL.getBracketsRange());
2772a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2773a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2774a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2775c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2776a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2777a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
2778a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
2779a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(0);
2780577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2781a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2782577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
27831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2784577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
2785a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
2786a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
278743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   VariableArrayTypeLoc TL) {
2788a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayType *T = TL.getTypePtr();
2789a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2790577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2791577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
27921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2793670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
2794f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2795670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
279660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
2797a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
2798a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
2799577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Size = SizeResult.take();
2802a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2804a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2805a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
2806a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
2807a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildVariableArrayType(ElementType,
2808a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
28099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Size,
2810a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                             T->getIndexTypeCVRQualifiers(),
281185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
2812a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2813a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2814577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
2815c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2816a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2817a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
2818a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
2819a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
28201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2822577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
28231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2825a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
2826a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
282743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             DependentSizedArrayTypeLoc TL) {
2828a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DependentSizedArrayType *T = TL.getTypePtr();
2829a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2830577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2831577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2833670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
2834f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
28351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
283660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
2837a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
2838a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
2839577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2841a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = static_cast<Expr*>(SizeResult.get());
2842a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2843a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2844a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2845a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
2846a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
2847a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2848a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                         T->getSizeModifier(),
28499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                         Size,
2850a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                T->getIndexTypeCVRQualifiers(),
285185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                        TL.getBracketsRange());
2852a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2853a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2854577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
2855a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else SizeResult.take();
28561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2857a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // We might have any sort of array type now, but fortunately they
2858a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // all have the same location layout.
2859a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2860a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
2861a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
2862a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
2863a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2864a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2865577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
28661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2868577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
2869a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                      TypeLocBuilder &TLB,
287043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentSizedExtVectorTypeLoc TL) {
2871a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DependentSizedExtVectorType *T = TL.getTypePtr();
2872a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2873a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: ext vector locs should be nested
2874577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
2875577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2876577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2878670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Vector sizes are not potentially evaluated contexts
2879f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2880670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
288160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2882577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (Size.isInvalid())
2883577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2885a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2886a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2887eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      ElementType != T->getElementType() ||
2888eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      Size.get() != T->getSizeExpr()) {
2889a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
28909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                             Size.take(),
2891577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                         T->getAttributeLoc());
2892a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2893a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2894a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2895a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2896a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Result might be dependent or not.
2897a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (isa<DependentSizedExtVectorType>(Result)) {
2898a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    DependentSizedExtVectorTypeLoc NewTL
2899a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2900a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
2901a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  } else {
2902a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2903a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
2904a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2905a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2906a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2907577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
29081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2910a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
291143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     VectorTypeLoc TL) {
2912a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorType *T = TL.getTypePtr();
2913577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
2914577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2915577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
2916577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2917a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2918a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2919a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
292082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2921e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                            T->getVectorKind());
2922a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2923a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2924a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2925c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2926a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2927a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
29281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2929a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2930577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
29311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2933a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
293443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        ExtVectorTypeLoc TL) {
2935a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorType *T = TL.getTypePtr();
2936577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
2937577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2938577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
29391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2940a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2941a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2942a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
2943a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildExtVectorType(ElementType,
2944a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               T->getNumElements(),
2945a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               /*FIXME*/ SourceLocation());
2946a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2947a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2948a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2949c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2950a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2951a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
29521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2953a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2954577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
2955577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
29561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
295721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl *
295821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
295921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
296021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
296121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (!NewDI)
296221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return 0;
296321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
296421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (NewDI == OldDI)
296521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return OldParm;
296621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  else
296721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return ParmVarDecl::Create(SemaRef.Context,
296821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getDeclContext(),
296921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getLocation(),
297021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getIdentifier(),
297121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               NewDI->getType(),
297221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               NewDI,
297321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getStorageClass(),
297416573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor                               OldParm->getStorageClassAsWritten(),
297521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               /* DefArg */ NULL);
297621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
297721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
297821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
297921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>::
298021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
298121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                              llvm::SmallVectorImpl<QualType> &PTypes,
298221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                              llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2983a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoType *T = TL.getTypePtr();
29841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2985a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2986a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ParmVarDecl *OldParm = TL.getArg(i);
2987a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2988a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    QualType NewType;
2989a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ParmVarDecl *NewParm;
2990a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2991a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (OldParm) {
299221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      NewParm = getDerived().TransformFunctionTypeParam(OldParm);
299321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      if (!NewParm)
299421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
2995a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NewType = NewParm->getType();
2996a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2997a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // Deal with the possibility that we don't have a parameter
2998a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // declaration for this parameter.
2999a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    } else {
3000a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NewParm = 0;
3001a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3002a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      QualType OldType = T->getArgType(i);
3003a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NewType = getDerived().TransformType(OldType);
3004a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      if (NewType.isNull())
300521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3006a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    }
30071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
300821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    PTypes.push_back(NewType);
300921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    PVars.push_back(NewParm);
3010577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
30111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
301221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  return false;
301321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
301421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
301521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
301621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType
301721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
301843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   FunctionProtoTypeLoc TL) {
30197e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // Transform the parameters and return type.
30207e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
30217e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // We instantiate in source order, with the return type first followed by
30227e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // the parameters, because users tend to expect this (even if they shouldn't
30237e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // rely on it!).
30247e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
3025dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // When the function has a trailing return type, we instantiate the
3026dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // parameters before the return type,  since the return type can then refer
3027dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // to the parameters themselves (via decltype, sizeof, etc.).
3028dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
302921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<QualType, 4> ParamTypes;
303021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
3031895162da2d52f4243f61081d7436de66af4503fcDouglas Gregor  FunctionProtoType *T = TL.getTypePtr();
30327e010a04fef171049291d8cb3047f118566da090Douglas Gregor
3033dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  QualType ResultType;
3034dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3035dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  if (TL.getTrailingReturn()) {
3036dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3037dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3038dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3039dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3040dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
3041dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3042dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
3043dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  else {
3044dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3045dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
3046dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3047dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3048dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3049dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3050dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
3051dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3052a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3053a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3054a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType() ||
3055a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3056a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionProtoType(ResultType,
3057a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.data(),
3058a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.size(),
3059a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->isVariadic(),
3060fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getTypeQuals(),
3061fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getExtInfo());
3062a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3063a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3064a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
30651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3066a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3067a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3068a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3069dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(TL.getTrailingReturn());
3070a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3071a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setArg(i, ParamDecls[i]);
3072a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3073a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3074577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
30751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3076577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3077577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType(
3078a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                 TypeLocBuilder &TLB,
307943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 FunctionNoProtoTypeLoc TL) {
3080a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoType *T = TL.getTypePtr();
3081a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3082a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (ResultType.isNull())
3083a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
3084a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3085a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3086a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3087a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType())
3088a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3089a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3090a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3091a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3092a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3093dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(false);
3094a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3095a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3096577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
30971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3098ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType
3099ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
310043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 UnresolvedUsingTypeLoc TL) {
3101ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingType *T = TL.getTypePtr();
31027c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
3103ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (!D)
3104ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return QualType();
3105ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3106ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType Result = TL.getType();
3107ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3108ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Result = getDerived().RebuildUnresolvedUsingType(D);
3109ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    if (Result.isNull())
3110ed97649e9574b9d854fa4d6109c9333ae0993554John McCall      return QualType();
3111ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3112ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3113ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // We might get an arbitrary type spec type back.  We should at
3114ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // least always get a type spec type, though.
3115ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3116ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  NewTL.setNameLoc(TL.getNameLoc());
3117ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3118ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return Result;
3119ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
3120ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3122a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
312343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypedefTypeLoc TL) {
3124a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefType *T = TL.getTypePtr();
3125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  TypedefDecl *Typedef
31267c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
31277c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           T->getDecl()));
3128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Typedef)
3129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
31301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Typedef != T->getDecl()) {
3134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildTypedefType(Typedef);
3135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3136a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3137a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3139a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3140a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
31411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3145577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
314743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypeOfExprTypeLoc TL) {
3148670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // typeof expressions are not potentially evaluated contexts
3149f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
31501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
315160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
3152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
3153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3155a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3157cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      E.get() != TL.getUnderlyingExpr()) {
31582a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
3159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3160a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3161577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3162a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
31631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3164a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
3165cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
3166cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3167cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3168a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3169a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3170577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3173a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
317443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     TypeOfTypeLoc TL) {
3175cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3176cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3177cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (!New_Under_TI)
3178577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
31791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3180a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3181cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3182cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
3183a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3184a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
31861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
3188cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
3189cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3190cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3191cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setUnderlyingTInfo(New_Under_TI);
3192a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3193a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3194577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3197a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
319843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                       DecltypeTypeLoc TL) {
3199a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeType *T = TL.getTypePtr();
3200a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3201670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // decltype expressions are not potentially evaluated contexts
3202f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
32031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
320460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3205577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
3206577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      E.get() != T->getUnderlyingExpr()) {
32112a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
3212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3214577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
3216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3218a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
32191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3220a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3221577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3222577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3223577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3224a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
322543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     RecordTypeLoc TL) {
3226a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordType *T = TL.getTypePtr();
3227577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  RecordDecl *Record
32287c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
32297c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                          T->getDecl()));
3230577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Record)
3231577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3233a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3234a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3235a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Record != T->getDecl()) {
3236a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildRecordType(Record);
3237a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3238a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3239a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
32401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3241a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3242a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
3243a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3244a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3245577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
32461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
324943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   EnumTypeLoc TL) {
3250a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumType *T = TL.getTypePtr();
3251577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  EnumDecl *Enum
32527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
32537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                        T->getDecl()));
3254577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Enum)
3255577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3257a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3258a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3259a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Enum != T->getDecl()) {
3260a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildEnumType(Enum);
3261a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3262a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3263a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3265a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3266a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
32671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3268a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3269577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
32707da2431c23ef1ee8acb114e39692246e1801afc2John McCall
32713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived>
32723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType(
32733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         TypeLocBuilder &TLB,
327443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         InjectedClassNameTypeLoc TL) {
32753cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
32763cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                       TL.getTypePtr()->getDecl());
32773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  if (!D) return QualType();
32783cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
32793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
32803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
32813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  return T;
32823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
32833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
32841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType(
3287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                TypeLocBuilder &TLB,
328843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TemplateTypeParmTypeLoc TL) {
3289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
3290577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3291577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
32921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
329349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
3294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                         TypeLocBuilder &TLB,
329543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         SubstTemplateTypeParmTypeLoc TL) {
3296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
329749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
329849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
329949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived>
3300833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
330143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        TypeLocBuilder &TLB,
330243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                           TemplateSpecializationTypeLoc TL) {
330343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
3304828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
330543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TemplateName Template
330643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformTemplateName(T->getTemplateName());
330743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Template.isNull())
330843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
3309833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
331043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3311dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor}
331243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
331343fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived>
3314577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3315833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                        TypeLocBuilder &TLB,
3316833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                           TemplateSpecializationTypeLoc TL,
331743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TemplateName Template) {
3318833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
3319833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3320d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo NewTemplateArgs;
3321d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3322d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3323d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
3324d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3325d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TemplateArgumentLoc Loc;
3326d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
3327577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      return QualType();
3328d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    NewTemplateArgs.addArgument(Loc);
3329d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
33301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3331833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  // FIXME: maybe don't rebuild if all the template arguments are the same.
3332833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3333833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType Result =
3334833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getDerived().RebuildTemplateSpecializationType(Template,
3335833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                   TL.getTemplateNameLoc(),
3336d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NewTemplateArgs);
33371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3338833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  if (!Result.isNull()) {
3339833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TemplateSpecializationTypeLoc NewTL
3340833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = TLB.push<TemplateSpecializationTypeLoc>(Result);
3341833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3342833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setLAngleLoc(TL.getLAngleLoc());
3343833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setRAngleLoc(TL.getRAngleLoc());
3344833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3345833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
3346833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
33471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3348833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return Result;
3349577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3352a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3353465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
335443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ElaboratedTypeLoc TL) {
3355465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType *T = TL.getTypePtr();
3356465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3357465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  NestedNameSpecifier *NNS = 0;
3358465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // NOTE: the qualifier in an ElaboratedType is optional.
3359465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  if (T->getQualifier() != 0) {
3360465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
336143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                    TL.getQualifierRange());
3362465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (!NNS)
3363465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      return QualType();
3364465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
33651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
336643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
336743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (NamedT.isNull())
336843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
3369a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar
3370a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3371a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3372a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NNS != T->getQualifier() ||
3373e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      NamedT != T->getNamedType()) {
337421e413fe6305a198564d436ac515497716c47844John McCall    Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
337521e413fe6305a198564d436ac515497716c47844John McCall                                                T->getKeyword(), NNS, NamedT);
3376a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3377a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3378a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3379577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3380465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3381e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setKeywordLoc(TL.getKeywordLoc());
3382e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setQualifierRange(TL.getQualifierRange());
3383a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3384a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3385577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
33884714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
338943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      DependentNameTypeLoc TL) {
33904714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  DependentNameType *T = TL.getTypePtr();
3391833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3392577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  NestedNameSpecifier *NNS
3393e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
339443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TL.getQualifierRange());
3395577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!NNS)
3396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
339833500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType Result
339933500955d731c73717af52088b7fc0e7a85681e7John McCall    = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
340033500955d731c73717af52088b7fc0e7a85681e7John McCall                                            T->getIdentifier(),
340133500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getKeywordLoc(),
340233500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getQualifierRange(),
340333500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getNameLoc());
3404a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3405a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
3406a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3407e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3408e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    QualType NamedT = ElabT->getNamedType();
340933500955d731c73717af52088b7fc0e7a85681e7John McCall    TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
341033500955d731c73717af52088b7fc0e7a85681e7John McCall
3411e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3412e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
3413e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setQualifierRange(TL.getQualifierRange());
341433500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
3415e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3416e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
3417e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setQualifierRange(TL.getQualifierRange());
3418e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setNameLoc(TL.getNameLoc());
3419e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
3420a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3423577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
342433500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>::
342533500955d731c73717af52088b7fc0e7a85681e7John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
342643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL) {
342733500955d731c73717af52088b7fc0e7a85681e7John McCall  DependentTemplateSpecializationType *T = TL.getTypePtr();
342833500955d731c73717af52088b7fc0e7a85681e7John McCall
342933500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS
343033500955d731c73717af52088b7fc0e7a85681e7John McCall    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
343143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TL.getQualifierRange());
343233500955d731c73717af52088b7fc0e7a85681e7John McCall  if (!NNS)
343333500955d731c73717af52088b7fc0e7a85681e7John McCall    return QualType();
343433500955d731c73717af52088b7fc0e7a85681e7John McCall
343543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived()
343643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall           .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
343743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
343843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
343943fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
344043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::
344143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
344243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL,
344343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *NNS) {
344443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  DependentTemplateSpecializationType *T = TL.getTypePtr();
344543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
344633500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentListInfo NewTemplateArgs;
344733500955d731c73717af52088b7fc0e7a85681e7John McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
344833500955d731c73717af52088b7fc0e7a85681e7John McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
344933500955d731c73717af52088b7fc0e7a85681e7John McCall
345033500955d731c73717af52088b7fc0e7a85681e7John McCall  for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
345133500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateArgumentLoc Loc;
345233500955d731c73717af52088b7fc0e7a85681e7John McCall    if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
345333500955d731c73717af52088b7fc0e7a85681e7John McCall      return QualType();
345433500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTemplateArgs.addArgument(Loc);
345533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
345633500955d731c73717af52088b7fc0e7a85681e7John McCall
34571efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor  QualType Result
34581efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
34591efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              NNS,
34601efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                        TL.getQualifierRange(),
34611efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                            T->getIdentifier(),
34621efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              TL.getNameLoc(),
34631efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              NewTemplateArgs);
346433500955d731c73717af52088b7fc0e7a85681e7John McCall  if (Result.isNull())
346533500955d731c73717af52088b7fc0e7a85681e7John McCall    return QualType();
346633500955d731c73717af52088b7fc0e7a85681e7John McCall
346733500955d731c73717af52088b7fc0e7a85681e7John McCall  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
346833500955d731c73717af52088b7fc0e7a85681e7John McCall    QualType NamedT = ElabT->getNamedType();
346933500955d731c73717af52088b7fc0e7a85681e7John McCall
347033500955d731c73717af52088b7fc0e7a85681e7John McCall    // Copy information relevant to the template specialization.
347133500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateSpecializationTypeLoc NamedTL
347233500955d731c73717af52088b7fc0e7a85681e7John McCall      = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
347333500955d731c73717af52088b7fc0e7a85681e7John McCall    NamedTL.setLAngleLoc(TL.getLAngleLoc());
347433500955d731c73717af52088b7fc0e7a85681e7John McCall    NamedTL.setRAngleLoc(TL.getRAngleLoc());
347533500955d731c73717af52088b7fc0e7a85681e7John McCall    for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
347633500955d731c73717af52088b7fc0e7a85681e7John McCall      NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
347733500955d731c73717af52088b7fc0e7a85681e7John McCall
347833500955d731c73717af52088b7fc0e7a85681e7John McCall    // Copy information relevant to the elaborated type.
347933500955d731c73717af52088b7fc0e7a85681e7John McCall    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
348033500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTL.setKeywordLoc(TL.getKeywordLoc());
348133500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTL.setQualifierRange(TL.getQualifierRange());
348233500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
3483e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor    TypeLoc NewTL(Result, TL.getOpaqueData());
3484e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor    TLB.pushFullCopy(NewTL);
348533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
348633500955d731c73717af52088b7fc0e7a85681e7John McCall  return Result;
348733500955d731c73717af52088b7fc0e7a85681e7John McCall}
348833500955d731c73717af52088b7fc0e7a85681e7John McCall
348933500955d731c73717af52088b7fc0e7a85681e7John McCalltemplate<typename Derived>
3490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3491a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
349243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ObjCInterfaceTypeLoc TL) {
3493ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCInterfaceType is never dependent.
3494c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
3495c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return TL.getType();
3496c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3497c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3498c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived>
3499c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType
3500c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
350143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjCObjectTypeLoc TL) {
3502c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // ObjCObjectType is never dependent.
3503c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
3504ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
3505577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3508a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3509a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
351043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ObjCObjectPointerTypeLoc TL) {
3511ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCObjectPointerType is never dependent.
3512c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
3513ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
351424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}
351524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis
3516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
351743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation
351843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
351943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
352060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
35211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
35223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
352343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
352443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
352543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
352660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
352743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
352843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().TransformCompoundStmt(S, false);
352943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
353043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
353143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
353260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
35331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
353443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              bool IsStmtExpr) {
35357114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  bool SubStmtInvalid = false;
353643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool SubStmtChanged = false;
3537ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Statements(getSema());
353843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
353943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       B != BEnd; ++B) {
354060d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Result = getDerived().TransformStmt(*B);
35417114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    if (Result.isInvalid()) {
35427114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Immediately fail if this was a DeclStmt, since it's very
35437114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // likely that this will cause problems for future statements.
35447114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      if (isa<DeclStmt>(*B))
35457114cbab7eb6e8b714eb22f014327daf2c741c08John McCall        return StmtError();
35467114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
35477114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Otherwise, just keep processing substatements and fail later.
35487114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      SubStmtInvalid = true;
35497114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      continue;
35507114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
35511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
355243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    SubStmtChanged = SubStmtChanged || Result.get() != *B;
355343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Statements.push_back(Result.takeAs<Stmt>());
355443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
35551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35567114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  if (SubStmtInvalid)
35577114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    return StmtError();
35587114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
355943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
356043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !SubStmtChanged)
35613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
356243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
356343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
356443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          move_arg(Statements),
356543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          S->getRBracLoc(),
356643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          IsStmtExpr);
356743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
35681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
356943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
357060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
35711eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
357260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS, RHS;
3573264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  {
3574264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // The case value expressions are not potentially evaluated.
3575f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
35761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3577264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the left-hand case value.
3578264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    LHS = getDerived().TransformExpr(S->getLHS());
3579264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (LHS.isInvalid())
3580f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
35811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3582264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the right-hand case value (for the GNU case-range extension).
3583264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    RHS = getDerived().TransformExpr(S->getRHS());
3584264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (RHS.isInvalid())
3585f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3586264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  }
35871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
358843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Build the case statement.
358943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Case statements are always rebuilt so that they will attached to their
359043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transformed switch statement.
359160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
35929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       LHS.get(),
359343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getEllipsisLoc(),
35949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       RHS.get(),
359543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getColonLoc());
359643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Case.isInvalid())
3597f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
35981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
359943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the case
360060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
360143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
3602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
360443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Attach the body to the case statement
36059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
360643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
360743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
360843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
360960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
36101eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
361143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the default case
361260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
361343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
3614f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
361643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Default statements are always rebuilt
361743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
36189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubStmt.get());
361943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
36201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
362143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
362260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
36231eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
362460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
362543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
3626f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
362843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // FIXME: Pass the real colon location in.
362943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
363043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
36311a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                       SubStmt.get(), S->HasUnusedAttribute());
363243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
36331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
363443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
363560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
36361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
363743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
363860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
36398cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  VarDecl *ConditionVar = 0;
36408cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  if (S->getConditionVariable()) {
3641c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
36428cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor      = cast_or_null<VarDecl>(
3643aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
3644aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
3645aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
36468cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    if (!ConditionVar)
3647f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
364899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
36498cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
3650c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
365199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
3652f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3653eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
3654eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor    // Convert the condition to a boolean value.
3655afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
365660d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult CondE = getSema().ActOnBooleanCondition(0,
3657afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor                                                               S->getIfLoc(),
36589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                               Cond.get());
3659afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
3660f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
3661eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
36629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
3663afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
366499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
3665c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
36669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
36679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3668f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3669eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
367043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "then" branch.
367160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Then = getDerived().TransformStmt(S->getThen());
367243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Then.isInvalid())
3673f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
367543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "else" branch.
367660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Else = getDerived().TransformStmt(S->getElse());
367743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Else.isInvalid())
3678f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
368043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
36819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
368299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
368343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Then.get() == S->getThen() &&
368443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Else.get() == S->getElse())
36853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
36861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3687eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
368844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                    Then.get(),
36899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    S->getElseLoc(), Else.get());
369043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
369143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
369243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
369360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
36941eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
369543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition.
369660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
3697d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  VarDecl *ConditionVar = 0;
3698d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  if (S->getConditionVariable()) {
3699c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
3700d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor      = cast_or_null<VarDecl>(
3701aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
3702aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
3703aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
3704d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    if (!ConditionVar)
3705f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
370699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
3707d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
3708c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
370999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
3710f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
371199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
37121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
371343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Rebuild the switch statement.
371460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Switch
37159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
3716586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                          ConditionVar);
371743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Switch.isInvalid())
3718f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
37191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
372043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body of the switch statement.
372160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
372243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
3723f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
37241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
372543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Complete the switch statement.
37269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
37279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Body.get());
372843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
37291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
373043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
373160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
37321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
373343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
373460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
37355656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  VarDecl *ConditionVar = 0;
37365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  if (S->getConditionVariable()) {
3737c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
37385656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      = cast_or_null<VarDecl>(
3739aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
3740aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
3741aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
37425656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    if (!ConditionVar)
3743f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
374499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
37455656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
3746c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
374799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
3748f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3749afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
3750afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
3751afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
375260d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult CondE = getSema().ActOnBooleanCondition(0,
3753eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor                                                             S->getWhileLoc(),
37549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                               Cond.get());
3755afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
3756f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
37579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE;
3758afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
375999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
37601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
37629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3763f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3764eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
376543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
376660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
376743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
3768f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
37691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
377043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
37719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
377299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
377343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
37749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(S);
37751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3776eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
37779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       ConditionVar, Body.get());
377843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
37791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
378043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
378160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
378243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
378343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
378460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
378543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
3786f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
37871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3788eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  // Transform the condition
378960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(S->getCond());
3790eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  if (Cond.isInvalid())
3791f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3792eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
379343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
379443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Cond.get() == S->getCond() &&
379543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
37963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
37971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
37999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    /*FIXME:*/S->getWhileLoc(), Cond.get(),
380043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    S->getRParenLoc());
380143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
38021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
380343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
380460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
38051eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) {
380643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the initialization statement
380760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Init = getDerived().TransformStmt(S->getInit());
380843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Init.isInvalid())
3809f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
38101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
381143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
381260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
381399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  VarDecl *ConditionVar = 0;
381499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  if (S->getConditionVariable()) {
3815c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
381699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      = cast_or_null<VarDecl>(
3817aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
3818aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
3819aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
382099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (!ConditionVar)
3821f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
382299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
382399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
3824c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
382599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
3826f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3827afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
3828afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
3829afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
383060d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult CondE = getSema().ActOnBooleanCondition(0,
3831afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor                                                               S->getForLoc(),
38329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                               Cond.get());
3833afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
3834f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
3835afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
38369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
3837afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
383899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
38391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
38419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3842f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3843eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
384443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the increment
384560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Inc = getDerived().TransformExpr(S->getInc());
384643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Inc.isInvalid())
3847f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
38481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
38509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (S->getInc() && !FullInc.get())
3851f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3852eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
385343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
385460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
385543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
3856f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
38571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
385843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
385943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Init.get() == S->getInit() &&
38609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
386143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Inc.get() == S->getInc() &&
386243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
38633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
38641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
386543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
38669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Init.get(), FullCond, ConditionVar,
38679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     FullInc, S->getRParenLoc(), Body.get());
386843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
386943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
387043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
387160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
38721eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
387343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Goto statements must always be rebuilt, to resolve the label.
38741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
387543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getLabel());
387643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
387743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
387843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
387960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
38801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
388160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Target = getDerived().TransformExpr(S->getTarget());
388243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Target.isInvalid())
3883f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
38841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
388543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
388643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Target.get() == S->getTarget())
38873fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
388843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
388943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
38909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Target.get());
389143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
389243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
389343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
389460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
38951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
38963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
389743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
38981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
389943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
390060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
39023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
390343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
39041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
390543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
390660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39071eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
390860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = getDerived().TransformExpr(S->getRetValue());
390943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Result.isInvalid())
3910f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
391143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
39121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: We always rebuild the return statement because there is no way
391343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // to tell whether the return type of the function has changed.
39149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
391543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
39161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
391743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
391860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
392043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool DeclChanged = false;
392143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  llvm::SmallVector<Decl *, 4> Decls;
392243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
392343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       D != DEnd; ++D) {
3924aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor    Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3925aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                         *D);
392643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (!Transformed)
3927f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
39281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
392943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Transformed != *D)
393043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      DeclChanged = true;
39311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
393243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Decls.push_back(Transformed);
393343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
39341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
393543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() && !DeclChanged)
39363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
39371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
393943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getStartLoc(), S->getEndLoc());
394043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
39411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
394243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
394360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
394543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  assert(false && "SwitchCase is abstract and cannot be transformed");
39463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
394743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
394843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
394943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
395060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
395143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3952c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3953ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Constraints(getSema());
3954ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Exprs(getSema());
3955ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  llvm::SmallVector<IdentifierInfo *, 4> Names;
3956a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson
395760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AsmString;
3958ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Clobbers(getSema());
3959703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
3960703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  bool ExprsChanged = false;
3961c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3962703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the outputs.
3963703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
3964ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getOutputIdentifier(I));
3965c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3966703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
39673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getOutputConstraintLiteral(I));
3968c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3969703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the output expr.
3970703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *OutputExpr = S->getOutputExpr(I);
397160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(OutputExpr);
3972703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
3973f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3974c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3975703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != OutputExpr;
3976c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
39779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
3978703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
3979c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3980703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the inputs.
3981703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
3982ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getInputIdentifier(I));
3983c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3984703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
39853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getInputConstraintLiteral(I));
3986c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3987703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the input expr.
3988703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *InputExpr = S->getInputExpr(I);
398960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(InputExpr);
3990703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
3991f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3992c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3993703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != InputExpr;
3994c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
39959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
3996703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
3997c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3998703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
39993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4000703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4001703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the clobbers.
4002703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
40033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Clobbers.push_back(S->getClobber(I));
4004703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4005703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // No need to transform the asm string literal.
4006703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  AsmString = SemaRef.Owned(S->getAsmString());
4007703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4008703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4009703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isSimple(),
4010703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isVolatile(),
4011703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumOutputs(),
4012703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumInputs(),
4013a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson                                     Names.data(),
4014703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Constraints),
4015703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Exprs),
40169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     AsmString.get(),
4017703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Clobbers),
4018703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getRParenLoc(),
4019703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isMSAsm());
402043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
402143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
402243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
402343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
402460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
40251eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
40264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body of the @try.
402760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
40284dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (TryBody.isInvalid())
4029f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4030c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
40318f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  // Transform the @catch statements (if present).
40328f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  bool AnyCatchChanged = false;
4033ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> CatchStmts(SemaRef);
40348f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
403560d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
40364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Catch.isInvalid())
4037f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
40388f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    if (Catch.get() != S->getCatchStmt(I))
40398f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      AnyCatchChanged = true;
40408f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    CatchStmts.push_back(Catch.release());
40414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
4042c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
40434dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the @finally statement (if present).
404460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Finally;
40454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (S->getFinallyStmt()) {
40464dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    Finally = getDerived().TransformStmt(S->getFinallyStmt());
40474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Finally.isInvalid())
4048f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
40494dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
40504dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
40514dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
40524dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
40534dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      TryBody.get() == S->getTryBody() &&
40548f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      !AnyCatchChanged &&
40554dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Finally.get() == S->getFinallyStmt())
40563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4057c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
40584dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
40599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
40609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           move_arg(CatchStmts), Finally.get());
406143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
40621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
406343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
406460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
40651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
4066be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  // Transform the @catch parameter, if there is one.
4067be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *Var = 0;
4068be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (VarDecl *FromVar = S->getCatchParamDecl()) {
4069be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    TypeSourceInfo *TSInfo = 0;
4070be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (FromVar->getTypeSourceInfo()) {
4071be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4072be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (!TSInfo)
4073f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4074be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
4075c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4076be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    QualType T;
4077be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (TSInfo)
4078be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = TSInfo->getType();
4079be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    else {
4080be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = getDerived().TransformType(FromVar->getType());
4081be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (T.isNull())
4082f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4083be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
4084c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4085be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4086be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (!Var)
4087f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4088be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
4089c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
409060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
4091be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (Body.isInvalid())
4092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4093c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4094c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
4095be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                             S->getRParenLoc(),
40969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Var, Body.get());
409743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
40981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
409943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
410060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
41011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
41024dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body.
410360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
41044dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (Body.isInvalid())
4105f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4106c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
41074dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
41084dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
41094dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Body.get() == S->getFinallyBody())
41103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
41114dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
41124dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
41134dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
41149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                               Body.get());
411543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
41161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
411743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
411860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
41191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
412060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand;
4121d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (S->getThrowExpr()) {
4122d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    Operand = getDerived().TransformExpr(S->getThrowExpr());
4123d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    if (Operand.isInvalid())
4124f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4125d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
4126c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4127d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4128d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor      Operand.get() == S->getThrowExpr())
41293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return getSema().Owned(S);
4130c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
41319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
413243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
41331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
413443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
413560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
413643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
41371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCAtSynchronizedStmt *S) {
41388fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the object we are locking.
413960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
41408fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Object.isInvalid())
4141f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4142c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
41438fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the body.
414460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
41458fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Body.isInvalid())
4146f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4147c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
41488fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // If nothing change, just retain the current statement.
41498fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
41508fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Object.get() == S->getSynchExpr() &&
41518fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Body.get() == S->getSynchBody())
41523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
41538fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor
41548fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Build a new statement.
41558fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
41569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    Object.get(), Body.get());
415743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
415843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
415943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
416060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
416143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt(
41621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCForCollectionStmt *S) {
4163c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the element statement.
416460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Element = getDerived().TransformStmt(S->getElement());
4165c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Element.isInvalid())
4166f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4168c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the collection expression.
416960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
4170c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Collection.isInvalid())
4171f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4172c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4173c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the body.
417460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
4175c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Body.isInvalid())
4176f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4177c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4178c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // If nothing changed, just retain this statement.
4179c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
4180c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Element.get() == S->getElement() &&
4181c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Collection.get() == S->getCollection() &&
4182c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Body.get() == S->getBody())
41833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4184c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4185c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Build a new statement.
4186c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4187c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   /*FIXME:*/S->getForLoc(),
41889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Element.get(),
41899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Collection.get(),
4190c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   S->getRParenLoc(),
41919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Body.get());
419243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
419343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
419443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
419543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
419660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
419743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
419843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the exception declaration, if any.
419943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  VarDecl *Var = 0;
420043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (S->getExceptionDecl()) {
420143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    VarDecl *ExceptionDecl = S->getExceptionDecl();
420283cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    TypeSourceInfo *T = getDerived().TransformType(
420383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getTypeSourceInfo());
420483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    if (!T)
4205f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
42061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
420783cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
420843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                            ExceptionDecl->getIdentifier(),
420983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getLocation());
4210ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor    if (!Var || Var->isInvalidDecl())
4211f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
421243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
42131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
421443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the actual exception handler.
421560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4216ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor  if (Handler.isInvalid())
4217f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
42181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
421943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
422043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !Var &&
422143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Handler.get() == S->getHandlerBlock())
42223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
422343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
422443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
422543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          Var,
42269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Handler.get());
422743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
42281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
422943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
423060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
423143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
423243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the try block itself.
423360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBlock
423443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    = getDerived().TransformCompoundStmt(S->getTryBlock());
423543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (TryBlock.isInvalid())
4236f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
42371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
423843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the handlers.
423943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool HandlerChanged = false;
4240ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Handlers(SemaRef);
424143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
424260d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Handler
424343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      = getDerived().TransformCXXCatchStmt(S->getHandler(I));
424443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Handler.isInvalid())
4245f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
42461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
424743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
424843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Handlers.push_back(Handler.takeAs<Stmt>());
424943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
42501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
425143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
425243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      TryBlock.get() == S->getTryBlock() &&
425343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !HandlerChanged)
42543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
425543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
42569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
42571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        move_arg(Handlers));
425843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
42591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
426043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
4261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation
4262577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
42631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
426460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4265454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
42663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
42671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
42681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
427060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4271454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
4272a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *Qualifier = 0;
4273a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (E->getQualifier()) {
4274a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4275edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                       E->getQualifierRange());
4276a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!Qualifier)
4277f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
4278a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
4279dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
4280dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *ND
42817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
42827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getDecl()));
4283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!ND)
4284f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
42851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4286ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  DeclarationNameInfo NameInfo = E->getNameInfo();
4287ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  if (NameInfo.getName()) {
4288ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4289ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    if (!NameInfo.getName())
4290f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
4291ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  }
42922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
42932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!getDerived().AlwaysRebuild() &&
4294a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      Qualifier == E->getQualifier() &&
4295a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ND == E->getDecl() &&
42962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NameInfo.getName() == E->getDecl()->getDeclName() &&
4297096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
42981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4299dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // Mark it referenced in the new context regardless.
4300dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: this is a bit instantiation-specific.
4301dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4302a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
43033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
4304a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
4305dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
4306dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4307096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
4308dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TemplateArgs = &TransArgs;
4309dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
4310dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
4311dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4312dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall      TemplateArgumentLoc Loc;
4313dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall      if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4314f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
4315dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall      TransArgs.addArgument(Loc);
4316dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    }
4317dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
4318dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
4319a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
43202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, TemplateArgs);
4321577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
432460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4325454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
43263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4327577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
433060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4331454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
43323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
433660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4337454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
43383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
434260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4343454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
43443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
434860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4349454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
43503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
435460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4355454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
435660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
4358f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
43591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
43613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
43621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
4364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       E->getRParen());
4365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
4366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
43671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
436860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4369454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
437060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
4372f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
43731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
43753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
43761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getOpcode(),
43799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get());
4380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
438360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
43848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
43858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform the type.
43868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
43878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!Type)
4388f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
4389c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
43908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform all of the components into components similar to what the
43918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // parser uses.
4392c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // FIXME: It would be slightly more efficient in the non-dependent case to
4393c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // just map FieldDecls, rather than requiring the rebuilder to look for
4394c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // the fields again. However, __builtin_offsetof is rare enough in
43958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // template code that we don't care.
43968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool ExprChanged = false;
4397f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::OffsetOfComponent Component;
43988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef OffsetOfExpr::OffsetOfNode Node;
43998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  llvm::SmallVector<Component, 4> Components;
44008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
44018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const Node &ON = E->getComponent(I);
44028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Component Comp;
440372be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor    Comp.isBrackets = true;
44048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Comp.LocStart = ON.getRange().getBegin();
44058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Comp.LocEnd = ON.getRange().getEnd();
44068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    switch (ON.getKind()) {
44078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Array: {
44088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
440960d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(FromIndex);
44108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (Index.isInvalid())
4411f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
4412c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      ExprChanged = ExprChanged || Index.get() != FromIndex;
44148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = true;
44159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Comp.U.E = Index.get();
44168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
44178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
4418c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Field:
44208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Identifier:
44218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = false;
44228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.U.IdentInfo = ON.getFieldName();
442329d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor      if (!Comp.U.IdentInfo)
442429d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor        continue;
4425c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
4427c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4428cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    case Node::Base:
4429cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      // Will be recomputed during the rebuild.
4430cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      continue;
44318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
4432c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Components.push_back(Comp);
44348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
4435c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // If nothing changed, retain the existing expression.
44378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
44388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Type == E->getTypeSourceInfo() &&
44398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      !ExprChanged)
44403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
4441c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Build a new offsetof expression.
44438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
44448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          Components.data(), Components.size(),
44458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          E->getRParenLoc());
44467cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}
44477cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
44487cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived>
44497cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult
44507cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
44517cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  assert(getDerived().AlreadyTransformed(E->getType()) &&
44527cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall         "opaque value expression requires transformation");
44537cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  return SemaRef.Owned(E);
44548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
44558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
44568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived>
445760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4458454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
4459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isArgumentType()) {
4460a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *OldT = E->getArgumentTypeInfo();
44615557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor
4462a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *NewT = getDerived().TransformType(OldT);
44635ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!NewT)
4464f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
44651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44665ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!getDerived().AlwaysRebuild() && OldT == NewT)
44673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
44681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44695ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
44701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             E->isSizeOf(),
4471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getSourceRange());
4472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
44731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
447460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr;
44751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  {
4476b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // C++0x [expr.sizeof]p1:
4477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   The operand is either an expression, which is an unevaluated operand
4478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   [...]
4479f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
44801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
4483f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
44841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
44863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
4487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
44881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
4490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isSizeOf(),
4491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getSourceRange());
4492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
44931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
449560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4496454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
449760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
4499f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
45001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
450160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
4503f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
45041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
4508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
45093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
45101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
4512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           /*FIXME:*/E->getLHS()->getLocStart(),
45139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                RHS.get(),
4514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getRBracketLoc());
4515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
45161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
451860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4519454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
4520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the callee.
452160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
4522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
4523f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
4524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform arguments.
4526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgChanged = false;
4527ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
4528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
452960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Arg.isInvalid())
4531f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
45321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
45349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Args.push_back(Arg.get());
4535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
45361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
4539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgChanged)
45403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
45411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Wrong source location information for the '('.
45431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLParenLoc
4544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = ((Expr *)Callee.get())->getSourceRange().getBegin();
45459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
4546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      move_arg(Args),
4547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
4548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
45491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
455160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4552454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
455360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
4554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
4555f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
45561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
455783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  NestedNameSpecifier *Qualifier = 0;
455883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (E->hasQualifier()) {
45591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Qualifier
456083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4561edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  E->getQualifierRange());
4562c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (Qualifier == 0)
4563f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
456483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
45651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4566f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *Member
45677c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
45687c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getMemberDecl()));
4569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Member)
4570f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
45711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45726bb8017bb9e828d118e15e59d71c66bba323c364John McCall  NamedDecl *FoundDecl = E->getFoundDecl();
45736bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (FoundDecl == E->getMemberDecl()) {
45746bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = Member;
45756bb8017bb9e828d118e15e59d71c66bba323c364John McCall  } else {
45766bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = cast_or_null<NamedDecl>(
45776bb8017bb9e828d118e15e59d71c66bba323c364John McCall                   getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
45786bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!FoundDecl)
4579f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
45806bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
45816bb8017bb9e828d118e15e59d71c66bba323c364John McCall
4582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase() &&
458483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      Qualifier == E->getQualifier() &&
45858a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor      Member == E->getMemberDecl() &&
45866bb8017bb9e828d118e15e59d71c66bba323c364John McCall      FoundDecl == E->getFoundDecl() &&
4587096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
4588c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
45891f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // Mark it referenced in the new context regardless.
45901f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // FIXME: this is a bit instantiation-specific.
45911f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
45923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
45931f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson  }
4594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4595d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs;
4596096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
4597d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
4598d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
45998a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor    for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4600d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      TemplateArgumentLoc Loc;
4601d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
4603d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      TransArgs.addArgument(Loc);
46048a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor    }
46058a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor  }
4606c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bogus source location for the operator
4608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeOperatorLoc
4609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4611c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
4612c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
4613c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
4614c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
4615c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
4616c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
46179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
4618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isArrow(),
461983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                        Qualifier,
462083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                        E->getQualifierRange(),
46212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                        E->getMemberNameInfo(),
46228a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor                                        Member,
46236bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        FoundDecl,
4624096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                        (E->hasExplicitTemplateArgs()
4625d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                           ? &TransArgs : 0),
4626c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                        FirstQualifierInScope);
4627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
46281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
463060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4631454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
463260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
4634f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
463660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
4638f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
4642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
46433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
46441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
46469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            LHS.get(), RHS.get());
4647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
4648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
46491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
465060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator(
4652454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CompoundAssignOperator *E) {
4653454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformBinaryOperator(E);
4654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
46551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
465760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4658454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
465960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
4660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
4661f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
466360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
4665f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
466760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
4669f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
4673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
4674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
46753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
46761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildConditionalOperator(Cond.get(),
467847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getQuestionLoc(),
46799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 LHS.get(),
468047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getColonLoc(),
46819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 RHS.get());
4682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
46831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
468560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4686454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
4687a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // Implicit casts are eliminated during transformation, since they
4688a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // will be recomputed by semantic analysis after transformation.
46896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return getDerived().TransformExpr(E->getSubExprAsWritten());
4690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
46911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
469360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4694454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
4695ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4696ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
4697ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
4698ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
469960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
47006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
4701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
4702f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4705ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
4706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
47073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
47081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47099d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4710ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                            Type,
4711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc(),
47129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            SubExpr.get());
4713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
471660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4717454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
471842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *OldT = E->getTypeSourceInfo();
471942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
472042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  if (!NewT)
4721f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
472360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
4724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
4725f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
472842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      OldT == NewT &&
4729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInitializer())
47303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
4731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
47321d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // Note: the expression type doesn't necessarily match the
47331d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // type-as-written, but that's okay, because it should always be
47341d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // derivable from the initializer.
47351d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
473642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
4737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   /*FIXME:*/E->getInitializer()->getLocEnd(),
47389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Init.get());
4739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
474260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4743454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
474460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
4745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
4746f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase())
47503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
47511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bad source location
47531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeOperatorLoc
4754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
47559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
4756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessorLoc(),
4757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessor());
4758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
476160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4762454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
4763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool InitChanged = false;
47641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4765ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
4766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
476760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Init = getDerived().TransformExpr(E->getInit(I));
4768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Init.isInvalid())
4769f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
47701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    InitChanged = InitChanged || Init.get() != E->getInit(I);
47729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Inits.push_back(Init.get());
4773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
47741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && !InitChanged)
47763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
47771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
4779e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                      E->getRBraceLoc(), E->getType());
4780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
478360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4784454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
4785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Designation Desig;
47861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
478743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the initializer value
478860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInit());
4789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
4790f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
479243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the designators.
4793ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
4794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ExprChanged = false;
4795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             DEnd = E->designators_end();
4797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       D != DEnd; ++D) {
4798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isFieldDesignator()) {
4799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Desig.AddDesignator(Designator::getField(D->getFieldName(),
4800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getDotLoc(),
4801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getFieldLoc()));
4802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
4803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
48041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isArrayDesignator()) {
480660d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Index.isInvalid())
4808f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
48091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Desig.AddDesignator(Designator::getArray(Index.get(),
4811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getLBracketLoc()));
48121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArrayExprs.push_back(Index.release());
4815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
4816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
48171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(D->isArrayRangeDesignator() && "New kind of designator?");
481960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Start
4820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Start.isInvalid())
4822f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
48231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
482460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (End.isInvalid())
4826f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
48271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Desig.AddDesignator(Designator::getArrayRange(Start.get(),
4829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  End.get(),
4830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getLBracketLoc(),
4831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getEllipsisLoc()));
48321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      End.get() != E->getArrayRangeEnd(*D);
48351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(Start.release());
4837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(End.release());
4838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
48391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInit() &&
4842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ExprChanged)
48433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
48441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getEqualOrColonLoc(),
48479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                E->usesGNUSyntax(), Init.get());
4848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
48491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
485160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr(
4853454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     ImplicitValueInitExpr *E) {
48545557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4855c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
48565557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // FIXME: Will we ever have proper type location here? Will we actually
48575557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // need to transform the type?
4858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
4859b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
4860f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
48611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType())
48643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
48651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildImplicitValueInitExpr(T);
4867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
48681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
487060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4871454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
48729bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
48739bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo)
4874f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
48751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
487660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
4878f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
48791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4880b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
48812cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      TInfo == E->getWrittenTypeInfo() &&
4882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
48833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
48841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
48862cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                       TInfo, E->getRParenLoc());
4887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
4888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
489060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4891454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
4892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
4893ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
4894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
489560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Init.isInvalid())
4897f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
48981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
49009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Inits.push_back(Init.get());
4901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
49021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           move_arg(Inits),
4905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getRParenLoc());
4906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression.
4909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
4910b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always
4911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to
4912b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis.
4913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
491460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4915454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
4916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4917b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLabel());
4918b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
492160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4922454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
492360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt
4924b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubStmt.isInvalid())
4926f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4929b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubStmt.get() == E->getSubStmt())
49303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
49311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
49339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      SubStmt.get(),
4934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
4935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
493860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4939454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
49403fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara  TypeSourceInfo *TInfo1;
49413fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara  TypeSourceInfo *TInfo2;
49429bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor
49439bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TInfo1 = getDerived().TransformType(E->getArgTInfo1());
49449bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo1)
4945f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49479bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TInfo2 = getDerived().TransformType(E->getArgTInfo2());
49489bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo2)
4949f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
4950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
49523fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara      TInfo1 == E->getArgTInfo1() &&
49533fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara      TInfo2 == E->getArgTInfo2())
49543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
49551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
49573fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara                                                 TInfo1, TInfo2,
49583fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara                                                 E->getRParenLoc());
4959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
496260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4963454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
496460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
4965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
4966f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
4970f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
497260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
4974f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
4978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
4979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
49803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
49811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
49839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Cond.get(), LHS.get(), RHS.get(),
4984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->getRParenLoc());
4985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
498860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4989454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
49903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4991b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
4992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4993b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
499460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4995454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
4996668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  switch (E->getOperator()) {
4997668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_New:
4998668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Delete:
4999668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_New:
5000668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_Delete:
5001668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
5002f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5003c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5004668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Call: {
5005668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // This is a call to an object's operator().
5006668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5007668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5008668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the object itself.
500960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Object = getDerived().TransformExpr(E->getArg(0));
5010668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    if (Object.isInvalid())
5011f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5012668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5013668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // FIXME: Poor location information
5014668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    SourceLocation FakeLParenLoc
5015668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      = SemaRef.PP.getLocForEndOfToken(
5016668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                              static_cast<Expr *>(Object.get())->getLocEnd());
5017668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5018668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the call arguments.
5019ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> Args(SemaRef);
5020668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
50216eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      if (getDerived().DropCallArgument(E->getArg(I)))
50226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor        break;
5023c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
502460d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5025668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      if (Arg.isInvalid())
5026f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
5027668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5028668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      Args.push_back(Arg.release());
5029668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    }
5030668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
50319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
5032668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        move_arg(Args),
5033668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        E->getLocEnd());
5034668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
5035668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5036668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5037668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_##Name:
5038668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5039668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def"
5040668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Subscript:
5041668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Handled below.
5042668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    break;
5043668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5044668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Conditional:
5045668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("conditional operator is not actually overloadable");
5046f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5047668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5048668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_None:
5049668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case NUM_OVERLOADED_OPERATORS:
5050668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("not an overloaded operator?");
5051f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5052668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
5053668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
505460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5055b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
5056f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
50571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
505860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult First = getDerived().TransformExpr(E->getArg(0));
5059b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (First.isInvalid())
5060f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
506260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Second;
5063b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->getNumArgs() == 2) {
5064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Second = getDerived().TransformExpr(E->getArg(1));
5065b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Second.isInvalid())
5066f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
50681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
5071b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      First.get() == E->getArg(0) &&
50721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
50733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
50741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5075b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 E->getOperatorLoc(),
50779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Callee.get(),
50789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 First.get(),
50799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Second.get());
5080b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
50811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5082b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
508360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5084454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5085454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCallExpr(E);
5086b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
50871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
508960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5090454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
5091ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5092ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
5093ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
5094ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
509560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
50966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
5097b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5098f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
50991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5101ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
5102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
51033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
51041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Poor source location information here.
51061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLAngleLoc
5107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5109b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRParenLoc
5110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(
5111b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  E->getSubExpr()->getSourceRange().getEnd());
5112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
51131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              E->getStmtClass(),
5114b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeLAngleLoc,
5115ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                              Type,
5116b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
5117b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
51189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              SubExpr.get(),
5119b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRParenLoc);
5120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5122b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
512360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5124454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5125454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
512960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5130454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5131454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
513560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr(
5137454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CXXReinterpretCastExpr *E) {
5138454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
514260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5143454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5144454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
514860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr(
5150454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXFunctionalCastExpr *E) {
5151ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5152ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
5153ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
51541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
515560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
51566eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
5157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5158f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
51591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5161ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
5162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
51633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
51641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5165ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  return getDerived().RebuildCXXFunctionalCastExpr(Type,
5166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      /*FIXME:*/E->getSubExpr()->getLocStart(),
51679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr.get(),
5168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   E->getRParenLoc());
5169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
517260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5173454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
5174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isTypeOperand()) {
517557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    TypeSourceInfo *TInfo
517657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      = getDerived().TransformType(E->getTypeOperandSourceInfo());
517757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    if (!TInfo)
5178f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
51791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
518157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        TInfo == E->getTypeOperandSourceInfo())
51823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
51831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
518457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return getDerived().RebuildCXXTypeidExpr(E->getType(),
518557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             E->getLocStart(),
518657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             TInfo,
5187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getLocEnd());
5188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
51891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // We don't know whether the expression is potentially evaluated until
5191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // after we perform semantic analysis, so the expression is potentially
5192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // potentially evaluated.
51931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  EnterExpressionEvaluationContext Unevaluated(SemaRef,
5194f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      Sema::PotentiallyPotentiallyEvaluated);
51951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
519660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5198f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
51991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getExprOperand())
52023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
52031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
520457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  return getDerived().RebuildCXXTypeidExpr(E->getType(),
520557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                           E->getLocStart(),
52069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get(),
5207b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLocEnd());
5208b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5210b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
521160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
521201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
521301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (E->isTypeOperand()) {
521401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    TypeSourceInfo *TInfo
521501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      = getDerived().TransformType(E->getTypeOperandSourceInfo());
521601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!TInfo)
521701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      return ExprError();
521801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
521901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!getDerived().AlwaysRebuild() &&
522001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet        TInfo == E->getTypeOperandSourceInfo())
52213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
522201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
522301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getDerived().RebuildCXXTypeidExpr(E->getType(),
522401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocStart(),
522501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             TInfo,
522601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocEnd());
522701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
522801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
522901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // We don't know whether the expression is potentially evaluated until
523001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // after we perform semantic analysis, so the expression is potentially
523101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // potentially evaluated.
523201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
523301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
523401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
523501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (SubExpr.isInvalid())
523601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return ExprError();
523701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
523801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (!getDerived().AlwaysRebuild() &&
523901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      SubExpr.get() == E->getExprOperand())
52403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
524101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
524201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  return getDerived().RebuildCXXUuidofExpr(E->getType(),
524301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocStart(),
524401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           SubExpr.get(),
524501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocEnd());
524601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}
524701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
524801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived>
524901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult
5250454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
52513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5252b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
525560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5256b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
5257454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXNullPtrLiteralExpr *E) {
52583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
526260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5263454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
5264ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  DeclContext *DC = getSema().getFunctionLevelDeclContext();
5265ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5266ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  QualType T = MD->getThisType(getSema().Context);
52671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5268ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!getDerived().AlwaysRebuild() && T == E->getType())
52693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
52701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5271828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
5272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5274b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
527560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5276454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
527760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5279f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
52833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5284b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
52859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
5286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
528960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5290454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
52911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParmVarDecl *Param
52927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
52937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           E->getParam()));
5294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Param)
5295f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
529753cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth  if (!getDerived().AlwaysRebuild() &&
5298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Param == E->getParam())
52993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
53001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5301036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
5302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
53031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
530560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5306ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5307ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXScalarValueInitExpr *E) {
5308ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5309ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
5310f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5311ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
5312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5313ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo())
53143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
53151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5316ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXScalarValueInitExpr(T,
5317ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
5318ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor                                                    E->getRParenLoc());
5319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
53201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
532260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5323454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
5324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the type that we're allocating
53251bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocTypeInfo
53261bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
53271bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  if (!AllocTypeInfo)
5328f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
53291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the size of the array we're allocating (if any).
533160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (ArraySize.isInvalid())
5333f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
53341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the placement arguments (if any).
5336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5337ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> PlacementArgs(SemaRef);
5338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
533963d5fb3a142c39ff4236235cb284401b88685692John McCall    if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
534063d5fb3a142c39ff4236235cb284401b88685692John McCall      ArgumentChanged = true;
534163d5fb3a142c39ff4236235cb284401b88685692John McCall      break;
534263d5fb3a142c39ff4236235cb284401b88685692John McCall    }
534363d5fb3a142c39ff4236235cb284401b88685692John McCall
534460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Arg.isInvalid())
5346f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    PlacementArgs.push_back(Arg.take());
5350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
53511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
535243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the constructor arguments (if any).
5353ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
5354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
535563d5fb3a142c39ff4236235cb284401b88685692John McCall    if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
535663d5fb3a142c39ff4236235cb284401b88685692John McCall      ArgumentChanged = true;
5357ff2e4f44e56aef84fa423af4ca5c1fe56886b4aaDouglas Gregor      break;
535863d5fb3a142c39ff4236235cb284401b88685692John McCall    }
5359ff2e4f44e56aef84fa423af4ca5c1fe56886b4aaDouglas Gregor
536060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Arg.isInvalid())
5362f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ConstructorArgs.push_back(Arg.take());
5366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
53671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53681af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform constructor, new operator, and delete operator.
53691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  CXXConstructorDecl *Constructor = 0;
53701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getConstructor()) {
53711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    Constructor = cast_or_null<CXXConstructorDecl>(
53727c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
53737c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
53741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!Constructor)
5375f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
53771af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
53781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorNew = 0;
53791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorNew()) {
53801af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorNew = cast_or_null<FunctionDecl>(
53817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(E->getLocStart(),
53827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getOperatorNew()));
53831af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorNew)
5384f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
53861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
53871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
53881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
53891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
53907c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
53917c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
53921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
5393f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
5395c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
53971bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor      AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
5398b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArraySize.get() == E->getArraySize() &&
53991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Constructor == E->getConstructor() &&
54001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorNew == E->getOperatorNew() &&
54011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete() &&
54021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      !ArgumentChanged) {
54031af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
54041af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
54051af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (Constructor)
54061af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
54071af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorNew)
54081af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
54091af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
54101af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
54113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
54121af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
54131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54141bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  QualType AllocType = AllocTypeInfo->getType();
54155b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  if (!ArraySize.get()) {
54165b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // If no array size was specified, but the new expression was
54175b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with an array type (e.g., "new T" where T is
54185b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with "int[4]"), extract the outer bound from the
54195b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // array type as our array size. We do this with constant and
54205b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // dependently-sized array types.
54215b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
54225b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    if (!ArrayT) {
54235b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      // Do nothing
54245b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const ConstantArrayType *ConsArrayT
54255b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                                     = dyn_cast<ConstantArrayType>(ArrayT)) {
5426c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      ArraySize
54279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
54289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               ConsArrayT->getSize(),
54299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               SemaRef.Context.getSizeType(),
54309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               /*FIXME:*/E->getLocStart()));
54315b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      AllocType = ConsArrayT->getElementType();
54325b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const DependentSizedArrayType *DepArrayT
54335b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                              = dyn_cast<DependentSizedArrayType>(ArrayT)) {
54345b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      if (DepArrayT->getSizeExpr()) {
54353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall        ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
54365b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor        AllocType = DepArrayT->getElementType();
54375b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      }
54385b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    }
54395b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  }
54401bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
5441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isGlobalNew(),
5443b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
5444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(PlacementArgs),
5445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
54464bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                        E->getTypeIdParens(),
5447b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        AllocType,
54481bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                        AllocTypeInfo,
54499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        ArraySize.get(),
5450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
5451b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(ConstructorArgs),
54521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        E->getLocEnd());
5453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5455b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
545660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5457454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
545860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
5459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Operand.isInvalid())
5460f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54621af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform the delete operator, if known.
54631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
54641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
54651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
54667c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
54677c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
54681af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
5469f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
54701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
5471c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
54731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Operand.get() == E->getArgument() &&
54741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete()) {
54751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
54761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
54771af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
54781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
54795833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
54805833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    if (!E->getArgument()->isTypeDependent()) {
54815833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      QualType Destroyed = SemaRef.Context.getBaseElementType(
54825833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                                         E->getDestroyedType());
54835833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
54845833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
54855833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        SemaRef.MarkDeclarationReferenced(E->getLocStart(),
54865833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                          SemaRef.LookupDestructor(Record));
54875833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      }
54885833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    }
54895833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
54903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
54911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
54921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isGlobalDelete(),
5495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isArrayForm(),
54969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Operand.get());
5497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
550060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5501a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
5502454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXPseudoDestructorExpr *E) {
550360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
5504a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  if (Base.isInvalid())
5505f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
55061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5507b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ObjectTypePtr;
5508a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  bool MayBePseudoDestructor = false;
55099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
5510a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              E->getOperatorLoc(),
5511a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        E->isArrow()? tok::arrow : tok::period,
5512a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              ObjectTypePtr,
5513a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              MayBePseudoDestructor);
5514a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (Base.isInvalid())
5515f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5516c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5517b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  QualType ObjectType = ObjectTypePtr.get();
551843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  NestedNameSpecifier *Qualifier = E->getQualifier();
551943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Qualifier) {
552043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Qualifier
552143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
552243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  E->getQualifierRange(),
552343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  ObjectType);
552443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (!Qualifier)
552543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      return ExprError();
552643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
55271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5528a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage Destroyed;
5529a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (E->getDestroyedTypeInfo()) {
5530a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    TypeSourceInfo *DestroyedTypeInfo
553143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
553243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjectType, 0, Qualifier);
5533a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!DestroyedTypeInfo)
5534f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5535a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = DestroyedTypeInfo;
5536a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else if (ObjectType->isDependentType()) {
5537a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // We aren't likely to be able to resolve the identifier down to a type
5538a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // now anyway, so just retain the identifier.
5539a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5540a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                            E->getDestroyedTypeLoc());
5541a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else {
5542a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // Look for a destructor known with the given name.
5543a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    CXXScopeSpec SS;
5544a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (Qualifier) {
5545a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      SS.setScopeRep(Qualifier);
5546a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      SS.setRange(E->getQualifierRange());
5547a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    }
5548c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5549b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
5550a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              *E->getDestroyedTypeIdentifier(),
5551a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                E->getDestroyedTypeLoc(),
5552a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                /*Scope=*/0,
5553a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                SS, ObjectTypePtr,
5554a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                false);
5555a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!T)
5556f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5557c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5558a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed
5559a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5560a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                 E->getDestroyedTypeLoc());
5561a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
556226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
556326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *ScopeTypeInfo = 0;
556426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (E->getScopeTypeInfo()) {
556543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
556626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    if (!ScopeTypeInfo)
5567f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5568a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
5569c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
55709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
5571a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->getOperatorLoc(),
5572a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->isArrow(),
5573a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     Qualifier,
557426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getQualifierRange(),
557526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     ScopeTypeInfo,
557626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getColonColonLoc(),
5577fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                     E->getTildeLoc(),
5578a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                     Destroyed);
5579a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}
55801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5581a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived>
558260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5583ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr(
5584454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  UnresolvedLookupExpr *Old) {
5585f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5586f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5587f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5588f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                 Sema::LookupOrdinaryName);
5589f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5590f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Transform all the decls.
5591f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5592f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall         E = Old->decls_end(); I != E; ++I) {
55937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
55947c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(Old->getNameLoc(),
55957c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                            *I));
55969f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
55979f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
55989f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
55999f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
56009f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
56019f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
5602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
56039f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
5604f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5605f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // Expand using declarations.
5606f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (isa<UsingDecl>(InstD)) {
5607f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
5608f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5609f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall             E = UD->shadow_end(); I != E; ++I)
5610f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        R.addDecl(*I);
5611f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      continue;
5612f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    }
5613f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5614f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    R.addDecl(InstD);
5615f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
5616f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5617f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Resolve a kind, but don't do any further analysis.  If it's
5618f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // ambiguous, the callee needs to deal with it.
5619f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  R.resolveKind();
5620f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5621f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Rebuild the nested-name qualifier, if present.
5622f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  CXXScopeSpec SS;
5623f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  NestedNameSpecifier *Qualifier = 0;
5624f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (Old->getQualifier()) {
5625f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5626edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                    Old->getQualifierRange());
5627f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!Qualifier)
5628f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5629c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5630f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SS.setScopeRep(Qualifier);
5631f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SS.setRange(Old->getQualifierRange());
5632c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
5633c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5634c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (Old->getNamingClass()) {
563566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    CXXRecordDecl *NamingClass
563666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
563766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                            Old->getNameLoc(),
563866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
563966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
5640f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5641c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
564266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
5643f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
5644f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5645f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have no template arguments, it's a normal declaration name.
5646f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!Old->hasExplicitTemplateArgs())
5647f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5648f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5649f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have template arguments, rebuild them, then rebuild the
5650f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // templateid expression.
5651f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5652f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5653f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    TemplateArgumentLoc Loc;
5654f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5655f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5656f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    TransArgs.addArgument(Loc);
5657f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
5658f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5659f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5660f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                            TransArgs);
5661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
566460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5665454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
56663d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
56673d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  if (!T)
5668f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
56713d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      T == E->getQueriedTypeSourceInfo())
56723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
56731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
5675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocStart(),
5676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            T,
5677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocEnd());
5678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
568160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
56826ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
56836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
56846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!LhsT)
56856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
56866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
56876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
56886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!RhsT)
56896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
56906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
56916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!getDerived().AlwaysRebuild() &&
56926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
56936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SemaRef.Owned(E);
56946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
56956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
56966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocStart(),
56976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            LhsT, RhsT,
56986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocEnd());
56996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}
57006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
57016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived>
57026ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult
5703865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
57042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                               DependentScopeDeclRefExpr *E) {
5705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  NestedNameSpecifier *NNS
5706f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor    = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5707edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                E->getQualifierRange());
5708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!NNS)
5709f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
571143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
571243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
571343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
571443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
57152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
57162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
57172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
5718f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5720f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!E->hasExplicitTemplateArgs()) {
5721f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!getDerived().AlwaysRebuild() &&
5722f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        NNS == E->getQualifier() &&
57232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // Note: it is sufficient to compare the Name component of NameInfo:
57242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // if name has not changed, DNLoc has not changed either.
57252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getDeclName())
57263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
57271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5728f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5729f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         E->getQualifierRange(),
57302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                         NameInfo,
5731f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         /*TemplateArgs*/ 0);
5732f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor  }
5733d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
5734d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
5735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
5736d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TemplateArgumentLoc Loc;
5737d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
5738f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5739d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.addArgument(Loc);
5740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
5741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5742f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5743f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       E->getQualifierRange(),
57442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
5745f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       &TransArgs);
5746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
574960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5750454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
5751321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // CXXConstructExprs are always implicit, so when we have a
5752321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // 1-argument construction we just transform that argument.
5753321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  if (E->getNumArgs() == 1 ||
5754321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor      (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5755321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor    return getDerived().TransformExpr(E->getArg(0));
5756321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor
5757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
5760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
5761f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
5764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
57657c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(E->getLocStart(),
57667c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
5767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
5768f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5771ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
57721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
5773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       ArgEnd = E->arg_end();
5774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       Arg != ArgEnd; ++Arg) {
57756eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    if (getDerived().DropCallArgument(*Arg)) {
57766eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      ArgumentChanged = true;
57776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      break;
57786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    }
57796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
578060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult TransArg = getDerived().TransformExpr(*Arg);
5781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (TransArg.isInvalid())
5782f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
57831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
57859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Args.push_back(TransArg.get());
5786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
5787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType() &&
5790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
5791c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor      !ArgumentChanged) {
57921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark the constructor as referenced.
57931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: Instantiation-specific
5794c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
57953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5796c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor  }
57971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57984411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
57994411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                              Constructor, E->isElidable(),
58008c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              move_arg(Args),
58018c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              E->requiresZeroInitialization(),
5802428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getConstructionKind(),
5803428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getParenRange());
5804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression.
5807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
58085132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
58095132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that.
5810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
581160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5812454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
58135132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
5814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58164765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should
58174765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated.
5818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
58194765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we
58205132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that.
5821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
582260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
58234765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
58245132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
5825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
582860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
5830ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXTemporaryObjectExpr *E) {
5831ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5832ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
5833f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
5836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
5837c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                  getDerived().TransformDecl(E->getLocStart(),
58387c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
5839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
5840f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5843ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
5844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Args.reserve(E->getNumArgs());
58451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
5846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         ArgEnd = E->arg_end();
5847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       Arg != ArgEnd; ++Arg) {
584891be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    if (getDerived().DropCallArgument(*Arg)) {
584991be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      ArgumentChanged = true;
585091be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      break;
585191be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    }
585291be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor
585360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult TransArg = getDerived().TransformExpr(*Arg);
5854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (TransArg.isInvalid())
5855f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
58561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Args.push_back((Expr *)TransArg.release());
5859b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
58601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5862ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
5863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
586491be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      !ArgumentChanged) {
586591be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    // FIXME: Instantiation-specific
5866ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
58673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.MaybeBindToTemporary(E);
586891be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor  }
5869ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
5870ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXTemporaryObjectExpr(T,
5871ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
5872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    move_arg(Args),
5873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    E->getLocEnd());
5874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
587760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
5879454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  CXXUnresolvedConstructExpr *E) {
5880ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5881ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
5882f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5885ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
5886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             ArgEnd = E->arg_end();
5888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       Arg != ArgEnd; ++Arg) {
588960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult TransArg = getDerived().TransformExpr(*Arg);
5890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (TransArg.isInvalid())
5891f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
58921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
58949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Args.push_back(TransArg.get());
5895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
58961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5898ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
5899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
59003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
59011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: we're faking the locations of the commas
5903ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
5904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getLParenLoc(),
5905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        move_arg(Args),
5906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getRParenLoc());
5907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
591060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5911865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
59122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                             CXXDependentScopeMemberExpr *E) {
5913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the base of the expression.
591460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
5915aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *OldBase;
5916aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
5917aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType ObjectType;
5918aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->isImplicitAccess()) {
5919aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = E->getBase();
5920aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(OldBase);
5921aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
5922f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
59231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5924aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    // Start the member reference and compute the object's type.
5925b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ObjectTy;
5926d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor    bool MayBePseudoDestructor = false;
59279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
5928aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                E->getOperatorLoc(),
5929a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                      E->isArrow()? tok::arrow : tok::period,
5930d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                ObjectTy,
5931d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                MayBePseudoDestructor);
5932aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
5933f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5934aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
5935b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ObjectType = ObjectTy.get();
5936aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
5937aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
5938aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = 0;
5939aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(E->getBaseType());
5940aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5941aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
59421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59436cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // Transform the first part of the nested-name-specifier that qualifies
59446cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // the member name.
5945c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierInScope
59466cd219879ffce00920189ec1dcea927a42602961Douglas Gregor    = getDerived().TransformFirstQualifierInScope(
59476cd219879ffce00920189ec1dcea927a42602961Douglas Gregor                                          E->getFirstQualifierFoundInScope(),
59486cd219879ffce00920189ec1dcea927a42602961Douglas Gregor                                          E->getQualifierRange().getBegin());
59491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5950a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  NestedNameSpecifier *Qualifier = 0;
5951a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  if (E->getQualifier()) {
5952a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5953a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                      E->getQualifierRange(),
5954aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                      ObjectType,
5955aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                      FirstQualifierInScope);
5956a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    if (!Qualifier)
5957f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5958a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  }
59591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
596043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
596143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
596243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
596343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
59642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
596543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
59662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
5967f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5969aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->hasExplicitTemplateArgs()) {
59703b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // This is a reference to a member without an explicitly-specified
59713b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // template argument list. Optimize for this common case.
59723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
5973aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        Base.get() == OldBase &&
5974aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        BaseType == E->getBaseType() &&
59753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        Qualifier == E->getQualifier() &&
59762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getMember() &&
59773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        FirstQualifierInScope == E->getFirstQualifierFoundInScope())
59783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
59791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
5981aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                       BaseType,
59823b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->isArrow(),
59833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getOperatorLoc(),
59843b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       Qualifier,
59853b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getQualifierRange(),
5986129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       FirstQualifierInScope,
59872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
5988129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       /*TemplateArgs*/ 0);
59893b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
59903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor
5991d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
59923b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
5993d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TemplateArgumentLoc Loc;
5994d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
5995f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5996d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.addArgument(Loc);
59973b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
59981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
6000aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                     BaseType,
6001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->isArrow(),
6002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->getOperatorLoc(),
6003a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     Qualifier,
6004a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     E->getQualifierRange(),
60053b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                     FirstQualifierInScope,
60062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                     NameInfo,
6007129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                     &TransArgs);
6008129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}
6009129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6010129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived>
601160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6012454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
6013129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform the base of the expression.
601460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
6015aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
6016aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!Old->isImplicitAccess()) {
6017aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(Old->getBase());
6018aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
6019f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6020aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
6021aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
6022aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(Old->getBaseType());
6023aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
6024129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6025129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  NestedNameSpecifier *Qualifier = 0;
6026129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->getQualifier()) {
6027129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    Qualifier
6028129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
6029edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  Old->getQualifierRange());
6030129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (Qualifier == 0)
6031f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6032129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6033129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
60342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  LookupResult R(SemaRef, Old->getMemberNameInfo(),
6035129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                 Sema::LookupOrdinaryName);
6036129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6037129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform all the decls.
6038129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6039129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         E = Old->decls_end(); I != E; ++I) {
60407c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
60417c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(Old->getMemberLoc(),
60427c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           *I));
60439f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
60449f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
60459f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
60469f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
60479f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
60489f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
6049f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
60509f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
6051129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6052129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    // Expand using declarations.
6053129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (isa<UsingDecl>(InstD)) {
6054129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
6055129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6056129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall             E = UD->shadow_end(); I != E; ++I)
6057129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall        R.addDecl(*I);
6058129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      continue;
6059129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
6060129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6061129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    R.addDecl(InstD);
6062129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6063129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6064129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  R.resolveKind();
6065129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6066c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  // Determine the naming class.
6067042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth  if (Old->getNamingClass()) {
6068c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    CXXRecordDecl *NamingClass
6069c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
607066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                          Old->getMemberLoc(),
607166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
607266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
6073f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6074c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
607566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
6076c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  }
6077c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6078129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  TemplateArgumentListInfo TransArgs;
6079129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->hasExplicitTemplateArgs()) {
6080129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setLAngleLoc(Old->getLAngleLoc());
6081129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setRAngleLoc(Old->getRAngleLoc());
6082129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6083129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      TemplateArgumentLoc Loc;
6084129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6085129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                 Loc))
6086f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
6087129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      TransArgs.addArgument(Loc);
6088129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
6089129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6090c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
6091c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
6092c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
6093c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
6094c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
6095c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
6096c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
60979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
6098aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  BaseType,
6099129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getOperatorLoc(),
6100129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->isArrow(),
6101129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Qualifier,
6102129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getQualifierRange(),
6103c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                                  FirstQualifierInScope,
6104129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  R,
6105129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              (Old->hasExplicitTemplateArgs()
6106129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  ? &TransArgs : 0));
6107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6109b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
611060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
61112e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
61122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
61132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (SubExpr.isInvalid())
61142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return ExprError();
61152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
61162e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
61173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61182e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
61192e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
61202e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}
61212e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
61222e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived>
61232e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult
6124454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
61253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
61281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
612960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6130454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
613181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  TypeSourceInfo *EncodedTypeInfo
613281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
613381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  if (!EncodedTypeInfo)
6134f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
613781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
61383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
614181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                            EncodedTypeInfo,
6142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc());
6143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
614660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6147454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
614892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Transform arguments.
614992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  bool ArgChanged = false;
6150ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
615192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
615260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
615392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Arg.isInvalid())
6154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6155c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
615692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
61579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Args.push_back(Arg.get());
615892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
615992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
616092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
616192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Class message: transform the receiver type.
616292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    TypeSourceInfo *ReceiverTypeInfo
616392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      = getDerived().TransformType(E->getClassReceiverTypeInfo());
616492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!ReceiverTypeInfo)
6165f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6166c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
616792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // If nothing changed, just retain the existing message send.
616892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
616992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor        ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
61703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
617192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
617292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Build a new class message send.
617392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
617492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getSelector(),
617592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getMethodDecl(),
617692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getLeftLoc(),
617792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               move_arg(Args),
617892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getRightLoc());
617992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
618092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
618192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Instance message: transform the receiver
618292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
618392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         "Only class and instance messages may be instantiated");
618460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Receiver
618592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    = getDerived().TransformExpr(E->getInstanceReceiver());
618692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (Receiver.isInvalid())
6187f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
618892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
618992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // If nothing changed, just retain the existing message send.
619092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
619192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
61923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6193c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
619492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Build a new instance message send.
61959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
619692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getSelector(),
619792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getMethodDecl(),
619892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getLeftLoc(),
619992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             move_arg(Args),
620092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getRightLoc());
6201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
620460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6205454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
62063fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6207b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6208b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
621060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6211454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
62123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6213b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
621660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6217454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
6218f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
621960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6220f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
6221f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6222f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor
6223f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // We don't need to transform the ivar; it will never change.
6224c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6225f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
6226f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
6227f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
62283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6229c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
62309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
6231f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->getLocation(),
6232f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->isArrow(), E->isFreeIvar());
6233b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
623660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6237454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
623812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // 'super' and types never change. Property never changes. Just
623912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // retain the existing expression.
624012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (!E->isObjectReceiver())
62413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62428ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian
6243e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // Transform the base expression.
624460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6245e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (Base.isInvalid())
6246f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6247c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6248e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // We don't need to transform the property; it will never change.
6249c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6250e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // If nothing changed, just retain the existing expression.
6251e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6252e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      Base.get() == E->getBase())
62533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
625512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (E->isExplicitProperty())
625612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
625712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getExplicitProperty(),
625812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getLocation());
625912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall
626012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
626112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getType(),
626212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertyGetter(),
626312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertySetter(),
626412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getLocation());
6265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
626860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6269454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
6270f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
627160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6272f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
6273f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6274c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6275f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
6276f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
6277f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
62783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6279c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
62809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
6281f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                         E->isArrow());
6282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
628560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6286454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
6287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6288ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> SubExprs(SemaRef);
6289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
629060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
6292f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
62931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
62959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    SubExprs.push_back(SubExpr.get());
6296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
62971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
63003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move_arg(SubExprs),
6304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               E->getRParenLoc());
6305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
630860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6309454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
6310a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  SourceLocation CaretLoc(E->getExprLoc());
6311a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6312a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6313a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6314a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6315a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  llvm::SmallVector<ParmVarDecl*, 4> Params;
6316a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  llvm::SmallVector<QualType, 4> ParamTypes;
6317a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6318a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Parameter substitution.
6319a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  const BlockDecl *BD = E->getBlockDecl();
6320a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  for (BlockDecl::param_const_iterator P = BD->param_begin(),
6321a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian       EN = BD->param_end(); P != EN; ++P) {
6322a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    ParmVarDecl *OldParm = (*P);
6323a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6324a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    QualType NewType = NewParm->getType();
6325a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    Params.push_back(NewParm);
6326a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    ParamTypes.push_back(NewParm->getType());
6327a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
6328a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6329a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  const FunctionType *BExprFunctionType = E->getFunctionType();
6330a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  QualType BExprResultType = BExprFunctionType->getResultType();
6331a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!BExprResultType.isNull()) {
6332a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    if (!BExprResultType->isDependentType())
6333a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      CurBlock->ReturnType = BExprResultType;
6334a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    else if (BExprResultType != SemaRef.Context.DependentTy)
6335a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6336a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
6337a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6338a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Transform the body
633960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(E->getBody());
6340a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (Body.isInvalid())
6341f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6342a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Set the parameters on the block decl.
6343a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!Params.empty())
6344a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    CurBlock->TheDecl->setParams(Params.data(), Params.size());
6345a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6346a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  QualType FunctionType = getDerived().RebuildFunctionProtoType(
6347a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        CurBlock->ReturnType,
6348a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        ParamTypes.data(),
6349a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        ParamTypes.size(),
6350a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        BD->isVariadic(),
6351fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                        0,
6352fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                               BExprFunctionType->getExtInfo());
6353a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6354a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  CurBlock->FunctionType = FunctionType;
63559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
6356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
635960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6360454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
6361a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  NestedNameSpecifier *Qualifier = 0;
6362a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6363a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  ValueDecl *ND
6364a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6365a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                       E->getDecl()));
6366a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!ND)
6367f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
6369a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!getDerived().AlwaysRebuild() &&
6370a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      ND == E->getDecl()) {
6371a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // Mark it referenced in the new context regardless.
6372a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // FIXME: this is a bit instantiation-specific.
6373a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6374a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
63753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6376a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
6377a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
63782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
6379a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
63802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, 0);
6381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
6384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction
6385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
6386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
638885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
638985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                    SourceLocation Star) {
63902865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildPointerType(PointeeType, Star,
6391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  getDerived().getBaseEntity());
6392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
639585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
639685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                         SourceLocation Star) {
63972865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildBlockPointerType(PointeeType, Star,
6398b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       getDerived().getBaseEntity());
6399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
64011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
64021eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
640385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
640485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             bool WrittenAsLValue,
640585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             SourceLocation Sigil) {
64062865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
640785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    Sigil, getDerived().getBaseEntity());
6408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
64101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
64111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
641285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
641385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 QualType ClassType,
641485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceLocation Sigil) {
64152865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
641685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        Sigil, getDerived().getBaseEntity());
6417577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6418577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6419577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64201eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
6421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6422577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         ArrayType::ArraySizeModifier SizeMod,
6423577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         const llvm::APInt *Size,
6424577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         Expr *SizeExpr,
6425577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         unsigned IndexTypeQuals,
6426577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         SourceRange BracketsRange) {
6427577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (SizeExpr || !Size)
6428577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6429577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  IndexTypeQuals, BracketsRange,
6430577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  getDerived().getBaseEntity());
64311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType Types[] = {
64331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
64341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
64351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
6436577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  };
6437577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6438577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType SizeType;
6439577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  for (unsigned I = 0; I != NumTypes; ++I)
6440577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6441577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      SizeType = Types[I];
6442577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      break;
6443577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    }
64441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
64469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                           /*FIXME*/BracketsRange.getBegin());
64471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
6448577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                IndexTypeQuals, BracketsRange,
64491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                getDerived().getBaseEntity());
6450577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
64511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6452577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
64541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
6455577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 ArrayType::ArraySizeModifier SizeMod,
6456577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 const llvm::APInt &Size,
645785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
645885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceRange BracketsRange) {
64591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
646085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        IndexTypeQuals, BracketsRange);
6461577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6462577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6463577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
64651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
6466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
646785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
646885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   SourceRange BracketsRange) {
64691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
647085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                       IndexTypeQuals, BracketsRange);
6471577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
64721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6473577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64741eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
64751eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
6476577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
64779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SizeExpr,
6478577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 unsigned IndexTypeQuals,
6479577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceRange BracketsRange) {
64801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
64819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
6482577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
6483577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6484577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6485577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
64871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
6488577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
64899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Expr *SizeExpr,
6490577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                       unsigned IndexTypeQuals,
6491577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                   SourceRange BracketsRange) {
64921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
64939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
6494577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
6495577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6496577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6497577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6498577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
6499e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               unsigned NumElements,
6500e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               VectorType::VectorKind VecKind) {
6501577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  // FIXME: semantic checking!
6502e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
6503577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6505577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6506577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6507577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                      unsigned NumElements,
6508577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceLocation AttributeLoc) {
6509577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6510577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                          NumElements, true);
6511577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  IntegerLiteral *VectorSize
65129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
65139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             AttributeLoc);
65149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
6515577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6517577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
65181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
65191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
65209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                           Expr *SizeExpr,
6521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                  SourceLocation AttributeLoc) {
65229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
6523577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6525577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6526577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
65271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          QualType *ParamTypes,
6528577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                        unsigned NumParamTypes,
65291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          bool Variadic,
6530fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                          unsigned Quals,
6531fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                            const FunctionType::ExtInfo &Info) {
65321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
6533577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   Quals,
6534577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   getDerived().getBaseLocation(),
6535fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   getDerived().getBaseEntity(),
6536fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   Info);
6537577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6539577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6540a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6541a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return SemaRef.Context.getFunctionNoProtoType(T);
6542a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
6543a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
6544a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
6545ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6546ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  assert(D && "no decl found");
6547ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (D->isInvalidDecl()) return QualType();
6548ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
654992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // FIXME: Doesn't account for ObjCInterfaceDecl!
6550ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeDecl *Ty;
6551ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (isa<UsingDecl>(D)) {
6552ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    UsingDecl *Using = cast<UsingDecl>(D);
6553ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(Using->isTypeName() &&
6554ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-typename using");
6555ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
6556ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    // A valid resolved using typename decl points to exactly one type decl.
6557ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(++Using->shadow_begin() == Using->shadow_end());
6558ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6559c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6560ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  } else {
6561ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6562ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-using decl");
6563ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<UnresolvedUsingTypenameDecl>(D);
6564ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
6565ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
6566ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return SemaRef.Context.getTypeDeclType(Ty);
6567ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
6568ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
6569ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived>
65702a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
65712a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                       SourceLocation Loc) {
65722a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildTypeofExprType(E, Loc);
6573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6576577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  return SemaRef.Context.getTypeOfType(Underlying);
6578577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
65812a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
65822a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                     SourceLocation Loc) {
65832a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildDecltypeType(E, Loc);
6584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
6588833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                      TemplateName Template,
6589833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateNameLoc,
6590d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                               const TemplateArgumentListInfo &TemplateArgs) {
6591d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
6592577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6594dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
6595dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
6596dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6597dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
6598a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                   IdentifierInfo &II,
6599c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   QualType ObjectType,
6600d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NamedDecl *FirstQualifierInScope) {
6601dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  CXXScopeSpec SS;
6602dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  // FIXME: The source location information is all wrong.
6603dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SS.setRange(Range);
6604dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SS.setScopeRep(Prefix);
6605dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return static_cast<NestedNameSpecifier *>(
66061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
6607495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor                                                        Range.getEnd(), II,
6608c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                        ObjectType,
6609c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                        FirstQualifierInScope,
661046646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner                                                        false, false));
6611dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
6612dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
6613dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
6614dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
6615dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6616dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
6617dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   NamespaceDecl *NS) {
6618dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6619dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
6620dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
6621dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
6622dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
6623dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6624dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
6625dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   bool TemplateKW,
6626edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                   QualType T) {
6627edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor  if (T->isDependentType() || T->isRecordType() ||
6628dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
6629a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
6630dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6631dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                       T.getTypePtr());
6632dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
66331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6634dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6635dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return 0;
6636dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
66371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6638d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
66391eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
6640d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6641d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            bool TemplateKW,
6642d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            TemplateDecl *Template) {
66431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
6644d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                                  Template);
6645d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
6646d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
6647d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
66481eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
6649d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
66501efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                            SourceRange QualifierRange,
66513b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                            const IdentifierInfo &II,
665243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            QualType ObjectType,
665343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            NamedDecl *FirstQualifierInScope) {
6654d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  CXXScopeSpec SS;
66551efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor  SS.setRange(QualifierRange);
66561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SS.setScopeRep(Qualifier);
6657014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  UnqualifiedId Name;
6658014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
6659d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
6660d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
6661d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*FIXME:*/getDerived().getBaseLocation(),
6662d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
6663d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
6664b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
6665d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
6666d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
666743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return Template.get();
6668d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
66691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
6671ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName
6672ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6673ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            OverloadedOperatorKind Operator,
6674ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            QualType ObjectType) {
6675ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  CXXScopeSpec SS;
6676ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SS.setRange(SourceRange(getDerived().getBaseLocation()));
6677ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SS.setScopeRep(Qualifier);
6678ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  UnqualifiedId Name;
6679ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6680ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6681ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                             Operator, SymbolLocations);
6682d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
6683d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
6684ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                       /*FIXME:*/getDerived().getBaseLocation(),
6685d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
6686d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
6687b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
6688d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
6689d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
6690d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  return Template.template getAsVal<TemplateName>();
6691ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor}
6692c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6693ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived>
669460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   SourceLocation OpLoc,
66979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *OrigCallee,
66989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *First,
66999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *Second) {
67009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Callee = OrigCallee->IgnoreParenCasts();
67019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
67021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Determine whether this should be a builtin operation.
6704f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript) {
67059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
67069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType())
67079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinArraySubscriptExpr(First,
67089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Callee->getLocStart(),
67099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Second, OpLoc);
67101a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman  } else if (Op == OO_Arrow) {
67111a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman    // -> is never a builtin operation.
67129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
67139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  } else if (Second == 0 || isPostIncDec) {
67149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType()) {
6715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // The argument is not of overloadable type, so try to create a
6716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // built-in unary operation.
67172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      UnaryOperatorKind Opc
6718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor        = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
67191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
6721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
6722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  } else {
67239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
67249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType()) {
6725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // Neither of the arguments is an overloadable type, so try to
6726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // create a built-in binary operation.
67272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
672860d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Result
67299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
6730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Result.isInvalid())
6731f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
67321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      return move(Result);
6734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
6735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
67361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Compute the transformed set of functions (and function templates) to be
6738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // used during overload resolution.
67396e26689f5d513e24ad7783a4493201930fdeccc0John McCall  UnresolvedSet<16> Functions;
67401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
6742ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    assert(ULE->requiresADL());
6743ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
6744ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // FIXME: Do we have to check
6745ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // IsAcceptableNonMemberOperatorCandidate for each of these?
67466e26689f5d513e24ad7783a4493201930fdeccc0John McCall    Functions.append(ULE->decls_begin(), ULE->decls_end());
6747ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  } else {
67489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
6749ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
67501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Add any functions found via argument-dependent lookup.
67529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Args[2] = { First, Second };
67539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  unsigned NumArgs = 1 + (Second != 0);
67541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for unary operators.
6756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (NumArgs == 1 || isPostIncDec) {
67572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    UnaryOperatorKind Opc
6758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
67599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
6760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
67611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6762f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript)
67639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
6764ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                                      OpLoc,
67659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      First,
67669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Second);
6767f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl
6768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for binary operators.
67692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
677060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result
6771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Result.isInvalid())
6773f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return move(Result);
6776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
677826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived>
677960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
67809ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
678126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceLocation OperatorLoc,
678226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       bool isArrow,
678326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                 NestedNameSpecifier *Qualifier,
678426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceRange QualifierRange,
678526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     TypeSourceInfo *ScopeType,
678626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       SourceLocation CCLoc,
6787fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                       SourceLocation TildeLoc,
6788a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed) {
678926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  CXXScopeSpec SS;
679026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (Qualifier) {
679126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    SS.setRange(QualifierRange);
679226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    SS.setScopeRep(Qualifier);
679326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
679426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
67959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  QualType BaseType = Base->getType();
67969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
679726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      (!isArrow && !BaseType->getAs<RecordType>()) ||
6798c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      (isArrow && BaseType->getAs<PointerType>() &&
6799bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif       !BaseType->getAs<PointerType>()->getPointeeType()
6800bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif                                              ->template getAs<RecordType>())){
680126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    // This pseudo-destructor expression is still a pseudo-destructor.
68029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
680326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             isArrow? tok::arrow : tok::period,
6804fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                             SS, ScopeType, CCLoc, TildeLoc,
6805a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                             Destroyed,
680626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             /*FIXME?*/true);
680726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
68082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
6809a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
68102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
68112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
68122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
68132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  NameInfo.setNamedTypeInfo(DestroyedType);
68142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
681526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  // FIXME: the ScopeType should be tacked onto SS.
68162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
68179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getSema().BuildMemberReferenceExpr(Base, BaseType,
681826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            OperatorLoc, isArrow,
681926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            SS, /*FIXME: FirstQualifier*/ 0,
68202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            NameInfo,
682126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            /*TemplateArgs*/ 0);
682226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor}
682326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
6824577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang
6825577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6826577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
6827