TreeTransform.h revision 075f8f1b6bed4d1b224c74f87508534cc6392ce6
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
522075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// \brief Build a new parenthesized type.
523075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ///
524075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// By default, builds a new ParenType type from the inner type.
525075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
526075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType RebuildParenType(QualType InnerType) {
527075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return SemaRef.Context.getParenType(InnerType);
528075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
529075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
530577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new qualified name type.
531577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
532465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// By default, builds a new ElaboratedType type from the keyword,
533465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// the nested-name-specifier and the named type.
534465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
53521e413fe6305a198564d436ac515497716c47844John McCall  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
53621e413fe6305a198564d436ac515497716c47844John McCall                                 ElaboratedTypeKeyword Keyword,
537465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                                 NestedNameSpecifier *NNS, QualType Named) {
538465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
540577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
541577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to a template-id.
542577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
543e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// By default, builds a new DependentNameType type from the
544e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// nested-name-specifier and the given type. Subclasses may override
545e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// this routine to provide different behavior.
54633500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType RebuildDependentTemplateSpecializationType(
54733500955d731c73717af52088b7fc0e7a85681e7John McCall                                    ElaboratedTypeKeyword Keyword,
5481efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                    NestedNameSpecifier *Qualifier,
5491efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                    SourceRange QualifierRange,
55033500955d731c73717af52088b7fc0e7a85681e7John McCall                                    const IdentifierInfo *Name,
55133500955d731c73717af52088b7fc0e7a85681e7John McCall                                    SourceLocation NameLoc,
55233500955d731c73717af52088b7fc0e7a85681e7John McCall                                    const TemplateArgumentListInfo &Args) {
55333500955d731c73717af52088b7fc0e7a85681e7John McCall    // Rebuild the template name.
55433500955d731c73717af52088b7fc0e7a85681e7John McCall    // TODO: avoid TemplateName abstraction
55533500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateName InstName =
5561efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
55743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                       QualType(), 0);
55833500955d731c73717af52088b7fc0e7a85681e7John McCall
55996fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor    if (InstName.isNull())
56096fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor      return QualType();
56196fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor
56233500955d731c73717af52088b7fc0e7a85681e7John McCall    // If it's still dependent, make a dependent specialization.
56333500955d731c73717af52088b7fc0e7a85681e7John McCall    if (InstName.getAsDependentTemplateName())
56433500955d731c73717af52088b7fc0e7a85681e7John McCall      return SemaRef.Context.getDependentTemplateSpecializationType(
5651efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                          Keyword, Qualifier, Name, Args);
56633500955d731c73717af52088b7fc0e7a85681e7John McCall
56733500955d731c73717af52088b7fc0e7a85681e7John McCall    // Otherwise, make an elaborated type wrapping a non-dependent
56833500955d731c73717af52088b7fc0e7a85681e7John McCall    // specialization.
56933500955d731c73717af52088b7fc0e7a85681e7John McCall    QualType T =
57033500955d731c73717af52088b7fc0e7a85681e7John McCall      getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
57133500955d731c73717af52088b7fc0e7a85681e7John McCall    if (T.isNull()) return QualType();
572465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
57322f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara    // NOTE: NNS is already recorded in template specialization type T.
57422f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
576577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to an identifier.
578577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typename type
580e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// (or elaborated type). Subclasses may override this routine to provide
581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
582e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
5834a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                                    NestedNameSpecifier *NNS,
5844a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                                    const IdentifierInfo *Id,
585e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation KeywordLoc,
586e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceRange NNSRange,
587e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation IdLoc) {
5884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    CXXScopeSpec SS;
5894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SS.setScopeRep(NNS);
590e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    SS.setRange(NNSRange);
591e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
5924033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (NNS->isDependent()) {
5934033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      // If the name is still dependent, just build a new dependent name type.
5944033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      if (!SemaRef.computeDeclContext(SS))
5954033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
5964033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
5974033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
598465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (Keyword == ETK_None || Keyword == ETK_Typename)
599e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
600e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                       KeywordLoc, NNSRange, IdLoc);
601465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
602465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
603465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
604e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    // We had a dependent elaborated-type-specifier that has been transformed
6054033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // into a non-dependent elaborated-type-specifier. Find the tag we're
6064033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // referring to.
607e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
6084033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    DeclContext *DC = SemaRef.computeDeclContext(SS, false);
6094033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!DC)
6104033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
6114033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
6125613876991c80a684595fe8de1f039296a0657ffJohn McCall    if (SemaRef.RequireCompleteDeclContext(SS, DC))
6135613876991c80a684595fe8de1f039296a0657ffJohn McCall      return QualType();
6145613876991c80a684595fe8de1f039296a0657ffJohn McCall
6154033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    TagDecl *Tag = 0;
6164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SemaRef.LookupQualifiedName(Result, DC);
6174033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    switch (Result.getResultKind()) {
6184033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFound:
6194033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFoundInCurrentInstantiation:
6204033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
621c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6224033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Found:
6234033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        Tag = Result.getAsSingle<TagDecl>();
6244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
625c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6264033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundOverloaded:
6274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundUnresolvedValue:
6284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        llvm_unreachable("Tag lookup cannot find non-tags");
6294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
630c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6314033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Ambiguous:
6324033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        // Let the LookupResult structure handle ambiguities.
6334033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
6344033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
6354033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
6364033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!Tag) {
6371eabb7d0c30f6a876b0fd03ad4656c096c26b8d0Douglas Gregor      // FIXME: Would be nice to highlight just the source range.
638e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
6391eabb7d0c30f6a876b0fd03ad4656c096c26b8d0Douglas Gregor        << Kind << Id << DC;
6404033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
6414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
642465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
643e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
644e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
6454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
6464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
6474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
6484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
6494033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // Build the elaborated-type-specifier type.
6504033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    QualType T = SemaRef.Context.getTypeDeclType(Tag);
651465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
652dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
654dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and an
655dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// identifier that names the next step in the nested-name-specifier.
656dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
657dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
658dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
659dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
660dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
661dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
662a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                  IdentifierInfo &II,
663c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                  QualType ObjectType,
664c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                              NamedDecl *FirstQualifierInScope);
665dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
666dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and the
667dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// namespace named in the next step in the nested-name-specifier.
668dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
669dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
670dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
671dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
672dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
673dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
674dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  NamespaceDecl *NS);
675dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
676dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// \brief Build a new nested-name-specifier given the prefix and the
677dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// type named in the next step in the nested-name-specifier.
678dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  ///
679dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, performs semantic analysis when building the new
680dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// nested-name-specifier. Subclasses may override this routine to provide
681dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// different behavior.
682dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
683dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  SourceRange Range,
684dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                  bool TemplateKW,
685edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  QualType T);
686d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
687d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier, a flag
688d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// indicating whether the "template" keyword was provided, and the template
689d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// that the template name refers to.
690d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
691d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, builds the new template name directly. Subclasses may override
692d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// this routine to provide different behavior.
693d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
694d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   bool TemplateKW,
695d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   TemplateDecl *Template);
696d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
697d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier and the
698d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// name that is referred to as a template.
699d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
700d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
701d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
702d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// template name. Subclasses may override this routine to provide different
703d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// behavior.
704d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
7051efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                   SourceRange QualifierRange,
7063b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                   const IdentifierInfo &II,
70743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   QualType ObjectType,
70843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   NamedDecl *FirstQualifierInScope);
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
710ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// \brief Build a new template name given a nested name specifier and the
711ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// overloaded operator name that is referred to as a template.
712ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  ///
713ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// By default, performs semantic analysis to determine whether the name can
714ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
715ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// template name. Subclasses may override this routine to provide different
716ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// behavior.
717ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
718ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   OverloadedOperatorKind Operator,
719ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   QualType ObjectType);
720c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
72143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new compound statement.
72243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
72343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
72443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
72560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
72643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       MultiStmtArg Statements,
72743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       SourceLocation RBraceLoc,
72843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       bool IsStmtExpr) {
7299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
73043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       IsStmtExpr);
73143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
73243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
73343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new case statement.
73443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
73543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
73643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
73760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
7389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *LHS,
73943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EllipsisLoc,
7409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *RHS,
74143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation ColonLoc) {
7429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
74343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   ColonLoc);
74443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to a new case statement.
74743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
74843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
74943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
75060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
7519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().ActOnCaseStmtBody(S, Body);
7529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return S;
75343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new default statement.
75643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
75743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
75843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
75960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
76043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      SourceLocation ColonLoc,
7619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      Stmt *SubStmt) {
7629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
76343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      /*CurScope=*/0);
76443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new label statement.
76743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
76843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
76943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
77060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
77143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    IdentifierInfo *Id,
77243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    SourceLocation ColonLoc,
7731a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                    Stmt *SubStmt, bool HasUnusedAttr) {
7741a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis    return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
7751a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                  HasUnusedAttr);
77643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new "if" statement.
77943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
78043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
78143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
78260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
78344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                 VarDecl *CondVar, Stmt *Then,
7849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 SourceLocation ElseLoc, Stmt *Else) {
78544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis    return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
78643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
78843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Start building a new switch statement.
78943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
79043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
79143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
79260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
7939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Cond, VarDecl *CondVar) {
7949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
795d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                            CondVar);
79643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
7971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to the switch statement.
79943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
80043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
80143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
80260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
8039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Stmt *Switch, Stmt *Body) {
8049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
80543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
80643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
80743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new while statement.
80843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
80943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
81043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
81160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
812eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor                                    Sema::FullExprArg Cond,
81399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor                                    VarDecl *CondVar,
8149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Stmt *Body) {
8159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
81643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new do-while statement.
81943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
82043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
82143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
82260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
82343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation WhileLoc,
82443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation LParenLoc,
8259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Expr *Cond,
82643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                 SourceLocation RParenLoc) {
8279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
8289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Cond, RParenLoc);
82943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
83043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
83143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new for statement.
83243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
83343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
83443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
83560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildForStmt(SourceLocation ForLoc,
83643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                  SourceLocation LParenLoc,
8379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Stmt *Init, Sema::FullExprArg Cond,
83899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor                                  VarDecl *CondVar, Sema::FullExprArg Inc,
8399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  SourceLocation RParenLoc, Stmt *Body) {
8409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
841d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                  CondVar,
8429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Inc, RParenLoc, Body);
84343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
84543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new goto statement.
84643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
84743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
84843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
84960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
85043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation LabelLoc,
85143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   LabelStmt *Label) {
85243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
85343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
85443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
85543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new indirect goto statement.
85643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
85743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
85843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
85960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
86043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                           SourceLocation StarLoc,
8619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *Target) {
8629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
86343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new return statement.
86643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
86743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
86843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
86960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
8709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Result) {
8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnReturnStmt(ReturnLoc, Result);
87343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new declaration statement.
87643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
87743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
87843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
87960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
8801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   SourceLocation StartLoc,
88143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EndLoc) {
88243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return getSema().Owned(
88343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor             new (getSema().Context) DeclStmt(
88443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                        DeclGroupRef::Create(getSema().Context,
88543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                             Decls, NumDecls),
88643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              StartLoc, EndLoc));
88743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
889703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// \brief Build a new inline asm statement.
890703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  ///
891703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// By default, performs semantic analysis to build the new statement.
892703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// Subclasses may override this routine to provide different behavior.
89360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
894703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsSimple,
895703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsVolatile,
896703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumOutputs,
897703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumInputs,
898ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                  IdentifierInfo **Names,
899703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Constraints,
900703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Exprs,
9019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Expr *AsmString,
902703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Clobbers,
903703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  SourceLocation RParenLoc,
904703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool MSAsm) {
905c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
906703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  NumInputs, Names, move(Constraints),
9079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Exprs, AsmString, Clobbers,
908703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  RParenLoc, MSAsm);
909703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
9104dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
9114dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @try statement.
9124dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
9134dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
9144dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
91560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
9169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *TryBody,
9178f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                        MultiStmtArg CatchStmts,
9189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *Finally) {
9199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
9209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Finally);
9214dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
9224dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
923be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Rebuild an Objective-C exception declaration.
924be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
925be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new declaration.
926be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
927be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
928be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                    TypeSourceInfo *TInfo, QualType T) {
929c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildObjCExceptionDecl(TInfo, T,
930c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                            ExceptionDecl->getIdentifier(),
931be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                            ExceptionDecl->getLocation());
932be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
933c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
934be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Build a new Objective-C @catch statement.
935be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
936be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
937be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
93860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
939be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          SourceLocation RParenLoc,
940be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          VarDecl *Var,
9419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Stmt *Body) {
942be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
9439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Var, Body);
944be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
945c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
9464dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @finally statement.
9474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
9484dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
9494dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
95060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
9519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Stmt *Body) {
9529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
9534dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
954c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
9558fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @throw statement.
956d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  ///
957d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
958d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
95960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
9609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Operand) {
9619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
962d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
963c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
9648fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @synchronized statement.
9658fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  ///
9668fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
9678fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
96860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
9699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *Object,
9709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Stmt *Body) {
9719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
9729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Body);
9738fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  }
974c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor
975c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// \brief Build a new Objective-C fast enumeration statement.
976c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  ///
977c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
978c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
97960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
980f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation LParenLoc,
981f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Element,
982f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Expr *Collection,
983f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation RParenLoc,
984f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Body) {
985c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor    return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
9869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Element,
9879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Collection,
988c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                RParenLoc,
9899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Body);
990c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  }
991c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
99243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ exception declaration.
99343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new decaration.
99543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
99683cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
997a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                                TypeSourceInfo *Declarator,
99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                IdentifierInfo *Name,
99983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                SourceLocation Loc) {
100083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
100243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
100343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ catch statement.
100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
100543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
100643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
100760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1008f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 VarDecl *ExceptionDecl,
1009f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 Stmt *Handler) {
10109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
10119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Handler));
101243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ try statement.
101543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
101643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
101743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
101860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1019f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               Stmt *TryBlock,
1020f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               MultiStmtArg Handlers) {
10219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
102243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression that references a declaration.
1025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
102860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1029f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        LookupResult &R,
1030f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        bool RequiresADL) {
1031f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1032f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1033f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1034f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1035f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Build a new expression that references a declaration.
1036f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  ///
1037f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// By default, performs semantic analysis to build the new expression.
1038f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Subclasses may override this routine to provide different behavior.
103960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1040f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                SourceRange QualifierRange,
1041f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                ValueDecl *VD,
1042f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                const DeclarationNameInfo &NameInfo,
1043f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                TemplateArgumentListInfo *TemplateArgs) {
1044a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    CXXScopeSpec SS;
1045a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    SS.setScopeRep(Qualifier);
1046a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    SS.setRange(QualifierRange);
1047dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
1048dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: loses template args.
10492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
10502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1051b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1053b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression in parentheses.
10541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1055b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
105760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                    SourceLocation RParen) {
10599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1060b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1062a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Build a new pseudo-destructor expression.
10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1064a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1065a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
106660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1067a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                  SourceLocation OperatorLoc,
1068a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                  bool isArrow,
1069a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                NestedNameSpecifier *Qualifier,
107026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  SourceRange QualifierRange,
107126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  TypeSourceInfo *ScopeType,
107226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                  SourceLocation CCLoc,
1073fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                  SourceLocation TildeLoc,
1074a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed);
10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary operator expression.
10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1078b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
108060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
10812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                        UnaryOperatorKind Opc,
10829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *SubExpr) {
10839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build a new builtin offsetof expression.
10878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
10888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
10898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
109060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
10918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       TypeSourceInfo *Type,
1092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                       Sema::OffsetOfComponent *Components,
10938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       unsigned NumComponents,
10948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       SourceLocation RParenLoc) {
10958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
10968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          NumComponents, RParenLoc);
10978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1098c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new sizeof or alignof expression with a type argument.
11001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
110360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
11045ab75172051a6d2ea71a80a79e81c65519fd3462John McCall                                        SourceLocation OpLoc,
1105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool isSizeOf, SourceRange R) {
1106a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
1107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new sizeof or alignof expression with an expression
1110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument.
11111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1113b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
111460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
1115b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool isSizeOf, SourceRange R) {
111660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
11179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
1118b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1119f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1122b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new array subscript expression.
11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
112860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1129b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LBracketLoc,
11309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *RHS,
1131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RBracketLoc) {
11329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
11339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             LBracketLoc, RHS,
1134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             RBracketLoc);
1135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new call expression.
11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
114160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Args,
1143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
11449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1145a1a04786cea2445759026edacd096abd1fbf4a05Douglas Gregor                                   move(Args), RParenLoc);
1146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member access expression.
11491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1151b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
115260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1153f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               bool isArrow,
1154f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NestedNameSpecifier *Qualifier,
1155f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               SourceRange QualifierRange,
1156f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               const DeclarationNameInfo &MemberNameInfo,
1157f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               ValueDecl *Member,
1158f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FoundDecl,
1159d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                        const TemplateArgumentListInfo *ExplicitTemplateArgs,
1160f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FirstQualifierInScope) {
1161d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    if (!Member->getDeclName()) {
1162f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // We have a reference to an unnamed field.  This is always the
1163f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // base of an anonymous struct/union member access, i.e. the
1164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // field is always of record type.
1165d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
1166f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      assert(Member->getType()->isRecordType() &&
1167f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             "unnamed member not of record type?");
11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      if (getSema().PerformObjectMemberConversion(Base, Qualifier,
11706bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                                  FoundDecl, Member))
1171f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
11728aa5f407d9e4787ff08bd66e1a2fe39be174fddcDouglas Gregor
1173f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      MemberExpr *ME =
11759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        new (getSema().Context) MemberExpr(Base, isArrow,
11762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           Member, MemberNameInfo,
1177f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           cast<FieldDecl>(Member)->getType(),
1178f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           VK, OK_Ordinary);
1179d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      return getSema().Owned(ME);
1180d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    }
11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    CXXScopeSpec SS;
118383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    if (Qualifier) {
118483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      SS.setRange(QualifierRange);
118583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      SS.setScopeRep(Qualifier);
118683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    }
118783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
11889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().DefaultFunctionArrayConversion(Base);
11899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    QualType BaseType = Base->getType();
1190aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
11916bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // FIXME: this involves duplicating earlier analysis in a lot of
11926bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // cases; we should avoid this when possible.
11932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
11946bb8017bb9e828d118e15e59d71c66bba323c364John McCall    R.addDecl(FoundDecl);
1195c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    R.resolveKind();
1196c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
11979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1198129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, FirstQualifierInScope,
1199c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                              R, ExplicitTemplateArgs);
1200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new binary operator expression.
12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1204b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1205b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
120660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
12072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                         BinaryOperatorKind Opc,
12089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *LHS, Expr *RHS) {
12099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1210b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1212b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new conditional operator expression.
12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
121660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildConditionalOperator(Expr *Cond,
1217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation QuestionLoc,
12189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *LHS,
1219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation ColonLoc,
12209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *RHS) {
12219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
12229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        LHS, RHS);
1223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C-style cast expression.
12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
122960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
12309d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                         TypeSourceInfo *TInfo,
1231b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc,
12329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *SubExpr) {
1233b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall    return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
12349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubExpr);
1235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1237b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new compound literal expression.
12381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1240b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
124160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
124242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall                                              TypeSourceInfo *TInfo,
1243b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation RParenLoc,
12449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Init) {
124542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
12469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Init);
1247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new extended vector element access expression.
12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1251b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1252b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
125360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildExtVectorElementExpr(Expr *Base,
1254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation OpLoc,
1255b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation AccessorLoc,
1256b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               IdentifierInfo &Accessor) {
1257aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
1258129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    CXXScopeSpec SS;
12592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
12609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1261129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              OpLoc, /*IsArrow*/ false,
1262129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, /*FirstQualifierInScope*/ 0,
12632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                              NameInfo,
1264129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              /* TemplateArgs */ 0);
1265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new initializer list expression.
12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1269b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1270b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
127160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildInitList(SourceLocation LBraceLoc,
1272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Inits,
1273e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   SourceLocation RBraceLoc,
1274e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                   QualType ResultTy) {
127560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1276e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1277e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    if (Result.isInvalid() || ResultTy->isDependentType())
1278e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      return move(Result);
1279c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1280e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // Patch in the result type we were given, which may have been computed
1281e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // when the initial InitListExpr was built.
1282e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1283e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    ILE->setType(ResultTy);
1284e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    return move(Result);
1285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new designated initializer expression.
12881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1290b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
129160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             MultiExprArg ArrayExprs,
1293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation EqualOrColonLoc,
1294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             bool GNUSyntax,
12959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *Init) {
129660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
12989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Init);
1299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1300f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.release();
1303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new value-initialized expression.
13071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds the implicit value initialization without performing
1309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// any semantic analysis. Subclasses may override this routine to provide
1310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
131160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildImplicitValueInitExpr(QualType T) {
1312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new \c va_arg expression.
13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
131960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
13209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SubExpr, TypeSourceInfo *TInfo,
13212cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    SourceLocation RParenLoc) {
13222cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara    return getSema().BuildVAArgExpr(BuiltinLoc,
13239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    SubExpr, TInfo,
13242cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    RParenLoc);
1325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1327b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression list in parentheses.
13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
133160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        MultiExprArg SubExprs,
1333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1334c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1335f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian                                               move(SubExprs));
1336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new address-of-label expression.
13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
13401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis, using the name of the label
1341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// rather than attempting to map the label statement itself.
1342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
134360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation LabelLoc,
1345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        LabelStmt *Label) {
1346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new GNU statement expression.
13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
135360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
13549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Stmt *SubStmt,
1355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
13569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new __builtin_choose_expr expression.
1360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
136360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
13649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Cond, Expr *LHS, Expr *RHS,
1365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                     SourceLocation RParenLoc) {
1366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.ActOnChooseExpr(BuiltinLoc,
13679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Cond, LHS, RHS,
1368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   RParenLoc);
1369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new overloaded operator call expression.
1372b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// The semantic analysis provides the behavior of template instantiation,
1375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// copying with transformations that turn what looks like an overloaded
13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// operator call into a use of a builtin operator, performing
1377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument-dependent lookup, etc. Subclasses may override this routine to
1378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
137960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation OpLoc,
13819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Callee,
13829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *First,
13839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Second);
13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++ "named" cast expression, such as static_cast or
1386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// reinterpret_cast.
1387b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1388b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine dispatches to one of the more-specific routines
13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
139160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           Stmt::StmtClass Class,
1393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
13949d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
13979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1398b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    switch (Class) {
1400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXStaticCastExprClass:
14019d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
14039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
1404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXDynamicCastExprClass:
14069d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                    RAngleLoc, LParenLoc,
14089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    SubExpr, RParenLoc);
14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXReinterpretCastExprClass:
14119d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                        RAngleLoc, LParenLoc,
14139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                        SubExpr,
1414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        RParenLoc);
14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXConstCastExprClass:
14179d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
14199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    default:
1422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      assert(false && "Invalid C++ named cast");
1423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      break;
1424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
14251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1426f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
1427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ static_cast expression.
1430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
143360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LAngleLoc,
14359d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                            TypeSourceInfo *TInfo,
1436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RAngleLoc,
1437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LParenLoc,
14389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Expr *SubExpr,
1439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RParenLoc) {
1440c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
14419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1442c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1443c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1446b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ dynamic_cast expression.
1447b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
145060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1451b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LAngleLoc,
14529d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                             TypeSourceInfo *TInfo,
1453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RAngleLoc,
1454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LParenLoc,
14559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *SubExpr,
1456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RParenLoc) {
1457c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
14589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1459c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1460c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ reinterpret_cast expression.
1464b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1465b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
146760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LAngleLoc,
14699d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                                 TypeSourceInfo *TInfo,
1470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RAngleLoc,
1471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LParenLoc,
14729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SubExpr,
1473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RParenLoc) {
1474c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
14759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1476c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1477c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1479b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ const_cast expression.
1481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
148460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
14869d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
14899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1491c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
14929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1493c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1494c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ functional-style cast expression.
1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1500b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1501ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1502ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation LParenLoc,
1503ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          Expr *Sub,
1504ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation RParenLoc) {
1505ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1506f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                               MultiExprArg(&Sub, 1),
1507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(type) expression.
1511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
151460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
151557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
151657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        TypeSourceInfo *Operand,
1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1518c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
151957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
1520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
152201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(expr) expression.
1524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
152760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
152857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
15299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand,
1530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
15319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
153257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
15341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
153501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(type) expression.
153601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
153701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
153801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
153901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
154001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
154101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        TypeSourceInfo *Operand,
154201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
154301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
154401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
154501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
154601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
154701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(expr) expression.
154801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
154901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
155001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
155101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
155201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
155301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        Expr *Operand,
155401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
155501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
155601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
155701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
155801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "this" expression.
1560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new "this" expression without performing any
15621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// semantic analysis. Subclasses may override this routine to provide
1563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
156460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1565ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                QualType ThisType,
1566ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                bool isImplicit) {
1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().Owned(
1568828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                      new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1569828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                                                          isImplicit));
1570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ throw expression.
1573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
157660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
15779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXThrow(ThrowLoc, Sub);
1578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ default-argument expression.
1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new default-argument expression, which does not
1583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// require any semantic analysis. Subclasses may override this routine to
1584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
158560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1586036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                            ParmVarDecl *Param) {
1587036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1588036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                                     Param));
1589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ zero-initialization expression.
1592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1595ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1596ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1597ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1598ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                               MultiExprArg(getSema(), 0, 0),
1600ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               RParenLoc);
1601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "new" expression.
1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
160760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
16081bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               bool UseGlobal,
16091bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementLParen,
16101bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg PlacementArgs,
16111bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementRParen,
16121bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceRange TypeIdParens,
16131bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               QualType AllocatedType,
16141bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               TypeSourceInfo *AllocatedTypeInfo,
16151bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               Expr *ArraySize,
16161bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorLParen,
16171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg ConstructorArgs,
16181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorRParen) {
16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getSema().BuildCXXNew(StartLoc, UseGlobal,
1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementLParen,
1621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(PlacementArgs),
1622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementRParen,
16234bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                 TypeIdParens,
16241bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedType,
16251bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedTypeInfo,
16269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 ArraySize,
1627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorLParen,
1628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(ConstructorArgs),
1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorRParen);
1630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "delete" expression.
1633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
163660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsGlobalDelete,
1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsArrayForm,
16399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand) {
1640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
16419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Operand);
1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary type trait expression.
1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
164860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
16493d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation StartLoc,
16503d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   TypeSourceInfo *T,
16513d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation RParenLoc) {
16523d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor    return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
1653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
16556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// \brief Build a new binary type trait expression.
16566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ///
16576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// By default, performs semantic analysis to build the new expression.
16586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Subclasses may override this routine to provide different behavior.
16596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
16606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation StartLoc,
16616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *LhsT,
16626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *RhsT,
16636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation RParenLoc) {
16646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
16656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
16666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
16671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new (previously unresolved) declaration reference
1668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// expression.
1669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
167260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                SourceRange QualifierRange,
16742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                       const DeclarationNameInfo &NameInfo,
1675f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
1677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SS.setRange(QualifierRange);
1678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SS.setScopeRep(NNS);
1679f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1680f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (TemplateArgs)
16812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
1682f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                    *TemplateArgs);
1683f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
16842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
1685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new template-id expression.
1688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
169160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1692f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         LookupResult &R,
1693f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         bool RequiresADL,
1694d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                              const TemplateArgumentListInfo &TemplateArgs) {
1695f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
1696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
170260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstructExpr(QualType T,
17034411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                           SourceLocation Loc,
1704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           CXXConstructorDecl *Constructor,
1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           bool IsElidable,
17068c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           MultiExprArg Args,
17078c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           bool RequiresZeroInit,
1708428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                             CXXConstructExpr::ConstructionKind ConstructKind,
1709428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           SourceRange ParenRange) {
1710ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
1711c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
17124411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                          ConvertedArgs))
1713f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1714c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
17154411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor    return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
17168c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           move_arg(ConvertedArgs),
1717428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           RequiresZeroInit, ConstructKind,
1718428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           ParenRange);
1719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1725ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1726ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1727ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           MultiExprArg Args,
1728ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1729ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
1730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
1731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
1736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1739ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1740ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation LParenLoc,
1741ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               MultiExprArg Args,
1742ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation RParenLoc) {
1743ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
1744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
1745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
1746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member reference expression.
1750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
175360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
1754aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  QualType BaseType,
1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  bool IsArrow,
1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  SourceLocation OperatorLoc,
1757a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                              NestedNameSpecifier *Qualifier,
1758a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                  SourceRange QualifierRange,
1759129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            NamedDecl *FirstQualifierInScope,
17602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                   const DeclarationNameInfo &MemberNameInfo,
1761129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
1762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
1763a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    SS.setRange(QualifierRange);
1764a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    SS.setScopeRep(Qualifier);
17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1767aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
1768129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            SS, FirstQualifierInScope,
17692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            MemberNameInfo,
17702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            TemplateArgs);
1771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1773129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Build a new member reference expression.
17743b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  ///
17753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
17763b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
177760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
1778aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                               QualType BaseType,
1779129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceLocation OperatorLoc,
1780129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               bool IsArrow,
1781129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               NestedNameSpecifier *Qualifier,
1782129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceRange QualifierRange,
1783c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                               NamedDecl *FirstQualifierInScope,
1784129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               LookupResult &R,
1785129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                const TemplateArgumentListInfo *TemplateArgs) {
17863b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    CXXScopeSpec SS;
17873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    SS.setRange(QualifierRange);
17883b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    SS.setScopeRep(Qualifier);
17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
1791aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
1792c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            SS, FirstQualifierInScope,
1793c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            R, TemplateArgs);
17943b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
17951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17962e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// \brief Build a new noexcept expression.
17972e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ///
17982e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// By default, performs semantic analysis to build the new expression.
17992e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// Subclasses may override this routine to provide different behavior.
18002e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
18012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
18022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
18032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
1804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new Objective-C @encode expression.
1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
180860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
180981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                         TypeSourceInfo *EncodeTypeInfo,
1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc) {
181181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                           RParenLoc));
18131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
1814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
181592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C class message.
181660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
181792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
181892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
1819c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
182092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
182192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
182292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return SemaRef.BuildClassMessage(ReceiverTypeInfo,
182392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     ReceiverTypeInfo->getType(),
182492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     /*SuperLoc=*/SourceLocation(),
1825f49bb082ebf6413b2d3cb956e9c78dbb8a978c58Douglas Gregor                                     Sel, Method, LBracLoc, RBracLoc,
182692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     move(Args));
182792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
182892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
182992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C instance message.
183060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(Expr *Receiver,
183192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
183292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
1833c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
183492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
183592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
18369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildInstanceMessage(Receiver,
18379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Receiver->getType(),
183892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        /*SuperLoc=*/SourceLocation(),
1839f49bb082ebf6413b2d3cb956e9c78dbb8a978c58Douglas Gregor                                        Sel, Method, LBracLoc, RBracLoc,
184092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        move(Args));
184192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
184292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
1843f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C ivar reference expression.
1844f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
1845f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
1846f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
184760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
1848f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          SourceLocation IvarLoc,
1849f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          bool IsArrow, bool IsFreeIvar) {
1850f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    // FIXME: We lose track of the IsFreeIvar bit.
1851f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
18529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
1853f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1854f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
185560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1856f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IvarLoc,
1857d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0,
1858ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall                                                         false);
1859f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.isInvalid())
1860f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1861c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1862f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
1863f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
1864c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1866c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IvarLoc, IsArrow, SS,
1867f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
1868c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
1869f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
1870f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
1871e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor
1872e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// \brief Build a new Objective-C property reference expression.
1873e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  ///
1874e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1875e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
187660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
1877e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              ObjCPropertyDecl *Property,
1878e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              SourceLocation PropertyLoc) {
1879e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    CXXScopeSpec SS;
18809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
1881e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1882e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                   Sema::LookupMemberName);
1883e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    bool IsArrow = false;
188460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1885e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                                         /*FIME:*/PropertyLoc,
1886d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
1887e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.isInvalid())
1888f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1889c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1890e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.get())
1891e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      return move(Result);
1892c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1894c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/PropertyLoc, IsArrow,
1895c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              SS,
1896e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*FirstQualifierInScope=*/0,
1897c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
1898e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*TemplateArgs=*/0);
1899e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  }
1900c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
190112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// \brief Build a new Objective-C property reference expression.
19029cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  ///
19039cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
190412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// Subclasses may override this routine to provide different behavior.
190512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
190612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Getter,
190712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Setter,
190812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        SourceLocation PropertyLoc) {
190912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // Since these expressions can only be value-dependent, we do not
191012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // need to perform semantic analysis again.
191112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return Owned(
191212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
191312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  VK_LValue, OK_ObjCProperty,
191412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  PropertyLoc, Base));
19159cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  }
19169cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor
1917f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C "isa" expression.
1918f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
1919f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
1920f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
192160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
1922f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                      bool IsArrow) {
1923f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
19249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Expr *Base = BaseArg;
1925f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1926f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
192760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1928f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IsaLoc,
1929d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
1930f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.isInvalid())
1931f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
1932c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1933f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
1934f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
1935c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
19369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1937c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IsaLoc, IsArrow, SS,
1938f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
1939c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
1940f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
1941f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
1942c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1943b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new shuffle vector expression.
1944b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
194760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1948f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      MultiExprArg SubExprs,
1949f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      SourceLocation RParenLoc) {
1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Find the declaration for __builtin_shufflevector
19511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const IdentifierInfo &Name
1952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.Context.Idents.get("__builtin_shufflevector");
1953b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Build a reference to the __builtin_shufflevector builtin
1958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
19591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Expr *Callee
1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
1961f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                          VK_LValue, BuiltinLoc);
1962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SemaRef.UsualUnaryConversions(Callee);
19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Build the CallExpr
1965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    unsigned NumSubExprs = SubExprs.size();
1966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Expr **Subs = (Expr **)SubExprs.release();
1967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       Subs, NumSubExprs,
19695291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor                                                   Builtin->getCallResultType(),
1970f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            Expr::getValueKindForType(Builtin->getResultType()),
1971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       RParenLoc);
197260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult OwnedCall(SemaRef.Owned(TheCall));
19731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Type-check the __builtin_shufflevector expression.
197560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1977f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
19781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    OwnedCall.release();
19801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return move(Result);
1981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
198243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
198343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate:
198443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformTypeInObjectScope(QualType T,
198543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      QualType ObjectType,
198643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      NamedDecl *FirstQualifierInScope,
198743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      NestedNameSpecifier *Prefix);
198843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
198943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
199043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             QualType ObjectType,
199143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             NamedDecl *FirstQualifierInScope,
199243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             NestedNameSpecifier *Prefix);
1993577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor};
1994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
199543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
199660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
199743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!S)
199843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return SemaRef.Owned(S);
19991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
200043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  switch (S->getStmtClass()) {
200143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::NoStmtClass: break;
20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
200343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform individual statement nodes
200443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                                              \
200543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
200643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent)
20074bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
20081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
200943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform expressions by calling TransformExpr.
201043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)
20117381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
201243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class:
20134bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
201443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    {
201560d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
201643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      if (E.isInvalid())
2017f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
202043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    }
20211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
202443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2027670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived>
202860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!E)
2030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(E);
2031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  switch (E->getStmtClass()) {
2033b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::NoStmtClass: break;
2034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break;
20357381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
2036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                                              \
2037454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall    case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
20384bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
20391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
20401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
2042657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor}
2043657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor
2044657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived>
2045dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
2046dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
2047a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     SourceRange Range,
2048c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                     QualType ObjectType,
2049c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                             NamedDecl *FirstQualifierInScope) {
205043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  NestedNameSpecifier *Prefix = NNS->getPrefix();
20511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
205243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the prefix of this nested name specifier.
2053dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  if (Prefix) {
20541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
2055c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                       ObjectType,
2056c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                       FirstQualifierInScope);
2057dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    if (!Prefix)
2058dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return 0;
2059dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
20601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2061dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  switch (NNS->getKind()) {
2062dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Identifier:
206343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (Prefix) {
206443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // The object type and qualifier-in-scope really apply to the
206543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // leftmost entity.
206643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      ObjectType = QualType();
206743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      FirstQualifierInScope = 0;
206843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
206943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
20701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert((Prefix || !ObjectType.isNull()) &&
2071a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor            "Identifier nested-name-specifier with no prefix or object type");
2072a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2073a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor        ObjectType.isNull())
2074dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
20751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2077a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                   *NNS->getAsIdentifier(),
2078c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   ObjectType,
2079c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   FirstQualifierInScope);
20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2081dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Namespace: {
20821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NamespaceDecl *NS
2083dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      = cast_or_null<NamespaceDecl>(
20847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                    getDerived().TransformDecl(Range.getBegin(),
20857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       NNS->getAsNamespace()));
20861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (!getDerived().AlwaysRebuild() &&
2087dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        Prefix == NNS->getPrefix() &&
2088dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        NS == NNS->getAsNamespace())
2089dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
20901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2091dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2092dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
20931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2094dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::Global:
2095dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    // There is no meaningful transformation that one could perform on the
2096dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    // global scope.
2097dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return NNS;
20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2099dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::TypeSpecWithTemplate:
2100dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  case NestedNameSpecifier::TypeSpec: {
2101fbf2c945f8f8bbfe0459d45c03f9ff34bb445c81Douglas Gregor    TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
210243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
210343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            ObjectType,
210443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            FirstQualifierInScope,
210543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            Prefix);
2106d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (T.isNull())
2107d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return 0;
21081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2109dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
2110dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        Prefix == NNS->getPrefix() &&
2111dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor        T == QualType(NNS->getAsType(), 0))
2112dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      return NNS;
21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
2116edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                   T);
2117dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
2118dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2120dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  // Required to silence a GCC warning
21211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return 0;
2122dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
2123dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
2124dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
21252577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo
21262577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived>
212743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
21282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name = NameInfo.getName();
212981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  if (!Name)
21302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo();
213181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
213281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  switch (Name.getNameKind()) {
213381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::Identifier:
213481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCZeroArgSelector:
213581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCOneArgSelector:
213681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCMultiArgSelector:
213781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXOperatorName:
21383e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  case DeclarationName::CXXLiteralOperatorName:
213981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXUsingDirective:
21402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NameInfo;
21411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
214281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConstructorName:
214381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXDestructorName:
214481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConversionFunctionName: {
21452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *NewTInfo;
21462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CanQualType NewCanTy;
21472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
214843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewTInfo = getDerived().TransformType(OldTInfo);
214943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NewTInfo)
215043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall        return DeclarationNameInfo();
215143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
21522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
21532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    else {
21542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewTInfo = 0;
21552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
215643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      QualType NewT = getDerived().TransformType(Name.getCXXNameType());
21572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      if (NewT.isNull())
21582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        return DeclarationNameInfo();
21592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewCanTy = SemaRef.Context.getCanonicalType(NewT);
21602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationName NewName
21632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
21642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                           NewCanTy);
21652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NewNameInfo(NameInfo);
21662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setName(NewName);
21672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setNamedTypeInfo(NewTInfo);
21682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NewNameInfo;
216981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  }
21701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
21711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  assert(0 && "Unknown name kind.");
21732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return DeclarationNameInfo();
217481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor}
217581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
217681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived>
21771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
21783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas GregorTreeTransform<Derived>::TransformTemplateName(TemplateName Name,
217943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              QualType ObjectType,
218043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              NamedDecl *FirstQualifierInScope) {
21817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  SourceLocation Loc = getDerived().getBaseLocation();
21827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor
2183d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NestedNameSpecifier *NNS
2185d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
218643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  /*FIXME*/ SourceRange(Loc),
218743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  ObjectType,
218843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  FirstQualifierInScope);
2189d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!NNS)
2190d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return TemplateName();
21911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2192d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (TemplateDecl *Template = QTN->getTemplateDecl()) {
21931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      TemplateDecl *TransTemplate
21947c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor        = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2195d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      if (!TransTemplate)
2196d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        return TemplateName();
21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2198d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      if (!getDerived().AlwaysRebuild() &&
2199d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor          NNS == QTN->getQualifier() &&
2200d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor          TransTemplate == Template)
2201d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        return Name;
22021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2203d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2204d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                              TransTemplate);
2205d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    }
22061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2207f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // These should be getting filtered out before they make it into the AST.
220843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    llvm_unreachable("overloaded template name survived to here");
2209d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
22101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2211d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
221243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    NestedNameSpecifier *NNS = DTN->getQualifier();
221343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (NNS) {
221443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NNS = getDerived().TransformNestedNameSpecifier(NNS,
221543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  /*FIXME:*/SourceRange(Loc),
221643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ObjectType,
221743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      FirstQualifierInScope);
221843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NNS) return TemplateName();
221943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
222043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      // These apply to the scope specifier, not the template.
222143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      ObjectType = QualType();
222243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      FirstQualifierInScope = 0;
222343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    }
22241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2225d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2226dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor        NNS == DTN->getQualifier() &&
2227dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor        ObjectType.isNull())
2228d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return Name;
22291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22301efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    if (DTN->isIdentifier()) {
22311efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      // FIXME: Bad range
22321efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      SourceRange QualifierRange(getDerived().getBaseLocation());
22331efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor      return getDerived().RebuildTemplateName(NNS, QualifierRange,
22341efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                              *DTN->getIdentifier(),
223543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              ObjectType,
223643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              FirstQualifierInScope);
22371efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    }
2238c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2240ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            ObjectType);
2241d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
22421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2243d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
22441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TemplateDecl *TransTemplate
22457c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
2246d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!TransTemplate)
2247d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return TemplateName();
22481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2249d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2250d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor        TransTemplate == Template)
2251d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor      return Name;
22521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2253d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor    return TemplateName(TransTemplate);
2254d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  }
22551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2256f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // These should be getting filtered out before they reach the AST.
225743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  llvm_unreachable("overloaded function decl survived to here");
2258f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return TemplateName();
2259d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
2260d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
2261d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
2262833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc(
2263833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgument &Arg,
2264833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2265833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation Loc = getDerived().getBaseLocation();
2266670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  switch (Arg.getKind()) {
2267670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Null:
22689f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("null template argument in TreeTransform");
2269833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2270833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2271833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
2272833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg,
2273a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall               SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2274c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2275833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2276833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2277788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
2278788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2279788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    break;
2280c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2281833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
2282833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2283833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2284833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2285833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
2286670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Integral:
2287833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
2288828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2289833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2290833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
2291833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
2292833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2293833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived>
2294833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument(
2295833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgumentLoc &Input,
2296833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2297833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgument &Arg = Input.getArgument();
2298833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
2299833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
2300833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
2301833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = Input;
2302833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
23031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2304670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Type: {
2305a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *DI = Input.getTypeSourceInfo();
2306833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (DI == NULL)
2307a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall      DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2308833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2309833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    DI = getDerived().TransformType(DI);
2310833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!DI) return true;
2311833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2312833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2313833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2314670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
23151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2316670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Declaration: {
2317833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // FIXME: we should never have to transform one of these.
2318972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    DeclarationName Name;
2319972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2320972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor      Name = ND->getDeclName();
2321788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemporaryBase Rebase(*this, Input.getLocation(), Name);
23227c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2323833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!D) return true;
2324833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2325828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Expr *SourceExpr = Input.getSourceDeclExpression();
2326828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    if (SourceExpr) {
2327828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      EnterExpressionEvaluationContext Unevaluated(getSema(),
2328f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Sema::Unevaluated);
232960d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(SourceExpr);
23309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      SourceExpr = (E.isInvalid() ? 0 : E.take());
2331828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    }
2332828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
2333828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2334833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2335670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
23361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2337788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template: {
2338c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2339788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemplateName Template
2340788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      = getDerived().TransformTemplateName(Arg.getAsTemplate());
2341788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    if (Template.isNull())
2342788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      return true;
2343c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2344788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(Template),
2345788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateQualifierRange(),
2346788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateNameLoc());
2347788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return false;
2348788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  }
2349c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2350670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Expression: {
2351670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    // Template argument expressions are not potentially evaluated.
23521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EnterExpressionEvaluationContext Unevaluated(getSema(),
2353f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                 Sema::Unevaluated);
23541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2355833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Expr *InputExpr = Input.getSourceExpression();
2356833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2357833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
235860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult E
2359833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = getDerived().TransformExpr(InputExpr);
2360833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (E.isInvalid()) return true;
23619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2362833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2363670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
23641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2365670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Pack: {
2366670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2367670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    TransformedArgs.reserve(Arg.pack_size());
23681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2369670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor                                      AEnd = Arg.pack_end();
2370670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor         A != AEnd; ++A) {
23711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2372833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // FIXME: preserve source information here when we start
2373833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // caring about parameter packs.
2374833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2375828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc InputArg;
2376828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc OutputArg;
2377828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      getDerived().InventTemplateArgumentLoc(*A, InputArg);
2378828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2379833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall        return true;
2380833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2381828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TransformedArgs.push_back(OutputArg.getArgument());
2382670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    }
2383910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
2384910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    TemplateArgument *TransformedArgsPtr
2385910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2386910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2387910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor              TransformedArgsPtr);
2388910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2389910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                                  TransformedArgs.size()),
2390910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                 Input.getLocInfo());
2391833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2392670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
2393670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
23941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2395670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Work around bogus GCC warning
2396833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return true;
2397670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor}
2398670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
2399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
2400577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation
2401577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
2402577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2403577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
240443fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) {
2405577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (getDerived().AlreadyTransformed(T))
2406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T;
24071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2408a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Temporary workaround.  All of these transformations should
2409a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // eventually turn into transformations on TypeLocs.
2410a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
24114802a311f402836f1f226a3d7a87e6a3088f9704John McCall  DI->getTypeLoc().initialize(getDerived().getBaseLocation());
2412c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
241343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
24141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2415a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (!NewDI)
2416a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
24171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2418a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return NewDI->getType();
2419577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
24201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
242243fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
2423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlreadyTransformed(DI->getType()))
2424a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return DI;
24251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2426a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLocBuilder TLB;
24271bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
2428a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLoc TL = DI->getTypeLoc();
2429a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TLB.reserve(TL.getFullDataSize());
24301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
243143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, TL);
2432a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
2433a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return 0;
24341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2435a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2436577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
24371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2439a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
244043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2441a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  switch (T.getTypeLocClass()) {
2442a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
2443a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \
2444a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  case TypeLoc::CLASS: \
244543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2446a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
2447a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2448577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
24499f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("unhandled type loc!");
2450a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return QualType();
2451577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2453a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types
2454a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers
2455a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function
2456a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but
2457a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients.
24581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
24591eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
2460a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
246143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               QualifiedTypeLoc T) {
2462a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers Quals = T.getType().getLocalQualifiers();
2463a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
246443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2465a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
2466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
24671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Silently suppress qualifiers if the result type can't be qualified.
2469a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: this is the right thing for template instantiation, but
2470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // probably not for other clients.
2471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result->isFunctionType() || Result->isReferenceType())
2472a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return Result;
24731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24742865474261a608c7873b87ba4af110d17907896dJohn McCall  if (!Quals.empty()) {
24752865474261a608c7873b87ba4af110d17907896dJohn McCall    Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
24762865474261a608c7873b87ba4af110d17907896dJohn McCall    TLB.push<QualifiedTypeLoc>(Result);
24772865474261a608c7873b87ba4af110d17907896dJohn McCall    // No location information to preserve.
24782865474261a608c7873b87ba4af110d17907896dJohn McCall  }
2479a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2480a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2481a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
2482a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
248343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// \brief Transforms a type that was written in a scope specifier,
248443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// given an object type, the results of unqualified lookup, and
248543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// an already-instantiated prefix.
248643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall///
248743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// The object type is provided iff the scope specifier qualifies the
248843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// member of a dependent member-access expression.  The prefix is
248943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// provided iff the the scope specifier in which this appears has a
249043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// prefix.
249143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall///
249243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// This is private to TreeTransform.
249343fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
249443fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType
249543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
249643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
249743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
249843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *Prefix) {
249943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
250043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return T;
250143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
250243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TSI =
250343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
250443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
250543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
250643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                UnqualLookup, Prefix);
250743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (!TSI) return QualType();
250843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TSI->getType();
250943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
251043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
251143fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
251243fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *
251343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
251443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
251543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
251643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *Prefix) {
251743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: in some cases, we might be some verification to do here.
251843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (ObjectType.isNull())
251943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().TransformType(TSI);
252043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
252143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType T = TSI->getType();
252243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
252343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return TSI;
252443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
252543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeLocBuilder TLB;
252643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result;
252743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
252843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (isa<TemplateSpecializationType>(T)) {
252943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateSpecializationTypeLoc TL
253043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
253143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
253243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateName Template =
253343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
253443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         ObjectType, UnqualLookup);
253543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (Template.isNull()) return 0;
253643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
253743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived()
253843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      .TransformTemplateSpecializationType(TLB, TL, Template);
253943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else if (isa<DependentTemplateSpecializationType>(T)) {
254043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    DependentTemplateSpecializationTypeLoc TL
254143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
254243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
254343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived()
254443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
254543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else {
254643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    // Nothing special needs to be done for these.
254743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
254843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
254943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
255043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Result.isNull()) return 0;
255143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
255243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
255343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
2554a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline
2555a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2556a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TyLoc NewT = TLB.push<TyLoc>(T.getType());
2557a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewT.setNameLoc(T.getNameLoc());
2558a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return T.getType();
2559a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
2560a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2561a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
2562a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
256343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      BuiltinTypeLoc T) {
2564ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2565ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  NewT.setBuiltinLoc(T.getBuiltinLoc());
2566ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (T.needsExtraLocalData())
2567ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2568ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  return T.getType();
2569577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
2570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
25711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2572a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
257343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ComplexTypeLoc T) {
2574a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: recurse?
2575a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, T);
2576a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
25771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2578a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
2579a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
258043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      PointerTypeLoc TL) {
2581c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType PointeeType
2582c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
258392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (PointeeType.isNull())
258492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return QualType();
258592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
258692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  QualType Result = TL.getType();
2587c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (PointeeType->getAs<ObjCObjectType>()) {
258892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // A dependent pointer type 'T *' has is being transformed such
258992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // that an Objective-C class type is being replaced for 'T'. The
259092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // resulting pointer type is an ObjCObjectPointerType, not a
259192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // PointerType.
2592c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
2593c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2594c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2595c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NewT.setStarLoc(TL.getStarLoc());
259692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return Result;
259792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
259843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
259992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (getDerived().AlwaysRebuild() ||
260092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      PointeeType != TL.getPointeeLoc().getType()) {
260192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
260292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Result.isNull())
260392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      return QualType();
260492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
2605c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
260692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
260792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
2608c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Result;
2609577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
2610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
26111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
26121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
2613a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
261443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  BlockPointerTypeLoc TL) {
2615db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  QualType PointeeType
2616c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
2617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (PointeeType.isNull())
2618c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return QualType();
2619c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2620c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType Result = TL.getType();
2621c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (getDerived().AlwaysRebuild() ||
2622c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      PointeeType != TL.getPointeeLoc().getType()) {
2623c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Result = getDerived().RebuildBlockPointerType(PointeeType,
2624db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor                                                  TL.getSigilLoc());
2625db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor    if (Result.isNull())
2626db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor      return QualType();
2627db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  }
2628db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor
262939968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
2630db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
2631db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  return Result;
2632a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
26331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
263485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type.  Note that somewhat paradoxically we
263585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value
263685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type;  we only care if the type was *written* as an l-value type
263785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type.
263885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived>
263985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType
264085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
264143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ReferenceTypeLoc TL) {
264285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  const ReferenceType *T = TL.getTypePtr();
264385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
264485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // Note that this works with the pointee-as-written.
264585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
264685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (PointeeType.isNull())
264785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return QualType();
264885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
264985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType Result = TL.getType();
265085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (getDerived().AlwaysRebuild() ||
265185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      PointeeType != T->getPointeeTypeAsWritten()) {
265285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildReferenceType(PointeeType,
265385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               T->isSpelledAsLValue(),
265485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               TL.getSigilLoc());
265585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    if (Result.isNull())
265685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      return QualType();
265785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
265885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
265985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // r-value references can be rebuilt as l-value references.
266085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  ReferenceTypeLoc NewTL;
266185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (isa<LValueReferenceType>(Result))
266285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
266385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  else
266485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
266585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
266685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
266785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  return Result;
266885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall}
266985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
2670a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
2671a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
2672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
267343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 LValueReferenceTypeLoc TL) {
267443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
2675a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
26761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2677a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
2678a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
2679a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
268043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 RValueReferenceTypeLoc TL) {
268143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
2682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
26831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
26851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
2686a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
268743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   MemberPointerTypeLoc TL) {
2688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerType *T = TL.getTypePtr();
2689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (PointeeType.isNull())
2692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
26931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // TODO: preserve source information for this.
2695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ClassType
2696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformType(QualType(T->getClass(), 0));
2697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ClassType.isNull())
2698577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
26991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2700a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2701a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2702a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      PointeeType != T->getPointeeType() ||
2703a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ClassType != QualType(T->getClass(), 0)) {
270485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
270585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getStarLoc());
2706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2709577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
2712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2714577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
2715577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
27161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
27171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
2718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
271943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ConstantArrayTypeLoc TL) {
2720a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayType *T = TL.getTypePtr();
2721a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2722577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
27241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2725a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2727a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
2728a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildConstantArrayType(ElementType,
2729a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
2730a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSize(),
273185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             T->getIndexTypeCVRQualifiers(),
273285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
2733a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2734a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2735a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2736c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2737a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2738a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
2739a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
27401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2741a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = TL.getSizeExpr();
2742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Size) {
2743f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2744a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2745a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2746a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
2747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2748a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2749577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
27501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2751577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
2752577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType(
2753a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                              TypeLocBuilder &TLB,
275443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              IncompleteArrayTypeLoc TL) {
2755a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayType *T = TL.getTypePtr();
2756a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2757577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2758577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
27591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2760a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2761a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2762a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
2763a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildIncompleteArrayType(ElementType,
2764a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                     T->getSizeModifier(),
276585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                           T->getIndexTypeCVRQualifiers(),
276685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                     TL.getBracketsRange());
2767a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2768a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2769a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2770c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2771a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2772a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
2773a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
2774a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(0);
2775577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2776a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2777577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
27781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2779577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
2780a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
2781a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
278243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   VariableArrayTypeLoc TL) {
2783a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayType *T = TL.getTypePtr();
2784a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2785577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2786577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
27871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2788670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
2789f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2790670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
279160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
2792a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
2793a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
2794577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
27951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Size = SizeResult.take();
2797a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2798a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2799a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2800a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
2801a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
2802a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildVariableArrayType(ElementType,
2803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
28049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Size,
2805a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                             T->getIndexTypeCVRQualifiers(),
280685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
2807a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2808a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2809577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
2810c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2811a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2812a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
2813a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
2814a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
28151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2816a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2817577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
28181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2820a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
2821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
282243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             DependentSizedArrayTypeLoc TL) {
2823a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DependentSizedArrayType *T = TL.getTypePtr();
2824a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2825577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2826577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2828670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
2829f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
28301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
283160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
2832a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
2833a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
2834577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2836a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = static_cast<Expr*>(SizeResult.get());
2837a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2838a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2839a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2840a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
2841a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
2842a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2843a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                         T->getSizeModifier(),
28449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                         Size,
2845a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                T->getIndexTypeCVRQualifiers(),
284685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                        TL.getBracketsRange());
2847a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2848a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2849577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
2850a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else SizeResult.take();
28511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2852a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // We might have any sort of array type now, but fortunately they
2853a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // all have the same location layout.
2854a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2855a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
2856a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
2857a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
2858a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2859a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2860577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
28611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2863577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
2864a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                      TypeLocBuilder &TLB,
286543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentSizedExtVectorTypeLoc TL) {
2866a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DependentSizedExtVectorType *T = TL.getTypePtr();
2867a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2868a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: ext vector locs should be nested
2869577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
2870577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2871577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2873670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Vector sizes are not potentially evaluated contexts
2874f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
2875670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
287660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2877577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (Size.isInvalid())
2878577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
28791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2880a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2881a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2882eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      ElementType != T->getElementType() ||
2883eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      Size.get() != T->getSizeExpr()) {
2884a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
28859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                             Size.take(),
2886577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                         T->getAttributeLoc());
2887a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2888a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2889a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2890a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2891a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Result might be dependent or not.
2892a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (isa<DependentSizedExtVectorType>(Result)) {
2893a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    DependentSizedExtVectorTypeLoc NewTL
2894a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2895a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
2896a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  } else {
2897a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2898a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
2899a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2900a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2901a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2902577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
29031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2905a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
290643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     VectorTypeLoc TL) {
2907a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorType *T = TL.getTypePtr();
2908577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
2909577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2910577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
2911577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2912a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2913a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2914a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
291582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2916e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                            T->getVectorKind());
2917a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2918a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2919a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2920c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2921a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2922a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
29231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2924a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2925577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
29261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
2928a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
292943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        ExtVectorTypeLoc TL) {
2930a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorType *T = TL.getTypePtr();
2931577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
2932577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
2933577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
29341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2935a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
2936a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
2937a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
2938a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildExtVectorType(ElementType,
2939a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               T->getNumElements(),
2940a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               /*FIXME*/ SourceLocation());
2941a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
2942a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
2943a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
2944c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2945a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2946a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
29471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2948a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
2949577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
2950577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
29511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
295221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl *
295321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
295421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
295521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
295621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (!NewDI)
295721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return 0;
295821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
295921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (NewDI == OldDI)
296021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return OldParm;
296121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  else
296221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return ParmVarDecl::Create(SemaRef.Context,
296321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getDeclContext(),
296421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getLocation(),
296521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getIdentifier(),
296621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               NewDI->getType(),
296721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               NewDI,
296821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               OldParm->getStorageClass(),
296916573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor                               OldParm->getStorageClassAsWritten(),
297021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                               /* DefArg */ NULL);
297121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
297221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
297321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
297421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>::
297521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
297621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                              llvm::SmallVectorImpl<QualType> &PTypes,
297721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall                              llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2978a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoType *T = TL.getTypePtr();
29791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2980a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2981a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ParmVarDecl *OldParm = TL.getArg(i);
2982a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2983a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    QualType NewType;
2984a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ParmVarDecl *NewParm;
2985a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2986a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (OldParm) {
298721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      NewParm = getDerived().TransformFunctionTypeParam(OldParm);
298821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      if (!NewParm)
298921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
2990a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NewType = NewParm->getType();
2991a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2992a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // Deal with the possibility that we don't have a parameter
2993a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // declaration for this parameter.
2994a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    } else {
2995a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NewParm = 0;
2996a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
2997a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      QualType OldType = T->getArgType(i);
2998a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NewType = getDerived().TransformType(OldType);
2999a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      if (NewType.isNull())
300021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3001a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    }
30021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
300321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    PTypes.push_back(NewType);
300421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    PVars.push_back(NewParm);
3005577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
300721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  return false;
300821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
300921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
301021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
301121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType
301221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
301343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   FunctionProtoTypeLoc TL) {
30147e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // Transform the parameters and return type.
30157e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
30167e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // We instantiate in source order, with the return type first followed by
30177e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // the parameters, because users tend to expect this (even if they shouldn't
30187e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // rely on it!).
30197e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
3020dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // When the function has a trailing return type, we instantiate the
3021dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // parameters before the return type,  since the return type can then refer
3022dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // to the parameters themselves (via decltype, sizeof, etc.).
3023dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
302421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<QualType, 4> ParamTypes;
302521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
3026895162da2d52f4243f61081d7436de66af4503fcDouglas Gregor  FunctionProtoType *T = TL.getTypePtr();
30277e010a04fef171049291d8cb3047f118566da090Douglas Gregor
3028dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  QualType ResultType;
3029dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3030dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  if (TL.getTrailingReturn()) {
3031dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3032dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3033dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3034dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3035dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
3036dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3037dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
3038dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  else {
3039dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3040dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
3041dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3042dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3043dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3044dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
3045dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
3046dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
3047a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3048a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3049a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType() ||
3050a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3051a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionProtoType(ResultType,
3052a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.data(),
3053a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.size(),
3054a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->isVariadic(),
3055fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getTypeQuals(),
3056fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getExtInfo());
3057a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3058a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3059a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
30601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3061a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3062a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3063a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3064dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(TL.getTrailingReturn());
3065a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3066a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setArg(i, ParamDecls[i]);
3067a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3068a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3069577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
30701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3071577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3072577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType(
3073a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                 TypeLocBuilder &TLB,
307443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 FunctionNoProtoTypeLoc TL) {
3075a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoType *T = TL.getTypePtr();
3076a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3077a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (ResultType.isNull())
3078a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
3079a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3080a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3081a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3082a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType())
3083a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3084a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3085a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3086a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3087a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3088dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(false);
3089a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3090a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3091577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
30921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3093ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType
3094ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
309543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 UnresolvedUsingTypeLoc TL) {
3096ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingType *T = TL.getTypePtr();
30977c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
3098ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (!D)
3099ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return QualType();
3100ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3101ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType Result = TL.getType();
3102ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3103ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Result = getDerived().RebuildUnresolvedUsingType(D);
3104ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    if (Result.isNull())
3105ed97649e9574b9d854fa4d6109c9333ae0993554John McCall      return QualType();
3106ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3107ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3108ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // We might get an arbitrary type spec type back.  We should at
3109ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // least always get a type spec type, though.
3110ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3111ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  NewTL.setNameLoc(TL.getNameLoc());
3112ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3113ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return Result;
3114ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
3115ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3117a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
311843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypedefTypeLoc TL) {
3119a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefType *T = TL.getTypePtr();
3120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  TypedefDecl *Typedef
31217c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
31227c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           T->getDecl()));
3123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Typedef)
3124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
31251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3126a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3128a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Typedef != T->getDecl()) {
3129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildTypedefType(Typedef);
3130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
31361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3137a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3141a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
314243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypeOfExprTypeLoc TL) {
3143670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // typeof expressions are not potentially evaluated contexts
3144f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
31451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
314660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
3147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
3148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3152cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      E.get() != TL.getUnderlyingExpr()) {
31532a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
3154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3155a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3156577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
31581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
3160cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
3161cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3162cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3163a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3164a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3165577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3168a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
316943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     TypeOfTypeLoc TL) {
3170cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3171cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3172cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (!New_Under_TI)
3173577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
31741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3175a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3176cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3177cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
3178a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3179a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3180a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
31811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3182a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
3183cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
3184cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
3185cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
3186cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setUnderlyingTInfo(New_Under_TI);
3187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3188a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3192a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
319343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                       DecltypeTypeLoc TL) {
3194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeType *T = TL.getTypePtr();
3195a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3196670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // decltype expressions are not potentially evaluated contexts
3197f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
31981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
319960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3200577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
3201577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      E.get() != T->getUnderlyingExpr()) {
32062a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
3207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3209577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
3211a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
32141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3216577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3217577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3218577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3219a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
322043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     RecordTypeLoc TL) {
3221a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordType *T = TL.getTypePtr();
3222577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  RecordDecl *Record
32237c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
32247c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                          T->getDecl()));
3225577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Record)
3226577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3228a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3229a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3230a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Record != T->getDecl()) {
3231a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildRecordType(Record);
3232a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3233a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3234a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
32351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3236a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3237a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
3238a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3239a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3240577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
32411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3243a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
324443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   EnumTypeLoc TL) {
3245a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumType *T = TL.getTypePtr();
3246577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  EnumDecl *Enum
32477c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
32487c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                        T->getDecl()));
3249577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Enum)
3250577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
32511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3252a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3253a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3254a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Enum != T->getDecl()) {
3255a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildEnumType(Enum);
3256a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3257a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3258a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3259a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3260a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3261a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
32621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3263a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3264577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
32657da2431c23ef1ee8acb114e39692246e1801afc2John McCall
32663cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived>
32673cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType(
32683cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         TypeLocBuilder &TLB,
326943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         InjectedClassNameTypeLoc TL) {
32703cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
32713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                       TL.getTypePtr()->getDecl());
32723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  if (!D) return QualType();
32733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
32743cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
32753cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
32763cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  return T;
32773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
32783cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
32791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3280577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3281577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType(
3282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                TypeLocBuilder &TLB,
328343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TemplateTypeParmTypeLoc TL) {
3284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
3285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
32871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
328849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
3289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                         TypeLocBuilder &TLB,
329043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         SubstTemplateTypeParmTypeLoc TL) {
3291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
329249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
329349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
329449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived>
3295833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
329643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        TypeLocBuilder &TLB,
329743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                           TemplateSpecializationTypeLoc TL) {
329843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
3299828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
330043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TemplateName Template
330143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformTemplateName(T->getTemplateName());
330243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Template.isNull())
330343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
3304833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
330543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3306dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor}
330743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
330843fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived>
3309577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3310833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                        TypeLocBuilder &TLB,
3311833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                           TemplateSpecializationTypeLoc TL,
331243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TemplateName Template) {
3313833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
3314833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3315d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo NewTemplateArgs;
3316d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3317d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3318d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
3319d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3320d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TemplateArgumentLoc Loc;
3321d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
3322577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      return QualType();
3323d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    NewTemplateArgs.addArgument(Loc);
3324d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
33251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3326833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  // FIXME: maybe don't rebuild if all the template arguments are the same.
3327833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3328833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType Result =
3329833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getDerived().RebuildTemplateSpecializationType(Template,
3330833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                   TL.getTemplateNameLoc(),
3331d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NewTemplateArgs);
33321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3333833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  if (!Result.isNull()) {
3334833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TemplateSpecializationTypeLoc NewTL
3335833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = TLB.push<TemplateSpecializationTypeLoc>(Result);
3336833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3337833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setLAngleLoc(TL.getLAngleLoc());
3338833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setRAngleLoc(TL.getRAngleLoc());
3339833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3340833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
3341833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
33421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3343833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return Result;
3344577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3348465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
334943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ElaboratedTypeLoc TL) {
3350465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType *T = TL.getTypePtr();
3351465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3352465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  NestedNameSpecifier *NNS = 0;
3353465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // NOTE: the qualifier in an ElaboratedType is optional.
3354465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  if (T->getQualifier() != 0) {
3355465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
335643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                    TL.getQualifierRange());
3357465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (!NNS)
3358465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      return QualType();
3359465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
33601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
336143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
336243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (NamedT.isNull())
336343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
3364a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar
3365a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3366a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3367a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      NNS != T->getQualifier() ||
3368e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      NamedT != T->getNamedType()) {
336921e413fe6305a198564d436ac515497716c47844John McCall    Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
337021e413fe6305a198564d436ac515497716c47844John McCall                                                T->getKeyword(), NNS, NamedT);
3371a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3372a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3373a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3374577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3375465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3376e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setKeywordLoc(TL.getKeywordLoc());
3377e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setQualifierRange(TL.getQualifierRange());
3378a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3379a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3380577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3383075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType
3384075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3385075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                                           ParenTypeLoc TL) {
3386075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3387075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (Inner.isNull())
3388075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType();
3389075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
3390075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Result = TL.getType();
3391075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (getDerived().AlwaysRebuild() ||
3392075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      Inner != TL.getInnerLoc().getType()) {
3393075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Result = getDerived().RebuildParenType(Inner);
3394075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    if (Result.isNull())
3395075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      return QualType();
3396075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
3397075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
3398075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3399075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setLParenLoc(TL.getLParenLoc());
3400075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setRParenLoc(TL.getRParenLoc());
3401075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  return Result;
3402075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
3403075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
3404075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived>
34054714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
340643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      DependentNameTypeLoc TL) {
34074714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  DependentNameType *T = TL.getTypePtr();
3408833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3409577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  NestedNameSpecifier *NNS
3410e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
341143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TL.getQualifierRange());
3412577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!NNS)
3413577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
341533500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType Result
341633500955d731c73717af52088b7fc0e7a85681e7John McCall    = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
341733500955d731c73717af52088b7fc0e7a85681e7John McCall                                            T->getIdentifier(),
341833500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getKeywordLoc(),
341933500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getQualifierRange(),
342033500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getNameLoc());
3421a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3422a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
3423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3424e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3425e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    QualType NamedT = ElabT->getNamedType();
342633500955d731c73717af52088b7fc0e7a85681e7John McCall    TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
342733500955d731c73717af52088b7fc0e7a85681e7John McCall
3428e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3429e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
3430e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setQualifierRange(TL.getQualifierRange());
343133500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
3432e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3433e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
3434e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setQualifierRange(TL.getQualifierRange());
3435e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setNameLoc(TL.getNameLoc());
3436e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
3437a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3438577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3440577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
344133500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>::
344233500955d731c73717af52088b7fc0e7a85681e7John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
344343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL) {
344433500955d731c73717af52088b7fc0e7a85681e7John McCall  DependentTemplateSpecializationType *T = TL.getTypePtr();
344533500955d731c73717af52088b7fc0e7a85681e7John McCall
344633500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS
344733500955d731c73717af52088b7fc0e7a85681e7John McCall    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
344843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TL.getQualifierRange());
344933500955d731c73717af52088b7fc0e7a85681e7John McCall  if (!NNS)
345033500955d731c73717af52088b7fc0e7a85681e7John McCall    return QualType();
345133500955d731c73717af52088b7fc0e7a85681e7John McCall
345243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived()
345343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall           .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
345443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
345543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
345643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
345743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::
345843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
345943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL,
346043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  NestedNameSpecifier *NNS) {
346143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  DependentTemplateSpecializationType *T = TL.getTypePtr();
346243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
346333500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgumentListInfo NewTemplateArgs;
346433500955d731c73717af52088b7fc0e7a85681e7John McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
346533500955d731c73717af52088b7fc0e7a85681e7John McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
346633500955d731c73717af52088b7fc0e7a85681e7John McCall
346733500955d731c73717af52088b7fc0e7a85681e7John McCall  for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
346833500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateArgumentLoc Loc;
346933500955d731c73717af52088b7fc0e7a85681e7John McCall    if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
347033500955d731c73717af52088b7fc0e7a85681e7John McCall      return QualType();
347133500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTemplateArgs.addArgument(Loc);
347233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
347333500955d731c73717af52088b7fc0e7a85681e7John McCall
34741efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor  QualType Result
34751efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor    = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
34761efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              NNS,
34771efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                        TL.getQualifierRange(),
34781efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                            T->getIdentifier(),
34791efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              TL.getNameLoc(),
34801efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                                              NewTemplateArgs);
348133500955d731c73717af52088b7fc0e7a85681e7John McCall  if (Result.isNull())
348233500955d731c73717af52088b7fc0e7a85681e7John McCall    return QualType();
348333500955d731c73717af52088b7fc0e7a85681e7John McCall
348433500955d731c73717af52088b7fc0e7a85681e7John McCall  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
348533500955d731c73717af52088b7fc0e7a85681e7John McCall    QualType NamedT = ElabT->getNamedType();
348633500955d731c73717af52088b7fc0e7a85681e7John McCall
348733500955d731c73717af52088b7fc0e7a85681e7John McCall    // Copy information relevant to the template specialization.
348833500955d731c73717af52088b7fc0e7a85681e7John McCall    TemplateSpecializationTypeLoc NamedTL
348933500955d731c73717af52088b7fc0e7a85681e7John McCall      = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
349033500955d731c73717af52088b7fc0e7a85681e7John McCall    NamedTL.setLAngleLoc(TL.getLAngleLoc());
349133500955d731c73717af52088b7fc0e7a85681e7John McCall    NamedTL.setRAngleLoc(TL.getRAngleLoc());
349233500955d731c73717af52088b7fc0e7a85681e7John McCall    for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
349333500955d731c73717af52088b7fc0e7a85681e7John McCall      NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
349433500955d731c73717af52088b7fc0e7a85681e7John McCall
349533500955d731c73717af52088b7fc0e7a85681e7John McCall    // Copy information relevant to the elaborated type.
349633500955d731c73717af52088b7fc0e7a85681e7John McCall    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
349733500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTL.setKeywordLoc(TL.getKeywordLoc());
349833500955d731c73717af52088b7fc0e7a85681e7John McCall    NewTL.setQualifierRange(TL.getQualifierRange());
349933500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
3500e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor    TypeLoc NewTL(Result, TL.getOpaqueData());
3501e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor    TLB.pushFullCopy(NewTL);
350233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
350333500955d731c73717af52088b7fc0e7a85681e7John McCall  return Result;
350433500955d731c73717af52088b7fc0e7a85681e7John McCall}
350533500955d731c73717af52088b7fc0e7a85681e7John McCall
350633500955d731c73717af52088b7fc0e7a85681e7John McCalltemplate<typename Derived>
3507a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3508a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
350943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ObjCInterfaceTypeLoc TL) {
3510ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCInterfaceType is never dependent.
3511c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
3512c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return TL.getType();
3513c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3514c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3515c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived>
3516c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType
3517c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
351843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjCObjectTypeLoc TL) {
3519c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // ObjCObjectType is never dependent.
3520c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
3521ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
3522577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3525a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3526a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
352743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ObjCObjectPointerTypeLoc TL) {
3528ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCObjectPointerType is never dependent.
3529c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
3530ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
353124fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}
353224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis
3533577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
353443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation
353543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
353643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
353760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
35381eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
35393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
354043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
354143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
354243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
354360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
354443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
354543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().TransformCompoundStmt(S, false);
354643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
354743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
354843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
354960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
35501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
355143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              bool IsStmtExpr) {
35527114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  bool SubStmtInvalid = false;
355343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool SubStmtChanged = false;
3554ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Statements(getSema());
355543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
355643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       B != BEnd; ++B) {
355760d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Result = getDerived().TransformStmt(*B);
35587114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    if (Result.isInvalid()) {
35597114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Immediately fail if this was a DeclStmt, since it's very
35607114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // likely that this will cause problems for future statements.
35617114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      if (isa<DeclStmt>(*B))
35627114cbab7eb6e8b714eb22f014327daf2c741c08John McCall        return StmtError();
35637114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
35647114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Otherwise, just keep processing substatements and fail later.
35657114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      SubStmtInvalid = true;
35667114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      continue;
35677114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
35681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
356943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    SubStmtChanged = SubStmtChanged || Result.get() != *B;
357043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Statements.push_back(Result.takeAs<Stmt>());
357143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
35721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35737114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  if (SubStmtInvalid)
35747114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    return StmtError();
35757114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
357643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
357743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !SubStmtChanged)
35783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
357943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
358043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
358143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          move_arg(Statements),
358243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          S->getRBracLoc(),
358343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          IsStmtExpr);
358443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
35851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
358643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
358760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
35881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
358960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS, RHS;
3590264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  {
3591264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // The case value expressions are not potentially evaluated.
3592f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
35931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3594264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the left-hand case value.
3595264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    LHS = getDerived().TransformExpr(S->getLHS());
3596264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (LHS.isInvalid())
3597f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
35981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3599264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the right-hand case value (for the GNU case-range extension).
3600264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    RHS = getDerived().TransformExpr(S->getRHS());
3601264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (RHS.isInvalid())
3602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3603264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  }
36041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
360543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Build the case statement.
360643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Case statements are always rebuilt so that they will attached to their
360743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transformed switch statement.
360860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
36099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       LHS.get(),
361043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getEllipsisLoc(),
36119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       RHS.get(),
361243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getColonLoc());
361343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Case.isInvalid())
3614f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
361643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the case
361760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
361843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
3619f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
362143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Attach the body to the case statement
36229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
362343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
362443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
362543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
362660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
36271eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
362843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the default case
362960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
363043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
3631f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
363343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Default statements are always rebuilt
363443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
36359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubStmt.get());
363643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
36371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
363843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
363960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
36401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
364160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
364243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
3643f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
364543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // FIXME: Pass the real colon location in.
364643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
364743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
36481a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis                                       SubStmt.get(), S->HasUnusedAttribute());
364943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
36501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
365143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
365260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
36531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
365443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
365560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
36568cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  VarDecl *ConditionVar = 0;
36578cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  if (S->getConditionVariable()) {
3658c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
36598cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor      = cast_or_null<VarDecl>(
3660aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
3661aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
3662aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
36638cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    if (!ConditionVar)
3664f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
366599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
36668cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
3667c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
366899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
3669f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3670eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
3671eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor    // Convert the condition to a boolean value.
3672afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
367360d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult CondE = getSema().ActOnBooleanCondition(0,
3674afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor                                                               S->getIfLoc(),
36759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                               Cond.get());
3676afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
3677f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
3678eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
36799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
3680afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
368199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
3682c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
36839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
36849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3685f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3686eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
368743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "then" branch.
368860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Then = getDerived().TransformStmt(S->getThen());
368943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Then.isInvalid())
3690f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
369243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "else" branch.
369360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Else = getDerived().TransformStmt(S->getElse());
369443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Else.isInvalid())
3695f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
36961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
369743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
36989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
369999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
370043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Then.get() == S->getThen() &&
370143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Else.get() == S->getElse())
37023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
37031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3704eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
370544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                    Then.get(),
37069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    S->getElseLoc(), Else.get());
370743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
370843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
370943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
371060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
37111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
371243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition.
371360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
3714d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  VarDecl *ConditionVar = 0;
3715d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  if (S->getConditionVariable()) {
3716c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
3717d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor      = cast_or_null<VarDecl>(
3718aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
3719aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
3720aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
3721d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    if (!ConditionVar)
3722f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
372399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
3724d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
3725c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
372699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
3727f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
372899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
37291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
373043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Rebuild the switch statement.
373160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Switch
37329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
3733586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                          ConditionVar);
373443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Switch.isInvalid())
3735f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
37361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
373743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body of the switch statement.
373860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
373943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
3740f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
37411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
374243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Complete the switch statement.
37439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
37449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Body.get());
374543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
37461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
374743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
374860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
37491eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
375043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
375160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
37525656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  VarDecl *ConditionVar = 0;
37535656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  if (S->getConditionVariable()) {
3754c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
37555656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      = cast_or_null<VarDecl>(
3756aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
3757aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
3758aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
37595656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    if (!ConditionVar)
3760f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
376199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
37625656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
3763c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
376499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
3765f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3766afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
3767afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
3768afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
376960d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult CondE = getSema().ActOnBooleanCondition(0,
3770eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor                                                             S->getWhileLoc(),
37719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                               Cond.get());
3772afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
3773f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
37749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE;
3775afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
377699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
37771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
37799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3780f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3781eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
378243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
378360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
378443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
3785f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
37861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
378743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
37889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
378999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
379043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
37919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(S);
37921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3793eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
37949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       ConditionVar, Body.get());
379543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
37961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
379743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
379860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
379943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
380043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
380160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
380243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
3803f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
38041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3805eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  // Transform the condition
380660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(S->getCond());
3807eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  if (Cond.isInvalid())
3808f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3809eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
381043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
381143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Cond.get() == S->getCond() &&
381243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
38133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
38141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
38169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    /*FIXME:*/S->getWhileLoc(), Cond.get(),
381743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    S->getRParenLoc());
381843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
38191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
382043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
382160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
38221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) {
382343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the initialization statement
382460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Init = getDerived().TransformStmt(S->getInit());
382543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Init.isInvalid())
3826f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
38271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
382843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
382960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
383099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  VarDecl *ConditionVar = 0;
383199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  if (S->getConditionVariable()) {
3832c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
383399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      = cast_or_null<VarDecl>(
3834aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
3835aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
3836aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
383799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (!ConditionVar)
3838f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
383999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
384099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
3841c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
384299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
3843f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3844afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
3845afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
3846afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
384760d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult CondE = getSema().ActOnBooleanCondition(0,
3848afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor                                                               S->getForLoc(),
38499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                               Cond.get());
3850afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
3851f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
3852afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
38539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
3854afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
385599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
38561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
38589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
3859f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3860eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
386143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the increment
386260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Inc = getDerived().TransformExpr(S->getInc());
386343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Inc.isInvalid())
3864f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
38651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
38679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (S->getInc() && !FullInc.get())
3868f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
3869eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
387043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
387160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
387243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
3873f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
38741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
387543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
387643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Init.get() == S->getInit() &&
38779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
387843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Inc.get() == S->getInc() &&
387943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
38803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
38811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
388243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
38839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Init.get(), FullCond, ConditionVar,
38849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     FullInc, S->getRParenLoc(), Body.get());
388543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
388643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
388743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
388860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
38891eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
389043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Goto statements must always be rebuilt, to resolve the label.
38911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
389243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getLabel());
389343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
389443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
389543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
389660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
38971eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
389860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Target = getDerived().TransformExpr(S->getTarget());
389943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Target.isInvalid())
3900f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
39011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
390243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
390343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Target.get() == S->getTarget())
39043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
390543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
390643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
39079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Target.get());
390843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
390943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
391043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
391160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
39133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
391443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
39151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
391643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
391760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
39193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
392043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
39211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
392243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
392360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
392560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = getDerived().TransformExpr(S->getRetValue());
392643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Result.isInvalid())
3927f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
392843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
39291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: We always rebuild the return statement because there is no way
393043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // to tell whether the return type of the function has changed.
39319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
393243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
39331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
393443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
393560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
393743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool DeclChanged = false;
393843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  llvm::SmallVector<Decl *, 4> Decls;
393943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
394043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       D != DEnd; ++D) {
3941aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor    Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3942aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                         *D);
394343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (!Transformed)
3944f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
39451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
394643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Transformed != *D)
394743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      DeclChanged = true;
39481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
394943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Decls.push_back(Transformed);
395043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
39511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
395243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() && !DeclChanged)
39533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
39541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
395643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getStartLoc(), S->getEndLoc());
395743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
39581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
395943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
396060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
39611eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
396243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  assert(false && "SwitchCase is abstract and cannot be transformed");
39633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
396443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
396543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
396643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
396760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
396843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3969c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3970ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Constraints(getSema());
3971ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Exprs(getSema());
3972ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson  llvm::SmallVector<IdentifierInfo *, 4> Names;
3973a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson
397460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AsmString;
3975ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Clobbers(getSema());
3976703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
3977703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  bool ExprsChanged = false;
3978c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3979703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the outputs.
3980703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
3981ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getOutputIdentifier(I));
3982c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3983703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
39843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getOutputConstraintLiteral(I));
3985c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3986703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the output expr.
3987703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *OutputExpr = S->getOutputExpr(I);
398860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(OutputExpr);
3989703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
3990f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
3991c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3992703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != OutputExpr;
3993c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
39949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
3995703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
3996c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3997703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the inputs.
3998703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
3999ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getInputIdentifier(I));
4000c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4001703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
40023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getInputConstraintLiteral(I));
4003c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4004703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the input expr.
4005703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *InputExpr = S->getInputExpr(I);
400660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(InputExpr);
4007703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
4008f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4009c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4010703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != InputExpr;
4011c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
40129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
4013703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
4014c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4015703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
40163fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4017703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4018703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the clobbers.
4019703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
40203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Clobbers.push_back(S->getClobber(I));
4021703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4022703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // No need to transform the asm string literal.
4023703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  AsmString = SemaRef.Owned(S->getAsmString());
4024703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
4025703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4026703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isSimple(),
4027703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isVolatile(),
4028703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumOutputs(),
4029703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumInputs(),
4030a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson                                     Names.data(),
4031703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Constraints),
4032703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Exprs),
40339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     AsmString.get(),
4034703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Clobbers),
4035703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getRParenLoc(),
4036703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isMSAsm());
403743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
403843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
403943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
404043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
404160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
40421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
40434dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body of the @try.
404460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
40454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (TryBody.isInvalid())
4046f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4047c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
40488f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  // Transform the @catch statements (if present).
40498f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  bool AnyCatchChanged = false;
4050ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> CatchStmts(SemaRef);
40518f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
405260d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
40534dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Catch.isInvalid())
4054f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
40558f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    if (Catch.get() != S->getCatchStmt(I))
40568f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      AnyCatchChanged = true;
40578f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    CatchStmts.push_back(Catch.release());
40584dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
4059c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
40604dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the @finally statement (if present).
406160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Finally;
40624dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (S->getFinallyStmt()) {
40634dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    Finally = getDerived().TransformStmt(S->getFinallyStmt());
40644dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Finally.isInvalid())
4065f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
40664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
40674dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
40684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
40694dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
40704dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      TryBody.get() == S->getTryBody() &&
40718f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      !AnyCatchChanged &&
40724dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Finally.get() == S->getFinallyStmt())
40733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4074c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
40754dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
40769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
40779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           move_arg(CatchStmts), Finally.get());
407843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
40791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
408043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
408160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
40821eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
4083be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  // Transform the @catch parameter, if there is one.
4084be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *Var = 0;
4085be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (VarDecl *FromVar = S->getCatchParamDecl()) {
4086be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    TypeSourceInfo *TSInfo = 0;
4087be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (FromVar->getTypeSourceInfo()) {
4088be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4089be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (!TSInfo)
4090f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4091be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
4092c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4093be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    QualType T;
4094be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (TSInfo)
4095be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = TSInfo->getType();
4096be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    else {
4097be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = getDerived().TransformType(FromVar->getType());
4098be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (T.isNull())
4099f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
4100be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
4101c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4102be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4103be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (!Var)
4104f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4105be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
4106c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
410760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
4108be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (Body.isInvalid())
4109f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4110c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4111c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
4112be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                             S->getRParenLoc(),
41139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Var, Body.get());
411443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
41151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
411643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
411760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
41181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
41194dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body.
412060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
41214dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (Body.isInvalid())
4122f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4123c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
41244dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
41254dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
41264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Body.get() == S->getFinallyBody())
41273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
41284dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
41294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
41304dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
41319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                               Body.get());
413243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
41331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
413443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
413560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
41361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
413760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand;
4138d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (S->getThrowExpr()) {
4139d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    Operand = getDerived().TransformExpr(S->getThrowExpr());
4140d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    if (Operand.isInvalid())
4141f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4142d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
4143c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4144d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4145d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor      Operand.get() == S->getThrowExpr())
41463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return getSema().Owned(S);
4147c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
41489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
414943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
41501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
415143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
415260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
415343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
41541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCAtSynchronizedStmt *S) {
41558fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the object we are locking.
415660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
41578fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Object.isInvalid())
4158f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
41608fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the body.
416160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
41628fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Body.isInvalid())
4163f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4164c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
41658fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // If nothing change, just retain the current statement.
41668fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
41678fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Object.get() == S->getSynchExpr() &&
41688fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Body.get() == S->getSynchBody())
41693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
41708fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor
41718fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Build a new statement.
41728fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
41739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    Object.get(), Body.get());
417443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
417543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
417643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
417760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
417843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt(
41791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCForCollectionStmt *S) {
4180c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the element statement.
418160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Element = getDerived().TransformStmt(S->getElement());
4182c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Element.isInvalid())
4183f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4184c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4185c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the collection expression.
418660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
4187c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Collection.isInvalid())
4188f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4189c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4190c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the body.
419160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
4192c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Body.isInvalid())
4193f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
4194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4195c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // If nothing changed, just retain this statement.
4196c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
4197c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Element.get() == S->getElement() &&
4198c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Collection.get() == S->getCollection() &&
4199c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Body.get() == S->getBody())
42003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
4201c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4202c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Build a new statement.
4203c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4204c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   /*FIXME:*/S->getForLoc(),
42059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Element.get(),
42069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Collection.get(),
4207c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   S->getRParenLoc(),
42089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Body.get());
420943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
421043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
421143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
421243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
421360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
421443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
421543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the exception declaration, if any.
421643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  VarDecl *Var = 0;
421743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (S->getExceptionDecl()) {
421843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    VarDecl *ExceptionDecl = S->getExceptionDecl();
421983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    TypeSourceInfo *T = getDerived().TransformType(
422083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getTypeSourceInfo());
422183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    if (!T)
4222f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
42231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
422483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
422543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                            ExceptionDecl->getIdentifier(),
422683cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getLocation());
4227ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor    if (!Var || Var->isInvalidDecl())
4228f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
422943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
42301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
423143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the actual exception handler.
423260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4233ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor  if (Handler.isInvalid())
4234f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
42351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
423643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
423743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !Var &&
423843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Handler.get() == S->getHandlerBlock())
42393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
424043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
424143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
424243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          Var,
42439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Handler.get());
424443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
42451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
424643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
424760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
424843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
424943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the try block itself.
425060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBlock
425143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    = getDerived().TransformCompoundStmt(S->getTryBlock());
425243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (TryBlock.isInvalid())
4253f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
42541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
425543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the handlers.
425643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool HandlerChanged = false;
4257ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Handlers(SemaRef);
425843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
425960d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Handler
426043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      = getDerived().TransformCXXCatchStmt(S->getHandler(I));
426143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Handler.isInvalid())
4262f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
42631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
426443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
426543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Handlers.push_back(Handler.takeAs<Stmt>());
426643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
42671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
426843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
426943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      TryBlock.get() == S->getTryBlock() &&
427043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !HandlerChanged)
42713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
427243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
42739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
42741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        move_arg(Handlers));
427543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
42761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
427743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
4278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation
4279577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
42801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
428160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4282454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
42833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
42841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
42851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
428760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4288454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
4289a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *Qualifier = 0;
4290a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (E->getQualifier()) {
4291a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4292edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                       E->getQualifierRange());
4293a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!Qualifier)
4294f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
4295a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
4296dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
4297dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *ND
42987c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
42997c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getDecl()));
4300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!ND)
4301f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
43021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4303ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  DeclarationNameInfo NameInfo = E->getNameInfo();
4304ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  if (NameInfo.getName()) {
4305ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4306ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    if (!NameInfo.getName())
4307f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
4308ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  }
43092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
43102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!getDerived().AlwaysRebuild() &&
4311a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      Qualifier == E->getQualifier() &&
4312a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ND == E->getDecl() &&
43132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NameInfo.getName() == E->getDecl()->getDeclName() &&
4314096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
43151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4316dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // Mark it referenced in the new context regardless.
4317dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: this is a bit instantiation-specific.
4318dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4319a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
43203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
4321a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
4322dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
4323dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4324096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
4325dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TemplateArgs = &TransArgs;
4326dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
4327dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
4328dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4329dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall      TemplateArgumentLoc Loc;
4330dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall      if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4331f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
4332dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall      TransArgs.addArgument(Loc);
4333dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    }
4334dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
4335dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
4336a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
43372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, TemplateArgs);
4338577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
434160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4342454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
43433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4344577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
434760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4348454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
43493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
435360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4354454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
43553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
435960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4360454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
43613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
436560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4366454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
43673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
437160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4372454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
437360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
4375f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
43761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
43783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
43791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
4381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       E->getRParen());
4382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
4383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
43841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
438560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4386454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
438760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4388b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
4389f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
43901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
43923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
43931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4394b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getOpcode(),
43969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get());
4397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
43981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
440060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
44018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
44028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform the type.
44038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
44048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!Type)
4405f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
4406c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform all of the components into components similar to what the
44088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // parser uses.
4409c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // FIXME: It would be slightly more efficient in the non-dependent case to
4410c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // just map FieldDecls, rather than requiring the rebuilder to look for
4411c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // the fields again. However, __builtin_offsetof is rare enough in
44128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // template code that we don't care.
44138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool ExprChanged = false;
4414f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::OffsetOfComponent Component;
44158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef OffsetOfExpr::OffsetOfNode Node;
44168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  llvm::SmallVector<Component, 4> Components;
44178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
44188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const Node &ON = E->getComponent(I);
44198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Component Comp;
442072be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor    Comp.isBrackets = true;
44218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Comp.LocStart = ON.getRange().getBegin();
44228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Comp.LocEnd = ON.getRange().getEnd();
44238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    switch (ON.getKind()) {
44248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Array: {
44258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
442660d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(FromIndex);
44278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (Index.isInvalid())
4428f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
4429c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      ExprChanged = ExprChanged || Index.get() != FromIndex;
44318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = true;
44329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Comp.U.E = Index.get();
44338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
44348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
4435c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Field:
44378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Identifier:
44388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = false;
44398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.U.IdentInfo = ON.getFieldName();
444029d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor      if (!Comp.U.IdentInfo)
444129d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor        continue;
4442c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
4444c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4445cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    case Node::Base:
4446cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      // Will be recomputed during the rebuild.
4447cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      continue;
44488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
4449c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Components.push_back(Comp);
44518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
4452c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // If nothing changed, retain the existing expression.
44548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
44558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Type == E->getTypeSourceInfo() &&
44568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      !ExprChanged)
44573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
4458c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
44598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Build a new offsetof expression.
44608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
44618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          Components.data(), Components.size(),
44628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          E->getRParenLoc());
44637cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}
44647cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
44657cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived>
44667cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult
44677cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
44687cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  assert(getDerived().AlreadyTransformed(E->getType()) &&
44697cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall         "opaque value expression requires transformation");
44707cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  return SemaRef.Owned(E);
44718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
44728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
44738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived>
447460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4475454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
4476b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isArgumentType()) {
4477a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *OldT = E->getArgumentTypeInfo();
44785557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor
4479a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *NewT = getDerived().TransformType(OldT);
44805ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!NewT)
4481f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
44821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44835ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!getDerived().AlwaysRebuild() && OldT == NewT)
44843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
44851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44865ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
44871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                             E->isSizeOf(),
4488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getSourceRange());
4489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
44901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
449160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr;
44921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  {
4493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // C++0x [expr.sizeof]p1:
4494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   The operand is either an expression, which is an unevaluated operand
4495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   [...]
4496f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
44971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
4500f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
45011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
45033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
4504b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
45051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
4507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isSizeOf(),
4508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getSourceRange());
4509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
45101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
451260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4513454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
451460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
4516f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
45171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
451860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
4520f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
45211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
4525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
45263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
45271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
4529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           /*FIXME:*/E->getLHS()->getLocStart(),
45309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                RHS.get(),
4531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getRBracketLoc());
4532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
45331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
453560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4536454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
4537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the callee.
453860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
4539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
4540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
4541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform arguments.
4543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgChanged = false;
4544ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
4545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
454660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Arg.isInvalid())
4548f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
45491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
45519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Args.push_back(Arg.get());
4552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
45531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
4556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgChanged)
45573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
45581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Wrong source location information for the '('.
45601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLParenLoc
4561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = ((Expr *)Callee.get())->getSourceRange().getBegin();
45629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
4563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      move_arg(Args),
4564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
4565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
45661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
456860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4569454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
457060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
4571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
4572f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
45731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
457483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  NestedNameSpecifier *Qualifier = 0;
457583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (E->hasQualifier()) {
45761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Qualifier
457783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4578edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  E->getQualifierRange());
4579c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (Qualifier == 0)
4580f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
458183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
45821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4583f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *Member
45847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
45857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getMemberDecl()));
4586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Member)
4587f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
45881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45896bb8017bb9e828d118e15e59d71c66bba323c364John McCall  NamedDecl *FoundDecl = E->getFoundDecl();
45906bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (FoundDecl == E->getMemberDecl()) {
45916bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = Member;
45926bb8017bb9e828d118e15e59d71c66bba323c364John McCall  } else {
45936bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = cast_or_null<NamedDecl>(
45946bb8017bb9e828d118e15e59d71c66bba323c364John McCall                   getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
45956bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!FoundDecl)
4596f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
45976bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
45986bb8017bb9e828d118e15e59d71c66bba323c364John McCall
4599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase() &&
460183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      Qualifier == E->getQualifier() &&
46028a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor      Member == E->getMemberDecl() &&
46036bb8017bb9e828d118e15e59d71c66bba323c364John McCall      FoundDecl == E->getFoundDecl() &&
4604096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
4605c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
46061f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // Mark it referenced in the new context regardless.
46071f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // FIXME: this is a bit instantiation-specific.
46081f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
46093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
46101f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson  }
4611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4612d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs;
4613096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
4614d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
4615d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
46168a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor    for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4617d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      TemplateArgumentLoc Loc;
4618d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4619f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
4620d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      TransArgs.addArgument(Loc);
46218a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor    }
46228a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor  }
4623c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bogus source location for the operator
4625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeOperatorLoc
4626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4628c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
4629c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
4630c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
4631c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
4632c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
4633c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
46349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
4635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isArrow(),
463683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                        Qualifier,
463783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                        E->getQualifierRange(),
46382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                        E->getMemberNameInfo(),
46398a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor                                        Member,
46406bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        FoundDecl,
4641096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                        (E->hasExplicitTemplateArgs()
4642d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                           ? &TransArgs : 0),
4643c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                        FirstQualifierInScope);
4644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
46451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
464760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4648454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
464960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
4651f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
465360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
4655f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
4659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
46603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
46611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
46639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            LHS.get(), RHS.get());
4664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
4665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
46661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
466760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator(
4669454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CompoundAssignOperator *E) {
4670454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformBinaryOperator(E);
4671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
46721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
467460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4675454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
467660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
4677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
4678f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
468060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
4682f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
468460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
4686f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
46871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
4690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
4691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
46923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
46931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildConditionalOperator(Cond.get(),
469547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getQuestionLoc(),
46969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 LHS.get(),
469747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getColonLoc(),
46989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 RHS.get());
4699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
470260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4703454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
4704a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // Implicit casts are eliminated during transformation, since they
4705a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // will be recomputed by semantic analysis after transformation.
47066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return getDerived().TransformExpr(E->getSubExprAsWritten());
4707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
471060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4711454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
4712ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
4713ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
4714ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
4715ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
471660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
47176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
4718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
4719f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4722ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
4723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
47243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
47251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47269d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4727ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                            Type,
4728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc(),
47299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            SubExpr.get());
4730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
473360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4734454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
473542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *OldT = E->getTypeSourceInfo();
473642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
473742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  if (!NewT)
4738f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
474060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
4741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
4742f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
474542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      OldT == NewT &&
4746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInitializer())
47473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
4748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
47491d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // Note: the expression type doesn't necessarily match the
47501d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // type-as-written, but that's okay, because it should always be
47511d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // derivable from the initializer.
47521d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
475342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
4754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   /*FIXME:*/E->getInitializer()->getLocEnd(),
47559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Init.get());
4756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
475960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4760454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
476160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
4762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
4763f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
47641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase())
47673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
47681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bad source location
47701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeOperatorLoc
4771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
47729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
4773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessorLoc(),
4774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessor());
4775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
477860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4779454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
4780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool InitChanged = false;
47811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4782ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
4783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
478460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Init = getDerived().TransformExpr(E->getInit(I));
4785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Init.isInvalid())
4786f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
47871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    InitChanged = InitChanged || Init.get() != E->getInit(I);
47899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Inits.push_back(Init.get());
4790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
47911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && !InitChanged)
47933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
47941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
4796e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                      E->getRBraceLoc(), E->getType());
4797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
47981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
480060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4801454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
4802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Designation Desig;
48031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
480443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the initializer value
480560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInit());
4806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
4807f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
48081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
480943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the designators.
4810ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
4811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ExprChanged = false;
4812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             DEnd = E->designators_end();
4814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       D != DEnd; ++D) {
4815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isFieldDesignator()) {
4816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Desig.AddDesignator(Designator::getField(D->getFieldName(),
4817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getDotLoc(),
4818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getFieldLoc()));
4819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
4820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
48211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isArrayDesignator()) {
482360d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Index.isInvalid())
4825f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
48261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Desig.AddDesignator(Designator::getArray(Index.get(),
4828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getLBracketLoc()));
48291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArrayExprs.push_back(Index.release());
4832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
4833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
48341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(D->isArrayRangeDesignator() && "New kind of designator?");
483660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Start
4837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Start.isInvalid())
4839f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
48401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
484160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (End.isInvalid())
4843f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
48441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Desig.AddDesignator(Designator::getArrayRange(Start.get(),
4846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  End.get(),
4847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getLBracketLoc(),
4848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getEllipsisLoc()));
48491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      End.get() != E->getArrayRangeEnd(*D);
48521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(Start.release());
4854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(End.release());
4855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
48561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInit() &&
4859b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ExprChanged)
48603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
48611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getEqualOrColonLoc(),
48649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                E->usesGNUSyntax(), Init.get());
4865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
48661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
486860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr(
4870454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     ImplicitValueInitExpr *E) {
48715557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4872c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
48735557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // FIXME: Will we ever have proper type location here? Will we actually
48745557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // need to transform the type?
4875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
4876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
4877f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
48781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4879b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4880b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType())
48813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
48821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildImplicitValueInitExpr(T);
4884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
48851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
488760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4888454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
48899bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
48909bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo)
4891f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
48921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
489360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
4895f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
48961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
48982cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      TInfo == E->getWrittenTypeInfo() &&
4899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
49003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
49011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
49032cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                       TInfo, E->getRParenLoc());
4904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
4905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
490760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4908454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
4909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
4910ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
4911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
491260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Init.isInvalid())
4914f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
49151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
49179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Inits.push_back(Init.get());
4918b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
49191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           move_arg(Inits),
4922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getRParenLoc());
4923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression.
4926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
4927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always
4928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to
4929b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis.
4930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
493160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4932454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
4933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLabel());
4935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
493860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4939454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
494060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt
4941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubStmt.isInvalid())
4943f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubStmt.get() == E->getSubStmt())
49473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
49481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
49509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      SubStmt.get(),
4951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
4952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
495560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4956454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
495760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
4958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
4959f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
4962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
4963f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
4966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
4967f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
49681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
4970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
4971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
4972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
49733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
49741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4975b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
49769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Cond.get(), LHS.get(), RHS.get(),
4977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->getRParenLoc());
4978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
49791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
498160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4982454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
49833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
4984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
4985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
4986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
498760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
4988454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
4989668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  switch (E->getOperator()) {
4990668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_New:
4991668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Delete:
4992668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_New:
4993668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_Delete:
4994668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4995f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
4996c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4997668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Call: {
4998668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // This is a call to an object's operator().
4999668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5000668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5001668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the object itself.
500260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Object = getDerived().TransformExpr(E->getArg(0));
5003668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    if (Object.isInvalid())
5004f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5005668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5006668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // FIXME: Poor location information
5007668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    SourceLocation FakeLParenLoc
5008668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      = SemaRef.PP.getLocForEndOfToken(
5009668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                              static_cast<Expr *>(Object.get())->getLocEnd());
5010668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5011668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the call arguments.
5012ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> Args(SemaRef);
5013668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
50146eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      if (getDerived().DropCallArgument(E->getArg(I)))
50156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor        break;
5016c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
501760d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5018668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      if (Arg.isInvalid())
5019f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
5020668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5021668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      Args.push_back(Arg.release());
5022668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    }
5023668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
50249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
5025668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        move_arg(Args),
5026668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        E->getLocEnd());
5027668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
5028668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5029668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5030668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_##Name:
5031668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5032668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def"
5033668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Subscript:
5034668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Handled below.
5035668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    break;
5036668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5037668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Conditional:
5038668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("conditional operator is not actually overloadable");
5039f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5040668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
5041668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_None:
5042668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case NUM_OVERLOADED_OPERATORS:
5043668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("not an overloaded operator?");
5044f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5045668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
5046668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
504760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
5049f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
50501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
505160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult First = getDerived().TransformExpr(E->getArg(0));
5052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (First.isInvalid())
5053f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5054b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
505560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Second;
5056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->getNumArgs() == 2) {
5057b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Second = getDerived().TransformExpr(E->getArg(1));
5058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Second.isInvalid())
5059f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5060b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
50611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5062b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5063b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
5064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      First.get() == E->getArg(0) &&
50651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
50663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
50671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5068b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 E->getOperatorLoc(),
50709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Callee.get(),
50719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 First.get(),
50729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Second.get());
5073b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
50741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5075b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
507660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5077454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5078454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCallExpr(E);
5079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
50801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5081b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
508260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5083454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
5084ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5085ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
5086ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
5087ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
508860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
50896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
5090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5091f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
50921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5094ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
5095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
50963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
50971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Poor source location information here.
50991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLAngleLoc
5100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRParenLoc
5103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(
5104b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  E->getSubExpr()->getSourceRange().getEnd());
5105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
51061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              E->getStmtClass(),
5107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeLAngleLoc,
5108ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                              Type,
5109b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
5110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
51119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              SubExpr.get(),
5112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRParenLoc);
5113b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5115b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
511660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5117454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5118454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5119b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
512260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5123454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5124454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
512860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5129b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr(
5130454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CXXReinterpretCastExpr *E) {
5131454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
513560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5136454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5137454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
5138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
514160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr(
5143454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXFunctionalCastExpr *E) {
5144ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5145ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
5146ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
51471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
514860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
51496eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
5150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5151f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
51521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5154ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
5155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
51563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
51571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5158ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  return getDerived().RebuildCXXFunctionalCastExpr(Type,
5159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      /*FIXME:*/E->getSubExpr()->getLocStart(),
51609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr.get(),
5161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   E->getRParenLoc());
5162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
51631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
516560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5166454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
5167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isTypeOperand()) {
516857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    TypeSourceInfo *TInfo
516957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      = getDerived().TransformType(E->getTypeOperandSourceInfo());
517057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    if (!TInfo)
5171f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
51721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
517457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        TInfo == E->getTypeOperandSourceInfo())
51753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
51761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
517757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return getDerived().RebuildCXXTypeidExpr(E->getType(),
517857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             E->getLocStart(),
517957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             TInfo,
5180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getLocEnd());
5181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
51821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // We don't know whether the expression is potentially evaluated until
5184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // after we perform semantic analysis, so the expression is potentially
5185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // potentially evaluated.
51861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  EnterExpressionEvaluationContext Unevaluated(SemaRef,
5187f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      Sema::PotentiallyPotentiallyEvaluated);
51881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
518960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5191f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
51921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5193b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getExprOperand())
51953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
51961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
519757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  return getDerived().RebuildCXXTypeidExpr(E->getType(),
519857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                           E->getLocStart(),
51999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get(),
5200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLocEnd());
5201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
520460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
520501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
520601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (E->isTypeOperand()) {
520701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    TypeSourceInfo *TInfo
520801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      = getDerived().TransformType(E->getTypeOperandSourceInfo());
520901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!TInfo)
521001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      return ExprError();
521101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
521201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!getDerived().AlwaysRebuild() &&
521301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet        TInfo == E->getTypeOperandSourceInfo())
52143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
521501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
521601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getDerived().RebuildCXXTypeidExpr(E->getType(),
521701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocStart(),
521801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             TInfo,
521901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocEnd());
522001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
522101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
522201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // We don't know whether the expression is potentially evaluated until
522301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // after we perform semantic analysis, so the expression is potentially
522401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // potentially evaluated.
522501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
522601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
522701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
522801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (SubExpr.isInvalid())
522901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return ExprError();
523001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
523101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (!getDerived().AlwaysRebuild() &&
523201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      SubExpr.get() == E->getExprOperand())
52333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
523401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
523501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  return getDerived().RebuildCXXUuidofExpr(E->getType(),
523601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocStart(),
523701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           SubExpr.get(),
523801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocEnd());
523901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}
524001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
524101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived>
524201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult
5243454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
52443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5245b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
524860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
5250454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXNullPtrLiteralExpr *E) {
52513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5252b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
525560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5256454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
5257ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  DeclContext *DC = getSema().getFunctionLevelDeclContext();
5258ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5259ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  QualType T = MD->getThisType(getSema().Context);
52601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5261ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!getDerived().AlwaysRebuild() && T == E->getType())
52623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
52631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5264828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
5265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
526860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5269454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
527060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5272f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5274b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
52763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
52789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
5279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
528260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5283454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
52841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParmVarDecl *Param
52857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
52867c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           E->getParam()));
5287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Param)
5288f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
52891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
529053cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth  if (!getDerived().AlwaysRebuild() &&
5291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Param == E->getParam())
52923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
52931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5294036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
5295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
52961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
529860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5299ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5300ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXScalarValueInitExpr *E) {
5301ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5302ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
5303f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5304ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
5305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5306ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo())
53073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
53081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5309ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXScalarValueInitExpr(T,
5310ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
5311ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor                                                    E->getRParenLoc());
5312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
53131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
531560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5316454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
5317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the type that we're allocating
53181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocTypeInfo
53191bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
53201bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  if (!AllocTypeInfo)
5321f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
53221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the size of the array we're allocating (if any).
532460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (ArraySize.isInvalid())
5326f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
53271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the placement arguments (if any).
5329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5330ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> PlacementArgs(SemaRef);
5331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
533263d5fb3a142c39ff4236235cb284401b88685692John McCall    if (getDerived().DropCallArgument(E->getPlacementArg(I))) {
533363d5fb3a142c39ff4236235cb284401b88685692John McCall      ArgumentChanged = true;
533463d5fb3a142c39ff4236235cb284401b88685692John McCall      break;
533563d5fb3a142c39ff4236235cb284401b88685692John McCall    }
533663d5fb3a142c39ff4236235cb284401b88685692John McCall
533760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Arg.isInvalid())
5339f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    PlacementArgs.push_back(Arg.take());
5343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
53441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
534543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the constructor arguments (if any).
5346ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
5347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
534863d5fb3a142c39ff4236235cb284401b88685692John McCall    if (getDerived().DropCallArgument(E->getConstructorArg(I))) {
534963d5fb3a142c39ff4236235cb284401b88685692John McCall      ArgumentChanged = true;
5350ff2e4f44e56aef84fa423af4ca5c1fe56886b4aaDouglas Gregor      break;
535163d5fb3a142c39ff4236235cb284401b88685692John McCall    }
5352ff2e4f44e56aef84fa423af4ca5c1fe56886b4aaDouglas Gregor
535360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Arg.isInvalid())
5355f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ConstructorArgs.push_back(Arg.take());
5359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
53601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform constructor, new operator, and delete operator.
53621af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  CXXConstructorDecl *Constructor = 0;
53631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getConstructor()) {
53641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    Constructor = cast_or_null<CXXConstructorDecl>(
53657c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
53667c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
53671af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!Constructor)
5368f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
53701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
53711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorNew = 0;
53721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorNew()) {
53731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorNew = cast_or_null<FunctionDecl>(
53747c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(E->getLocStart(),
53757c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getOperatorNew()));
53761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorNew)
5377f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
53791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
53801af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
53811af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
53821af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
53837c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
53847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
53851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
5386f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
53871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
5388c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5389b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
53901bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor      AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
5391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArraySize.get() == E->getArraySize() &&
53921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Constructor == E->getConstructor() &&
53931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorNew == E->getOperatorNew() &&
53941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete() &&
53951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      !ArgumentChanged) {
53961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
53971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
53981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (Constructor)
53991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
54001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorNew)
54011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
54021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
54031af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
54043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
54051af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
54061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54071bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  QualType AllocType = AllocTypeInfo->getType();
54085b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  if (!ArraySize.get()) {
54095b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // If no array size was specified, but the new expression was
54105b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with an array type (e.g., "new T" where T is
54115b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with "int[4]"), extract the outer bound from the
54125b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // array type as our array size. We do this with constant and
54135b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // dependently-sized array types.
54145b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
54155b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    if (!ArrayT) {
54165b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      // Do nothing
54175b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const ConstantArrayType *ConsArrayT
54185b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                                     = dyn_cast<ConstantArrayType>(ArrayT)) {
5419c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      ArraySize
54209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
54219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               ConsArrayT->getSize(),
54229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               SemaRef.Context.getSizeType(),
54239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               /*FIXME:*/E->getLocStart()));
54245b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      AllocType = ConsArrayT->getElementType();
54255b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const DependentSizedArrayType *DepArrayT
54265b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                              = dyn_cast<DependentSizedArrayType>(ArrayT)) {
54275b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      if (DepArrayT->getSizeExpr()) {
54283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall        ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
54295b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor        AllocType = DepArrayT->getElementType();
54305b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      }
54315b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    }
54325b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  }
54331bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
5434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isGlobalNew(),
5436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
5437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(PlacementArgs),
5438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
54394bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                        E->getTypeIdParens(),
5440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        AllocType,
54411bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                        AllocTypeInfo,
54429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        ArraySize.get(),
5443b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
5444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(ConstructorArgs),
54451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        E->getLocEnd());
5446b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
544960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5450454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
545160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
5452b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Operand.isInvalid())
5453f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform the delete operator, if known.
54561af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
54571af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
54581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
54597c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
54607c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
54611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
5462f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
54631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
5464c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5465b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
54661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Operand.get() == E->getArgument() &&
54671af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete()) {
54681af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
54691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
54701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
54711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
54725833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
54735833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    if (!E->getArgument()->isTypeDependent()) {
54745833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      QualType Destroyed = SemaRef.Context.getBaseElementType(
54755833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                                         E->getDestroyedType());
54765833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
54775833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
54785833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        SemaRef.MarkDeclarationReferenced(E->getLocStart(),
54795833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                          SemaRef.LookupDestructor(Record));
54805833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      }
54815833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    }
54825833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
54833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
54841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
54851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isGlobalDelete(),
5488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isArrayForm(),
54899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Operand.get());
5490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
54911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
549360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5494a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
5495454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXPseudoDestructorExpr *E) {
549660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
5497a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  if (Base.isInvalid())
5498f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
54991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5500b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ObjectTypePtr;
5501a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  bool MayBePseudoDestructor = false;
55029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
5503a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              E->getOperatorLoc(),
5504a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        E->isArrow()? tok::arrow : tok::period,
5505a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              ObjectTypePtr,
5506a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              MayBePseudoDestructor);
5507a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (Base.isInvalid())
5508f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5509c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5510b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  QualType ObjectType = ObjectTypePtr.get();
551143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  NestedNameSpecifier *Qualifier = E->getQualifier();
551243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Qualifier) {
551343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    Qualifier
551443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
551543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  E->getQualifierRange(),
551643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  ObjectType);
551743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    if (!Qualifier)
551843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      return ExprError();
551943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
55201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5521a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage Destroyed;
5522a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (E->getDestroyedTypeInfo()) {
5523a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    TypeSourceInfo *DestroyedTypeInfo
552443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
552543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjectType, 0, Qualifier);
5526a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!DestroyedTypeInfo)
5527f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5528a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = DestroyedTypeInfo;
5529a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else if (ObjectType->isDependentType()) {
5530a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // We aren't likely to be able to resolve the identifier down to a type
5531a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // now anyway, so just retain the identifier.
5532a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5533a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                            E->getDestroyedTypeLoc());
5534a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else {
5535a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // Look for a destructor known with the given name.
5536a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    CXXScopeSpec SS;
5537a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (Qualifier) {
5538a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      SS.setScopeRep(Qualifier);
5539a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      SS.setRange(E->getQualifierRange());
5540a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    }
5541c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5542b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
5543a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              *E->getDestroyedTypeIdentifier(),
5544a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                E->getDestroyedTypeLoc(),
5545a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                /*Scope=*/0,
5546a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                SS, ObjectTypePtr,
5547a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                false);
5548a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!T)
5549f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5550c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5551a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed
5552a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5553a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                 E->getDestroyedTypeLoc());
5554a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
555526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
555626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *ScopeTypeInfo = 0;
555726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (E->getScopeTypeInfo()) {
555843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
555926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    if (!ScopeTypeInfo)
5560f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5561a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
5562c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
55639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
5564a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->getOperatorLoc(),
5565a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->isArrow(),
5566a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     Qualifier,
556726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getQualifierRange(),
556826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     ScopeTypeInfo,
556926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getColonColonLoc(),
5570fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                     E->getTildeLoc(),
5571a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                     Destroyed);
5572a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}
55731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5574a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived>
557560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5576ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr(
5577454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  UnresolvedLookupExpr *Old) {
5578f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5579f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5580f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5581f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                 Sema::LookupOrdinaryName);
5582f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5583f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Transform all the decls.
5584f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5585f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall         E = Old->decls_end(); I != E; ++I) {
55867c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
55877c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(Old->getNameLoc(),
55887c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                            *I));
55899f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
55909f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
55919f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
55929f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
55939f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
55949f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
5595f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
55969f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
5597f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5598f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // Expand using declarations.
5599f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (isa<UsingDecl>(InstD)) {
5600f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
5601f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5602f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall             E = UD->shadow_end(); I != E; ++I)
5603f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        R.addDecl(*I);
5604f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      continue;
5605f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    }
5606f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5607f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    R.addDecl(InstD);
5608f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
5609f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5610f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Resolve a kind, but don't do any further analysis.  If it's
5611f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // ambiguous, the callee needs to deal with it.
5612f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  R.resolveKind();
5613f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5614f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Rebuild the nested-name qualifier, if present.
5615f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  CXXScopeSpec SS;
5616f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  NestedNameSpecifier *Qualifier = 0;
5617f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (Old->getQualifier()) {
5618f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5619edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                    Old->getQualifierRange());
5620f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!Qualifier)
5621f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5622c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5623f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SS.setScopeRep(Qualifier);
5624f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SS.setRange(Old->getQualifierRange());
5625c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
5626c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5627c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (Old->getNamingClass()) {
562866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    CXXRecordDecl *NamingClass
562966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
563066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                            Old->getNameLoc(),
563166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
563266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
5633f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5634c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
563566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
5636f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
5637f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5638f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have no template arguments, it's a normal declaration name.
5639f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!Old->hasExplicitTemplateArgs())
5640f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5641f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5642f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have template arguments, rebuild them, then rebuild the
5643f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // templateid expression.
5644f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5645f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5646f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    TemplateArgumentLoc Loc;
5647f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5648f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5649f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    TransArgs.addArgument(Loc);
5650f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
5651f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
5652f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5653f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                            TransArgs);
5654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
565760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5658454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
56593d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
56603d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  if (!T)
5661f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
56621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
56643d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      T == E->getQueriedTypeSourceInfo())
56653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
56661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
5668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocStart(),
5669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            T,
5670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocEnd());
5671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
56721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
567460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
56756ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
56766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
56776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!LhsT)
56786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
56796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
56806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
56816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!RhsT)
56826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
56836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
56846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!getDerived().AlwaysRebuild() &&
56856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
56866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SemaRef.Owned(E);
56876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
56886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
56896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocStart(),
56906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            LhsT, RhsT,
56916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocEnd());
56926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}
56936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
56946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived>
56956ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult
5696865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
56972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                               DependentScopeDeclRefExpr *E) {
5698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  NestedNameSpecifier *NNS
5699f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor    = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5700edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                E->getQualifierRange());
5701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!NNS)
5702f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
570443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
570543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
570643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
570743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
57082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
57092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
57102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
5711f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5713f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!E->hasExplicitTemplateArgs()) {
5714f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!getDerived().AlwaysRebuild() &&
5715f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        NNS == E->getQualifier() &&
57162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // Note: it is sufficient to compare the Name component of NameInfo:
57172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // if name has not changed, DNLoc has not changed either.
57182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getDeclName())
57193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
57201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5721f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5722f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         E->getQualifierRange(),
57232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                         NameInfo,
5724f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         /*TemplateArgs*/ 0);
5725f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor  }
5726d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
5727d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
5728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
5729d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TemplateArgumentLoc Loc;
5730d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
5731f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5732d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.addArgument(Loc);
5733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
5734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5735f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5736f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       E->getQualifierRange(),
57372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
5738f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       &TransArgs);
5739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
574260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5743454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
5744321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // CXXConstructExprs are always implicit, so when we have a
5745321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // 1-argument construction we just transform that argument.
5746321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  if (E->getNumArgs() == 1 ||
5747321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor      (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5748321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor    return getDerived().TransformExpr(E->getArg(0));
5749321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor
5750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
5753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
5754f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
5757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
57587c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(E->getLocStart(),
57597c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
5760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
5761f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5764ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
57651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
5766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       ArgEnd = E->arg_end();
5767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       Arg != ArgEnd; ++Arg) {
57686eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    if (getDerived().DropCallArgument(*Arg)) {
57696eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      ArgumentChanged = true;
57706eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      break;
57716eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    }
57726eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
577360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult TransArg = getDerived().TransformExpr(*Arg);
5774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (TransArg.isInvalid())
5775f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
57761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
57789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Args.push_back(TransArg.get());
5779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
5780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
5781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType() &&
5783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
5784c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor      !ArgumentChanged) {
57851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark the constructor as referenced.
57861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: Instantiation-specific
5787c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
57883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5789c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor  }
57901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57914411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
57924411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                              Constructor, E->isElidable(),
57938c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              move_arg(Args),
57948c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              E->requiresZeroInitialization(),
5795428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getConstructionKind(),
5796428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getParenRange());
5797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
57981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression.
5800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
58015132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
58025132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that.
5803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
580460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5805454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
58065132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
5807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58094765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should
58104765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated.
5811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
58124765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we
58135132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that.
5814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
581560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
58164765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
58175132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
5818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
582160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
5823ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXTemporaryObjectExpr *E) {
5824ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5825ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
5826f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
5829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
5830c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                  getDerived().TransformDecl(E->getLocStart(),
58317c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
5832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
5833f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5836ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
5837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Args.reserve(E->getNumArgs());
58381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
5839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         ArgEnd = E->arg_end();
5840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       Arg != ArgEnd; ++Arg) {
584191be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    if (getDerived().DropCallArgument(*Arg)) {
584291be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      ArgumentChanged = true;
584391be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      break;
584491be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    }
584591be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor
584660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult TransArg = getDerived().TransformExpr(*Arg);
5847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (TransArg.isInvalid())
5848f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
58491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Args.push_back((Expr *)TransArg.release());
5852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
58531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5855ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
5856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
585791be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      !ArgumentChanged) {
585891be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    // FIXME: Instantiation-specific
5859ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
58603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.MaybeBindToTemporary(E);
586191be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor  }
5862ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
5863ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXTemporaryObjectExpr(T,
5864ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
5865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    move_arg(Args),
5866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    E->getLocEnd());
5867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
587060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5871b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
5872454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  CXXUnresolvedConstructExpr *E) {
5873ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5874ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
5875f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
5878ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
5879b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5880b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             ArgEnd = E->arg_end();
5881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       Arg != ArgEnd; ++Arg) {
588260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult TransArg = getDerived().TransformExpr(*Arg);
5883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (TransArg.isInvalid())
5884f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
58851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
58879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Args.push_back(TransArg.get());
5888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
58891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5891ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
5892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
58933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: we're faking the locations of the commas
5896ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
5897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getLParenLoc(),
5898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        move_arg(Args),
5899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getRParenLoc());
5900b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
590360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5904865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
59052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                             CXXDependentScopeMemberExpr *E) {
5906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the base of the expression.
590760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
5908aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *OldBase;
5909aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
5910aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType ObjectType;
5911aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->isImplicitAccess()) {
5912aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = E->getBase();
5913aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(OldBase);
5914aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
5915f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
59161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5917aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    // Start the member reference and compute the object's type.
5918b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ObjectTy;
5919d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor    bool MayBePseudoDestructor = false;
59209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
5921aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                E->getOperatorLoc(),
5922a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                      E->isArrow()? tok::arrow : tok::period,
5923d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                ObjectTy,
5924d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                MayBePseudoDestructor);
5925aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
5926f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5927aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
5928b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ObjectType = ObjectTy.get();
5929aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
5930aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
5931aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = 0;
5932aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(E->getBaseType());
5933aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5934aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
59351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59366cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // Transform the first part of the nested-name-specifier that qualifies
59376cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // the member name.
5938c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierInScope
59396cd219879ffce00920189ec1dcea927a42602961Douglas Gregor    = getDerived().TransformFirstQualifierInScope(
59406cd219879ffce00920189ec1dcea927a42602961Douglas Gregor                                          E->getFirstQualifierFoundInScope(),
59416cd219879ffce00920189ec1dcea927a42602961Douglas Gregor                                          E->getQualifierRange().getBegin());
59421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5943a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  NestedNameSpecifier *Qualifier = 0;
5944a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  if (E->getQualifier()) {
5945a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5946a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                      E->getQualifierRange(),
5947aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                      ObjectType,
5948aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                      FirstQualifierInScope);
5949a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor    if (!Qualifier)
5950f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5951a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  }
59521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
595343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
595443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
595543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
595643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
59572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
595843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
59592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
5960f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
59611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5962aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->hasExplicitTemplateArgs()) {
59633b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // This is a reference to a member without an explicitly-specified
59643b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // template argument list. Optimize for this common case.
59653b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
5966aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        Base.get() == OldBase &&
5967aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        BaseType == E->getBaseType() &&
59683b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        Qualifier == E->getQualifier() &&
59692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getMember() &&
59703b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        FirstQualifierInScope == E->getFirstQualifierFoundInScope())
59713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
59721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
5974aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                       BaseType,
59753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->isArrow(),
59763b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getOperatorLoc(),
59773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       Qualifier,
59783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getQualifierRange(),
5979129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       FirstQualifierInScope,
59802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
5981129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       /*TemplateArgs*/ 0);
59823b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
59833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor
5984d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
59853b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
5986d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TemplateArgumentLoc Loc;
5987d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
5988f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5989d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.addArgument(Loc);
59903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
59911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
5993aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                     BaseType,
5994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->isArrow(),
5995b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->getOperatorLoc(),
5996a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     Qualifier,
5997a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                     E->getQualifierRange(),
59983b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                     FirstQualifierInScope,
59992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                     NameInfo,
6000129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                     &TransArgs);
6001129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}
6002129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6003129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived>
600460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6005454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
6006129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform the base of the expression.
600760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
6008aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
6009aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!Old->isImplicitAccess()) {
6010aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(Old->getBase());
6011aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
6012f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6013aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
6014aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
6015aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(Old->getBaseType());
6016aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
6017129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6018129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  NestedNameSpecifier *Qualifier = 0;
6019129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->getQualifier()) {
6020129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    Qualifier
6021129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
6022edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                  Old->getQualifierRange());
6023129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (Qualifier == 0)
6024f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6025129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6026129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
60272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  LookupResult R(SemaRef, Old->getMemberNameInfo(),
6028129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                 Sema::LookupOrdinaryName);
6029129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6030129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform all the decls.
6031129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6032129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         E = Old->decls_end(); I != E; ++I) {
60337c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
60347c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(Old->getMemberLoc(),
60357c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           *I));
60369f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
60379f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
60389f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
60399f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
60409f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
60419f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
6042f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
60439f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
6044129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6045129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    // Expand using declarations.
6046129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (isa<UsingDecl>(InstD)) {
6047129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
6048129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6049129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall             E = UD->shadow_end(); I != E; ++I)
6050129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall        R.addDecl(*I);
6051129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      continue;
6052129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
6053129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6054129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    R.addDecl(InstD);
6055129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6056129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6057129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  R.resolveKind();
6058129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
6059c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  // Determine the naming class.
6060042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth  if (Old->getNamingClass()) {
6061c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    CXXRecordDecl *NamingClass
6062c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
606366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                          Old->getMemberLoc(),
606466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
606566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
6066f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6067c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
606866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
6069c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  }
6070c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6071129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  TemplateArgumentListInfo TransArgs;
6072129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->hasExplicitTemplateArgs()) {
6073129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setLAngleLoc(Old->getLAngleLoc());
6074129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setRAngleLoc(Old->getRAngleLoc());
6075129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
6076129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      TemplateArgumentLoc Loc;
6077129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
6078129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                 Loc))
6079f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
6080129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      TransArgs.addArgument(Loc);
6081129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
6082129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
6083c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
6084c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
6085c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
6086c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
6087c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
6088c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
6089c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
60909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
6091aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  BaseType,
6092129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getOperatorLoc(),
6093129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->isArrow(),
6094129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Qualifier,
6095129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getQualifierRange(),
6096c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                                  FirstQualifierInScope,
6097129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  R,
6098129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              (Old->hasExplicitTemplateArgs()
6099129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  ? &TransArgs : 0));
6100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
610360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
61042e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
61052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
61062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (SubExpr.isInvalid())
61072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return ExprError();
61082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
61092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
61103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
61122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
61132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}
61142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
61152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived>
61162e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult
6117454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
61183fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6119b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
61211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
612260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6123454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
612481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  TypeSourceInfo *EncodedTypeInfo
612581d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
612681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  if (!EncodedTypeInfo)
6127f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6129b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
613081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
61313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
613481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                            EncodedTypeInfo,
6135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc());
6136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
613960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6140454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
614192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Transform arguments.
614292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  bool ArgChanged = false;
6143ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
614492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
614560d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Arg = getDerived().TransformExpr(E->getArg(I));
614692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Arg.isInvalid())
6147f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6148c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
614992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
61509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Args.push_back(Arg.get());
615192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
615292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
615392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
615492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Class message: transform the receiver type.
615592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    TypeSourceInfo *ReceiverTypeInfo
615692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      = getDerived().TransformType(E->getClassReceiverTypeInfo());
615792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!ReceiverTypeInfo)
6158f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
616092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // If nothing changed, just retain the existing message send.
616192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
616292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor        ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
61633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
616492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
616592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Build a new class message send.
616692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
616792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getSelector(),
616892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getMethodDecl(),
616992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getLeftLoc(),
617092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               move_arg(Args),
617192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getRightLoc());
617292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
617392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
617492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Instance message: transform the receiver
617592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
617692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         "Only class and instance messages may be instantiated");
617760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Receiver
617892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    = getDerived().TransformExpr(E->getInstanceReceiver());
617992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (Receiver.isInvalid())
6180f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
618192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
618292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // If nothing changed, just retain the existing message send.
618392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
618492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
61853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6186c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
618792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Build a new instance message send.
61889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
618992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getSelector(),
619092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getMethodDecl(),
619192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getLeftLoc(),
619292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             move_arg(Args),
619392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getRightLoc());
6194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
61961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
619760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6198454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
61993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
620360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6204454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
62053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6207b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
620960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6210454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
6211f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
621260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6213f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
6214f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6215f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor
6216f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // We don't need to transform the ivar; it will never change.
6217c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6218f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
6219f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
6220f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
62213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6222c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
62239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
6224f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->getLocation(),
6225f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->isArrow(), E->isFreeIvar());
6226b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
622960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6230454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
623112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // 'super' and types never change. Property never changes. Just
623212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // retain the existing expression.
623312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (!E->isObjectReceiver())
62343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62358ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian
6236e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // Transform the base expression.
623760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6238e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (Base.isInvalid())
6239f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6240c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6241e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // We don't need to transform the property; it will never change.
6242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6243e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // If nothing changed, just retain the existing expression.
6244e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6245e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      Base.get() == E->getBase())
62463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
624812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (E->isExplicitProperty())
624912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
625012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getExplicitProperty(),
625112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getLocation());
625212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall
625312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
625412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getType(),
625512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertyGetter(),
625612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertySetter(),
625712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getLocation());
6258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
626160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6262454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
6263f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
626460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6265f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
6266f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6267c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6268f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
6269f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
6270f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
62713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6272c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
62739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
6274f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                         E->isArrow());
6275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
627860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6279454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
6280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6281ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> SubExprs(SemaRef);
6282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
628360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6284b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
6285f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
62861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
62889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    SubExprs.push_back(SubExpr.get());
6289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
62901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
62933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move_arg(SubExprs),
6297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               E->getRParenLoc());
6298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
630160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6302454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
6303a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  SourceLocation CaretLoc(E->getExprLoc());
6304a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6305a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6306a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6307a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6308a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  llvm::SmallVector<ParmVarDecl*, 4> Params;
6309a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  llvm::SmallVector<QualType, 4> ParamTypes;
6310a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6311a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Parameter substitution.
6312a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  const BlockDecl *BD = E->getBlockDecl();
6313a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  for (BlockDecl::param_const_iterator P = BD->param_begin(),
6314a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian       EN = BD->param_end(); P != EN; ++P) {
6315a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    ParmVarDecl *OldParm = (*P);
6316a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6317a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    QualType NewType = NewParm->getType();
6318a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    Params.push_back(NewParm);
6319a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    ParamTypes.push_back(NewParm->getType());
6320a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
6321a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6322a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  const FunctionType *BExprFunctionType = E->getFunctionType();
6323a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  QualType BExprResultType = BExprFunctionType->getResultType();
6324a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!BExprResultType.isNull()) {
6325a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    if (!BExprResultType->isDependentType())
6326a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      CurBlock->ReturnType = BExprResultType;
6327a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    else if (BExprResultType != SemaRef.Context.DependentTy)
6328a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6329a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
6330a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6331a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Transform the body
633260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(E->getBody());
6333a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (Body.isInvalid())
6334f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6335a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Set the parameters on the block decl.
6336a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!Params.empty())
6337a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    CurBlock->TheDecl->setParams(Params.data(), Params.size());
6338a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6339a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  QualType FunctionType = getDerived().RebuildFunctionProtoType(
6340a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        CurBlock->ReturnType,
6341a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        ParamTypes.data(),
6342a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        ParamTypes.size(),
6343a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                        BD->isVariadic(),
6344fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                        0,
6345fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                               BExprFunctionType->getExtInfo());
6346a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6347a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  CurBlock->FunctionType = FunctionType;
63489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
6349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
635260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6353454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
6354a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  NestedNameSpecifier *Qualifier = 0;
6355a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
6356a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  ValueDecl *ND
6357a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6358a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                       E->getDecl()));
6359a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!ND)
6360f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
6362a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!getDerived().AlwaysRebuild() &&
6363a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      ND == E->getDecl()) {
6364a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // Mark it referenced in the new context regardless.
6365a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // FIXME: this is a bit instantiation-specific.
6366a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6367a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
63683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6369a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
6370a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
63712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
6372a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
63732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, 0);
6374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6376b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
6377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction
6378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
6379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
638185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
638285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                    SourceLocation Star) {
63832865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildPointerType(PointeeType, Star,
6384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  getDerived().getBaseEntity());
6385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
638885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
638985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                         SourceLocation Star) {
63902865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildBlockPointerType(PointeeType, Star,
6391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       getDerived().getBaseEntity());
6392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
63941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
63951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
639685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
639785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             bool WrittenAsLValue,
639885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             SourceLocation Sigil) {
63992865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
640085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    Sigil, getDerived().getBaseEntity());
6401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
64031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
64041eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
640585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
640685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 QualType ClassType,
640785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceLocation Sigil) {
64082865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
640985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        Sigil, getDerived().getBaseEntity());
6410577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6411577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6412577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64131eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
6414577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6415577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         ArrayType::ArraySizeModifier SizeMod,
6416577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         const llvm::APInt *Size,
6417577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         Expr *SizeExpr,
6418577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         unsigned IndexTypeQuals,
6419577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         SourceRange BracketsRange) {
6420577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (SizeExpr || !Size)
6421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6422577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  IndexTypeQuals, BracketsRange,
6423577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  getDerived().getBaseEntity());
64241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType Types[] = {
64261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
64271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
64281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
6429577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  };
6430577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6431577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType SizeType;
6432577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  for (unsigned I = 0; I != NumTypes; ++I)
6433577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6434577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      SizeType = Types[I];
6435577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      break;
6436577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    }
64371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
64399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                           /*FIXME*/BracketsRange.getBegin());
64401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
6441577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                IndexTypeQuals, BracketsRange,
64421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                getDerived().getBaseEntity());
6443577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
64441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6445577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64461eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
64471eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
6448577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 ArrayType::ArraySizeModifier SizeMod,
6449577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 const llvm::APInt &Size,
645085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
645185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceRange BracketsRange) {
64521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
645385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        IndexTypeQuals, BracketsRange);
6454577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6455577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6456577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64571eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
64581eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
6459577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
646085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
646185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   SourceRange BracketsRange) {
64621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
646385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                       IndexTypeQuals, BracketsRange);
6464577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
64651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64671eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
64681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
6469577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
64709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SizeExpr,
6471577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 unsigned IndexTypeQuals,
6472577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceRange BracketsRange) {
64731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
64749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
6475577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
6476577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6477577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6478577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
64791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
64801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
6481577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
64829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Expr *SizeExpr,
6483577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                       unsigned IndexTypeQuals,
6484577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                   SourceRange BracketsRange) {
64851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
64869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
6487577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
6488577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6489577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6490577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6491577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
6492e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               unsigned NumElements,
6493e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               VectorType::VectorKind VecKind) {
6494577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  // FIXME: semantic checking!
6495e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
6496577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
64971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6498577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6499577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6500577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                      unsigned NumElements,
6501577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceLocation AttributeLoc) {
6502577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6503577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                          NumElements, true);
6504577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  IntegerLiteral *VectorSize
65059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
65069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             AttributeLoc);
65079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
6508577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6510577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
65111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
65121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
65139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                           Expr *SizeExpr,
6514577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                  SourceLocation AttributeLoc) {
65159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
6516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6518577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6519577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
65201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          QualType *ParamTypes,
6521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                        unsigned NumParamTypes,
65221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          bool Variadic,
6523fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                          unsigned Quals,
6524fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                            const FunctionType::ExtInfo &Info) {
65251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
6526577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   Quals,
6527577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   getDerived().getBaseLocation(),
6528fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   getDerived().getBaseEntity(),
6529fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   Info);
6530577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6533a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6534a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return SemaRef.Context.getFunctionNoProtoType(T);
6535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
6536a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
6537a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
6538ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6539ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  assert(D && "no decl found");
6540ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (D->isInvalidDecl()) return QualType();
6541ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
654292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // FIXME: Doesn't account for ObjCInterfaceDecl!
6543ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeDecl *Ty;
6544ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (isa<UsingDecl>(D)) {
6545ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    UsingDecl *Using = cast<UsingDecl>(D);
6546ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(Using->isTypeName() &&
6547ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-typename using");
6548ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
6549ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    // A valid resolved using typename decl points to exactly one type decl.
6550ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(++Using->shadow_begin() == Using->shadow_end());
6551ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
6552c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6553ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  } else {
6554ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6555ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-using decl");
6556ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<UnresolvedUsingTypenameDecl>(D);
6557ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
6558ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
6559ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return SemaRef.Context.getTypeDeclType(Ty);
6560ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
6561ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
6562ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived>
65632a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
65642a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                       SourceLocation Loc) {
65652a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildTypeofExprType(E, Loc);
6566577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6567577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6568577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6569577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  return SemaRef.Context.getTypeOfType(Underlying);
6571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
65742a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
65752a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                     SourceLocation Loc) {
65762a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildDecltypeType(E, Loc);
6577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
6578577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
6580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
6581833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                      TemplateName Template,
6582833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateNameLoc,
6583d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                               const TemplateArgumentListInfo &TemplateArgs) {
6584d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
6585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
65861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6587dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
6588dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
6589dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6590dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
6591a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                                   IdentifierInfo &II,
6592c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                   QualType ObjectType,
6593d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NamedDecl *FirstQualifierInScope) {
6594dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  CXXScopeSpec SS;
6595dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  // FIXME: The source location information is all wrong.
6596dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SS.setRange(Range);
6597dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SS.setScopeRep(Prefix);
6598dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return static_cast<NestedNameSpecifier *>(
65991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
6600495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor                                                        Range.getEnd(), II,
6601c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                        ObjectType,
6602c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                                                        FirstQualifierInScope,
660346646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner                                                        false, false));
6604dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
6605dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
6606dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
6607dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
6608dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6609dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
6610dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   NamespaceDecl *NS) {
6611dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6612dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
6613dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor
6614dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
6615dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier *
6616dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6617dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   SourceRange Range,
6618dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                                   bool TemplateKW,
6619edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor                                                   QualType T) {
6620edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor  if (T->isDependentType() || T->isRecordType() ||
6621dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor      (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
6622a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
6623dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor    return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6624dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor                                       T.getTypePtr());
6625dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
66261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6627dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6628dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  return 0;
6629dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor}
66301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6631d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
66321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
6633d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6634d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            bool TemplateKW,
6635d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            TemplateDecl *Template) {
66361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
6637d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                                  Template);
6638d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
6639d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
6640d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
66411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
6642d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
66431efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor                                            SourceRange QualifierRange,
66443b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                            const IdentifierInfo &II,
664543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            QualType ObjectType,
664643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            NamedDecl *FirstQualifierInScope) {
6647d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  CXXScopeSpec SS;
66481efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor  SS.setRange(QualifierRange);
66491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SS.setScopeRep(Qualifier);
6650014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  UnqualifiedId Name;
6651014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor  Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
6652d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
6653d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
6654d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*FIXME:*/getDerived().getBaseLocation(),
6655d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
6656d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
6657b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
6658d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
6659d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
666043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return Template.get();
6661d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
66621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
6664ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName
6665ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6666ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            OverloadedOperatorKind Operator,
6667ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            QualType ObjectType) {
6668ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  CXXScopeSpec SS;
6669ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SS.setRange(SourceRange(getDerived().getBaseLocation()));
6670ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SS.setScopeRep(Qualifier);
6671ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  UnqualifiedId Name;
6672ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6673ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6674ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                             Operator, SymbolLocations);
6675d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
6676d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
6677ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                       /*FIXME:*/getDerived().getBaseLocation(),
6678d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
6679d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
6680b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
6681d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
6682d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
6683d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  return Template.template getAsVal<TemplateName>();
6684ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor}
6685c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6686ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived>
668760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   SourceLocation OpLoc,
66909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *OrigCallee,
66919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *First,
66929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *Second) {
66939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Callee = OrigCallee->IgnoreParenCasts();
66949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
66951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Determine whether this should be a builtin operation.
6697f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript) {
66989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
66999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType())
67009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinArraySubscriptExpr(First,
67019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Callee->getLocStart(),
67029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Second, OpLoc);
67031a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman  } else if (Op == OO_Arrow) {
67041a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman    // -> is never a builtin operation.
67059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
67069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  } else if (Second == 0 || isPostIncDec) {
67079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType()) {
6708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // The argument is not of overloadable type, so try to create a
6709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // built-in unary operation.
67102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      UnaryOperatorKind Opc
6711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor        = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
67121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
6714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
6715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  } else {
67169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
67179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType()) {
6718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // Neither of the arguments is an overloadable type, so try to
6719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // create a built-in binary operation.
67202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
672160d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Result
67229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
6723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Result.isInvalid())
6724f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
67251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      return move(Result);
6727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
6728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
67291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Compute the transformed set of functions (and function templates) to be
6731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // used during overload resolution.
67326e26689f5d513e24ad7783a4493201930fdeccc0John McCall  UnresolvedSet<16> Functions;
67331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
6735ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    assert(ULE->requiresADL());
6736ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
6737ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // FIXME: Do we have to check
6738ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // IsAcceptableNonMemberOperatorCandidate for each of these?
67396e26689f5d513e24ad7783a4493201930fdeccc0John McCall    Functions.append(ULE->decls_begin(), ULE->decls_end());
6740ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  } else {
67419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
6742ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
67431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Add any functions found via argument-dependent lookup.
67459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Args[2] = { First, Second };
67469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  unsigned NumArgs = 1 + (Second != 0);
67471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for unary operators.
6749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (NumArgs == 1 || isPostIncDec) {
67502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    UnaryOperatorKind Opc
6751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
67529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
6753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
67541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6755f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript)
67569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
6757ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                                      OpLoc,
67589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      First,
67599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Second);
6760f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl
6761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for binary operators.
67622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
676360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result
6764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Result.isInvalid())
6766f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return move(Result);
6769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
677126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived>
677260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
67739ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
677426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceLocation OperatorLoc,
677526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       bool isArrow,
677626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                 NestedNameSpecifier *Qualifier,
677726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceRange QualifierRange,
677826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     TypeSourceInfo *ScopeType,
677926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       SourceLocation CCLoc,
6780fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                       SourceLocation TildeLoc,
6781a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed) {
678226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  CXXScopeSpec SS;
678326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (Qualifier) {
678426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    SS.setRange(QualifierRange);
678526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    SS.setScopeRep(Qualifier);
678626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
678726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
67889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  QualType BaseType = Base->getType();
67899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
679026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      (!isArrow && !BaseType->getAs<RecordType>()) ||
6791c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      (isArrow && BaseType->getAs<PointerType>() &&
6792bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif       !BaseType->getAs<PointerType>()->getPointeeType()
6793bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif                                              ->template getAs<RecordType>())){
679426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    // This pseudo-destructor expression is still a pseudo-destructor.
67959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
679626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             isArrow? tok::arrow : tok::period,
6797fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                             SS, ScopeType, CCLoc, TildeLoc,
6798a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                             Destroyed,
679926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             /*FIXME?*/true);
680026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
68012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
6802a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
68032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
68042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
68052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
68062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  NameInfo.setNamedTypeInfo(DestroyedType);
68072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
680826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  // FIXME: the ScopeType should be tacked onto SS.
68092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
68109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getSema().BuildMemberReferenceExpr(Base, BaseType,
681126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            OperatorLoc, isArrow,
681226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            SS, /*FIXME: FirstQualifier*/ 0,
68132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            NameInfo,
681426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            /*TemplateArgs*/ 0);
681526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor}
681626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
6817577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang
6818577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6819577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
6820