TreeTransform.h revision 990567cb60e8530ba01b41d4e056e32b44b95ec0
157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
3577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//                     The LLVM Compiler Infrastructure
4577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
5577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file is distributed under the University of Illinois Open Source
6577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// License. See LICENSE.TXT for details.
757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===//
8577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
9577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//  This file implements a semantic tree transformation that takes a given
10577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//  AST and rebuilds it, possibly transforming some nodes in the process.
11577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//
1257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===//
1357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
172d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h"
18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h"
198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor#include "clang/Sema/ParsedTemplate.h"
20dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h"
21781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h"
22c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h"
237cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h"
243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith#include "clang/AST/DeclTemplate.h"
25657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h"
26b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h"
27b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h"
2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h"
2943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h"
3043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h"
3119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h"
3219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h"
33b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h"
34a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h"
357e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h"
36577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm>
37577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
38577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang {
39781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema;
401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one
42577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another.
43577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide
461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template
47577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the
48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the
49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar
50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and
51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters.
52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow
541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can
55577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an
56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The
57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual.
58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which
60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node
61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions,
62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation
64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g.,
65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes
66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create
67577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node.
68577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The
70670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(),
719151c11836f5fbb36cedfe4d22df7e00e77a1d42Douglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
72577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations.
74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the
76577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
7743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
78577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template
80577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX
81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change.
82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps.
85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one
871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation
88577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the
90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking
91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()).
92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
93577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform {
94d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief Private RAII object that helps us forget and then re-remember
95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// the template argument corresponding to a partially-substituted parameter
96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack.
97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  class ForgetPartiallySubstitutedPackRAII {
98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    Derived &Self;
99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    TemplateArgument Old;
100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
101d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  public:
102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Old = Self.ForgetPartiallySubstitutedPack();
104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ~ForgetPartiallySubstitutedPackRAII() {
107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Self.RememberPartiallySubstitutedPack(Old);
108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  };
110d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected:
112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &SemaRef;
1138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
115577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Initializes a new tree transformer.
116b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Derived &getDerived() { return static_cast<Derived&>(*this); }
120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Derived &getDerived() const {
1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return static_cast<const Derived&>(*this);
124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
12660d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline ExprResult Owned(Expr *E) { return E; }
12760d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline StmtResult Owned(Stmt *S) { return S; }
1289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall
129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the semantic analysis object used for
130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// this tree transform.
131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &getSema() const { return SemaRef; }
1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Whether the transformation should always rebuild AST nodes, even
134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// if none of the children have changed.
135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this function to specify when the transformation
137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// should rebuild all AST nodes.
138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlwaysRebuild() { return false; }
1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the location of the entity being transformed, if that
141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, returns no source-location information. Subclasses can
144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// provide an alternative implementation that provides better location
145577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information.
146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  SourceLocation getBaseLocation() { return SourceLocation(); }
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the name of the entity being transformed, if that
149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, returns an empty name. Subclasses can provide an alternative
152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// implementation with a more precise name.
153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  DeclarationName getBaseEntity() { return DeclarationName(); }
154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Sets the "base" location and entity when that
156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// information is known based on another transformation.
157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, the source location and entity are ignored. Subclasses can
159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// override this function to provide a customized implementation.
160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  void setBase(SourceLocation Loc, DeclarationName Entity) { }
1611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief RAII object that temporarily sets the base location and entity
163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// used for reporting diagnostics in types.
164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  class TemporaryBase {
165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TreeTransform &Self;
166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SourceLocation OldLocation;
167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclarationName OldEntity;
1681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  public:
170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TemporaryBase(TreeTransform &Self, SourceLocation Location,
1711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  DeclarationName Entity) : Self(Self) {
172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldLocation = Self.getDerived().getBaseLocation();
173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldEntity = Self.getDerived().getBaseEntity();
174ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor
175ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor      if (Location.isValid())
176ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor        Self.getDerived().setBase(Location, Entity);
177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ~TemporaryBase() {
180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Self.getDerived().setBase(OldLocation, OldEntity);
181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  };
1831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determine whether the given type \p T has already been
185577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// transformed.
186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
187577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses can provide an alternative implementation of this routine
1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// to short-circuit evaluation when it is known that a given type will
189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// not change. For example, template instantiation need not traverse
190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// non-dependent types.
191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlreadyTransformed(QualType T) {
192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T.isNull();
193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
194577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
1956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether the given call argument should be dropped, e.g.,
1966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// because it is a default argument.
1976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
1986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Subclasses can provide an alternative implementation of this routine to
1996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// determine which kinds of call arguments get dropped. By default,
2006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// CXXDefaultArgument nodes are dropped (prior to transformation).
2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool DropCallArgument(Expr *E) {
2026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return E->isDefaultArgument();
2036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
204c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Determine whether we should expand a pack expansion with the
2068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// given set of parameter packs into separate arguments by repeatedly
2078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// transforming the pattern.
2088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
209b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  /// By default, the transformer never tries to expand pack expansions.
2108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// Subclasses can override this routine to provide different behavior.
2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param EllipsisLoc The location of the ellipsis that identifies the
2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pack expansion.
2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param PatternRange The source range that covers the entire pattern of
2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// the pack expansion.
2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param Unexpanded The set of unexpanded parameter packs within the
2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pattern.
2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumUnexpanded The number of unexpanded parameter packs in
2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \p Unexpanded.
2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param ShouldExpand Will be set to \c true if the transformer should
2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// expand the corresponding pack expansions into separate arguments. When
2268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// set, \c NumExpansions must also be set.
2278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
228d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \param RetainExpansion Whether the caller should add an unexpanded
229d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack expansion after all of the expanded arguments. This is used
230d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when extending explicitly-specified template argument packs per
231d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// C++0x [temp.arg.explicit]p9.
232d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
2338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumExpansions The number of separate arguments that will be in
234cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// the expanded form of the corresponding pack expansion. This is both an
235cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// input and an output parameter, which can be set by the caller if the
236cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// number of expansions is known a priori (e.g., due to a prior substitution)
237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// and will be set by the callee when the number of expansions is known.
238cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// The callee must set this value when \c ShouldExpand is \c true; it may
239cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// set this value in other cases.
2408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \returns true if an error occurred (e.g., because the parameter packs
2428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// are to be instantiated with arguments of different lengths), false
2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
2448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// must be set.
2458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
2468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               SourceRange PatternRange,
2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               const UnexpandedParameterPack *Unexpanded,
2488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               unsigned NumUnexpanded,
2498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               bool &ShouldExpand,
250d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                               bool &RetainExpansion,
251cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                               llvm::Optional<unsigned> &NumExpansions) {
2528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    ShouldExpand = false;
2538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return false;
2548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
2558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
256d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Forget" about the partially-substituted pack template argument,
257d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when performing an instantiation that must preserve the parameter pack
258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  TemplateArgument ForgetPartiallySubstitutedPack() {
262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    return TemplateArgument();
263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  }
264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Remember" the partially-substituted pack template argument
266d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// after performing an instantiation that must preserve the parameter pack
267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
27212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// \brief Note to the derived class when a function parameter pack is
27312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// being expanded.
27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
27512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor
276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transforms the given type into another type.
277577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by creating a
279a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// TypeSourceInfo for it and delegating to the appropriate
280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// function.  This is expensive, but we don't mind, because
281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// this method is deprecated anyway;  all users should be
282a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// switched to storing TypeSourceInfos.
283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
284577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \returns the transformed type.
28543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(QualType T);
2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transforms the given type-with-location into a new
288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type-with-location.
289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ///
290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by delegating to the
291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// appropriate TransformXXXType to build a new type.  Subclasses
292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// may override this function (to take over all type
293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// transformations) or some set of the TransformXXXType functions
294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// to alter the transformation.
29543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transform the given type-with-location into a new
298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type, collecting location information in the given builder
299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// as necessary.
300577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
30143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
303657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given statement.
304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this routine transforms a statement by delegating to the
30643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// appropriate TransformXXXStmt function to transform a specific kind of
30743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// statement or the TransformExpr() function to transform an expression.
30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to transform statements using some
30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// other mechanism.
31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
31143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \returns the transformed statement.
31260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformStmt(Stmt *S);
3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
314657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given expression.
315657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  ///
316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine transforms an expression by delegating to the
317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// appropriate TransformXXXExpr function to build a new expression.
318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this function to transform expressions using some
319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// other mechanism.
320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \returns the transformed expression.
32260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformExpr(Expr *E);
3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Transform the given list of expressions.
325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// This routine transforms a list of expressions by invoking
327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \c TransformExpr() for each subexpression. However, it also provides
328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// support for variadic templates by expanding any pack expansions (if the
329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// derived class permits such expansion) along the way. When pack expansions
330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// are present, the number of outputs may not equal the number of inputs.
331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Inputs The set of expressions to be transformed.
333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param NumInputs The number of expressions in \c Inputs.
335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param IsCall If \c true, then this transform is being performed on
337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// function-call arguments, and any arguments that should be dropped, will
338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// be.
339aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Outputs The transformed input expressions will be added to this
341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// vector.
342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// due to transformation.
345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \returns true if an error occurred, false otherwise.
347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
348686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                      SmallVectorImpl<Expr *> &Outputs,
349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                      bool *ArgChanged = 0);
350aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given declaration, which is referenced from a type
352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// or expression.
353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
354dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// By default, acts as the identity function on declarations. Subclasses
355dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// may override this function to provide alternate behavior.
3567c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
35743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
35843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Transform the definition of the given declaration.
35943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, invokes TransformDecl() to transform the declaration.
36143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getDerived().TransformDecl(Loc, D);
3647c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  }
3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3666cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// \brief Transform the given declaration, which was the first part of a
3676cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// nested-name-specifier in a member access expression.
3686cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
369c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// This specific declaration transformation only applies to the first
3706cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// identifier in a nested-name-specifier of a member access expression, e.g.,
3716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// the \c T in \c x->T::member
3726cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
3736cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// By default, invokes TransformDecl() to transform the declaration.
3746cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// Subclasses may override this function to provide alternate behavior.
375c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
3776cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  }
378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
379c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// \brief Transform the given nested-name-specifier with source-location
380c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// information.
381c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  ///
382c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// By default, transforms all of the types and declarations within the
383c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// nested-name-specifier. Subclasses may override this function to provide
384c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// alternate behavior.
385c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                    NestedNameSpecifierLoc NNS,
387c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                          QualType ObjectType = QualType(),
388c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                          NamedDecl *FirstQualifierInScope = 0);
389c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
39081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// \brief Transform the given declaration name.
39181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  ///
39281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// By default, transforms the types of conversion function, constructor,
39381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// and destructor names and then (if needed) rebuilds the declaration name.
39481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// Identifiers and selectors are returned unmodified. Sublcasses may
39581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// override this function to provide alternate behavior.
3962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo
39743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template name.
4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
401fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param SS The nested-name-specifier that qualifies the template
402fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// name. This nested-name-specifier must already have been transformed.
403fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
404fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param Name The template name to transform.
405fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
406fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param NameLoc The source location of the template name.
407fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
408fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param ObjectType If we're translating a template name within a member
409fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// access expression, this is the type of the object whose member template
410fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// is being referenced.
411fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
412fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// also refers to a name within the current (lexical) scope, this is the
414fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// declaration it refers to.
415fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
416fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// By default, transforms the template name by transforming the declarations
417fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// and nested-name-specifiers that occur within the template name.
418fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
419fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName TransformTemplateName(CXXScopeSpec &SS,
420fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     TemplateName Name,
421fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     SourceLocation NameLoc,
422fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     QualType ObjectType = QualType(),
423fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     NamedDecl *FirstQualifierInScope = 0);
424fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
425577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template argument.
426577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this operation transforms the type, expression, or
4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// declaration stored within the template argument and constructs a
429670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// new template argument from the transformed result. Subclasses may
430670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// override this function to provide alternate behavior.
431833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  ///
432833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// Returns true if there was an error.
433833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &Output);
435833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
436fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \brief Transform the given set of template arguments.
437fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
438fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// By default, this operation transforms all of the template arguments
439fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
440fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// the transformed arguments to the output list.
441fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
4427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// Note that this overload of \c TransformTemplateArguments() is merely
4437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// a convenience function. Subclasses that wish to override this behavior
4447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// should override the iterator-based member template version.
4457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
446fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Inputs The set of template arguments to be transformed.
447fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
448fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param NumInputs The number of template arguments in \p Inputs.
449fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
450fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Outputs The set of transformed template arguments output by this
451fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// routine.
452fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
453fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// Returns true if an error occurred.
454fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                  unsigned NumInputs,
4567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs) {
4577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
4587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
4597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
4607f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \brief Transform the given set of template arguments.
4617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// By default, this operation transforms all of the template arguments
4637f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
4647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// the transformed arguments to the output list.
4657f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param First An iterator to the first template argument.
4677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
4687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param Last An iterator one step past the last template argument.
4697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4707f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \param Outputs The set of transformed template arguments output by this
4717f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// routine.
4727f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4737f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// Returns true if an error occurred.
4747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename InputIterator>
4757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  bool TransformTemplateArguments(InputIterator First,
4767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  InputIterator Last,
4777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs);
4787f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
479833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &ArgLoc);
482833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
483a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// \brief Fakes up a TypeSourceInfo for a type.
484a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return SemaRef.Context.getTrivialTypeSourceInfo(T,
486833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                       getDerived().getBaseLocation());
487833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT)                                   \
49143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
493577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
49428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult
49528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  TransformSEHHandler(Stmt *Handler);
49628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
49743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
49843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
49943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateSpecializationTypeLoc TL,
50043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateName Template);
50143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
50243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType
50343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
50443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentTemplateSpecializationTypeLoc TL,
505087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                               TemplateName Template,
506087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                               CXXScopeSpec &SS);
507a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
508a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  QualType
509a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
51094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                               DependentTemplateSpecializationTypeLoc TL,
51194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                         NestedNameSpecifierLoc QualifierLoc);
51294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
51321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms the parameters of a function type into the
51421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// given vectors.
51521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
51621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// The result vectors should be kept in sync; null entries in the
51721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// variables vector are acceptable.
51821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
51921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// Return true on error.
520a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  bool TransformFunctionTypeParams(SourceLocation Loc,
521a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   ParmVarDecl **Params, unsigned NumParams,
522a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   const QualType *ParamTypes,
523686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                   SmallVectorImpl<QualType> &PTypes,
524686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                   SmallVectorImpl<ParmVarDecl*> *PVars);
52521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
52621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms a single function-type parameter.  Return null
52721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// on error.
528fb44de956f27875def889482b5393475060392afJohn McCall  ///
529fb44de956f27875def889482b5393475060392afJohn McCall  /// \param indexAdjustment - A number to add to the parameter's
530fb44de956f27875def889482b5393475060392afJohn McCall  ///   scope index;  can be negative
5316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
532fb44de956f27875def889482b5393475060392afJohn McCall                                          int indexAdjustment,
5336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                        llvm::Optional<unsigned> NumExpansions);
53421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
53543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
536833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
53760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
53860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                        \
54160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Transform##Node(Node *S);
542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                        \
54360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Transform##Node(Node *E);
5447381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
5454bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new pointer type given its pointee type.
548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the pointer type.
550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
55185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new block pointer type given its pointee type.
554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis when building the block pointer
556577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
55785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
558577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
55985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \brief Build a new reference type given the type it references.
560577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
56185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// By default, performs semantic analysis when building the
56285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// reference type. Subclasses may override this routine to provide
56385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// different behavior.
564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
56585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \param LValue whether the type was written with an lvalue sigil
56685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// or an rvalue sigil.
56785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildReferenceType(QualType ReferentType,
56885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                bool LValue,
56985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                SourceLocation Sigil);
5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new member pointer type given the pointee type and the
572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// class type it refers into.
573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the member pointer
575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
57685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
57785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceLocation Sigil);
5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new array type given the element type, size
580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, size of the array (if known), size expression, and index type
581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// qualifiers.
582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Also by default, all of the other Rebuild*Array
586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildArrayType(QualType ElementType,
587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            ArrayType::ArraySizeModifier SizeMod,
588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            const llvm::APInt *Size,
589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            Expr *SizeExpr,
590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            unsigned IndexTypeQuals,
591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            SourceRange BracketsRange);
5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new constant array type given the element type, size
594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, (known) size of the array, and index type qualifiers.
595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
596577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildConstantArrayType(QualType ElementType,
599577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    const llvm::APInt &Size,
60185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    unsigned IndexTypeQuals,
60285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceRange BracketsRange);
603577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new incomplete array type given the element type, size
605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, and index type qualifiers.
606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildIncompleteArrayType(QualType ElementType,
610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                      ArrayType::ArraySizeModifier SizeMod,
61185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      unsigned IndexTypeQuals,
61285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      SourceRange BracketsRange);
613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new variable-length array type given the element type,
615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildVariableArrayType(QualType ElementType,
620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
6219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SizeExpr,
622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned IndexTypeQuals,
623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    SourceRange BracketsRange);
624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new dependent-sized array type given the element type,
626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedArrayType(QualType ElementType,
631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
6329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *SizeExpr,
633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          unsigned IndexTypeQuals,
634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          SourceRange BracketsRange);
635577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
636577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new vector type given the element type and
637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
64182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
642e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                             VectorType::VectorKind VecKind);
6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new extended vector type given the element type and
645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
646577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                SourceLocation AttributeLoc);
6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new potentially dependently-sized extended vector type
653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// given the element type and number of elements.
654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
6589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *SizeExpr,
659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                              SourceLocation AttributeLoc);
6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
661577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new function type.
662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the function type.
664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildFunctionProtoType(QualType T,
6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    QualType *ParamTypes,
667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned NumParamTypes,
668fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    bool Variadic, unsigned Quals,
669c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                    RefQualifierKind RefQualifier,
670fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    const FunctionType::ExtInfo &Info);
6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Build a new unprototyped function type.
673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType RebuildFunctionNoProtoType(QualType ResultType);
674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
675ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// \brief Rebuild an unresolved typename type, given the decl that
676ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// the UnresolvedUsingTypenameDecl was transformed to.
677ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType RebuildUnresolvedUsingType(Decl *D);
678ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typedef type.
680162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Typedef);
682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new class/struct/union type.
685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildRecordType(RecordDecl *Record) {
686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Record);
687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new Enum type.
690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildEnumType(EnumDecl *Enum) {
691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Enum);
692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
6937da2431c23ef1ee8acb114e39692246e1801afc2John McCall
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(expr) type.
695577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typeof type.
697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(type) type.
701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, builds a new TypeOfType with the given underlying type.
703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypeOfType(QualType Underlying);
704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
705ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// \brief Build a new unary transform type.
706ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType RebuildUnaryTransformType(QualType BaseType,
707ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                     UnaryTransformType::UTTKind UKind,
708ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                     SourceLocation Loc);
709ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++0x decltype type.
711577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
712577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the decltype type.
713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
7142a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71634b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Build a new C++0x auto type.
71734b41d939a1328f484511c6002ba2456db879a29Richard Smith  ///
71834b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// By default, builds a new AutoType with the given deduced type.
71934b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType RebuildAutoType(QualType Deduced) {
72034b41d939a1328f484511c6002ba2456db879a29Richard Smith    return SemaRef.Context.getAutoType(Deduced);
72134b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
72234b41d939a1328f484511c6002ba2456db879a29Richard Smith
723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new template specialization type.
724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the template
726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// specialization type. Subclasses may override this routine to provide
727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTemplateSpecializationType(TemplateName Template,
729833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateLoc,
73067714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                             TemplateArgumentListInfo &Args);
7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
732075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// \brief Build a new parenthesized type.
733075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ///
734075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// By default, builds a new ParenType type from the inner type.
735075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
736075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType RebuildParenType(QualType InnerType) {
737075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return SemaRef.Context.getParenType(InnerType);
738075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
739075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new qualified name type.
741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
742465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// By default, builds a new ElaboratedType type from the keyword,
743465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// the nested-name-specifier and the named type.
744465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
74521e413fe6305a198564d436ac515497716c47844John McCall  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
74621e413fe6305a198564d436ac515497716c47844John McCall                                 ElaboratedTypeKeyword Keyword,
7479e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                 NestedNameSpecifierLoc QualifierLoc,
7489e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                 QualType Named) {
7499e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    return SemaRef.Context.getElaboratedType(Keyword,
7509e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                         QualifierLoc.getNestedNameSpecifier(),
7519e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                             Named);
7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
753577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
754577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to a template-id.
755577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
756e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// By default, builds a new DependentNameType type from the
757e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// nested-name-specifier and the given type. Subclasses may override
758e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// this routine to provide different behavior.
75933500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType RebuildDependentTemplateSpecializationType(
76094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          ElaboratedTypeKeyword Keyword,
76194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
76294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          const IdentifierInfo *Name,
76394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          SourceLocation NameLoc,
76467714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                          TemplateArgumentListInfo &Args) {
76594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Rebuild the template name.
76694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // TODO: avoid TemplateName abstraction
767fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    CXXScopeSpec SS;
768fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    SS.Adopt(QualifierLoc);
76994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    TemplateName InstName
770fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
77194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
77294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (InstName.isNull())
77394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return QualType();
77494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
77594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // If it's still dependent, make a dependent specialization.
77694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (InstName.getAsDependentTemplateName())
77794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
77894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          QualifierLoc.getNestedNameSpecifier(),
77994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                                    Name,
78094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                                    Args);
78194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
78294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Otherwise, make an elaborated type wrapping a non-dependent
78394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // specialization.
78494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualType T =
78594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
78694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (T.isNull()) return QualType();
78794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
78894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
78994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return T;
79094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
79194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return SemaRef.Context.getElaboratedType(Keyword,
79294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                       QualifierLoc.getNestedNameSpecifier(),
79394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                             T);
79494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  }
79594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
796577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to an identifier.
797577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
798577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typename type
799e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// (or elaborated type). Subclasses may override this routine to provide
800577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
801e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
802e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation KeywordLoc,
8032494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                    NestedNameSpecifierLoc QualifierLoc,
8042494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                    const IdentifierInfo *Id,
805e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation IdLoc) {
8064033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    CXXScopeSpec SS;
8072494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    SS.Adopt(QualifierLoc);
808e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
8092494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
8104033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      // If the name is still dependent, just build a new dependent name type.
8114033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      if (!SemaRef.computeDeclContext(SS))
8122494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor        return SemaRef.Context.getDependentNameType(Keyword,
8132494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                          QualifierLoc.getNestedNameSpecifier(),
8142494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                                    Id);
8154033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
817465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (Keyword == ETK_None || Keyword == ETK_Typename)
8182494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor      return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
819e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor                                       *Id, IdLoc);
820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
823e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    // We had a dependent elaborated-type-specifier that has been transformed
8244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // into a non-dependent elaborated-type-specifier. Find the tag we're
8254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // referring to.
826e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
8274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    DeclContext *DC = SemaRef.computeDeclContext(SS, false);
8284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!DC)
8294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8315613876991c80a684595fe8de1f039296a0657ffJohn McCall    if (SemaRef.RequireCompleteDeclContext(SS, DC))
8325613876991c80a684595fe8de1f039296a0657ffJohn McCall      return QualType();
8335613876991c80a684595fe8de1f039296a0657ffJohn McCall
8344033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    TagDecl *Tag = 0;
8354033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SemaRef.LookupQualifiedName(Result, DC);
8364033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    switch (Result.getResultKind()) {
8374033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFound:
8384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFoundInCurrentInstantiation:
8394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
840c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Found:
8424033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        Tag = Result.getAsSingle<TagDecl>();
8434033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundOverloaded:
8464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundUnresolvedValue:
8474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        llvm_unreachable("Tag lookup cannot find non-tags");
8484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
849c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8504033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Ambiguous:
8514033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        // Let the LookupResult structure handle ambiguities.
8524033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8554033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!Tag) {
856446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // Check where the name exists but isn't a tag type and use that to emit
857446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // better diagnostics.
858446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      SemaRef.LookupQualifiedName(Result, DC);
860446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      switch (Result.getResultKind()) {
861446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::Found:
862446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundOverloaded:
863446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundUnresolvedValue: {
8643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith          NamedDecl *SomeDecl = Result.getRepresentativeDecl();
865446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          unsigned Kind = 0;
866446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
867162e1c1b487352434552147967c3dd296ebee2f7Richard Smith          else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868162e1c1b487352434552147967c3dd296ebee2f7Richard Smith          else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
869446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
8723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        }
873446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        default:
874446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          // FIXME: Would be nice to highlight just the source range.
875446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky            << Kind << Id << DC;
877446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
878446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      }
8794033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
881465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
882bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu    if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu                                              IdLoc, *Id)) {
884e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
8854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
8864033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // Build the elaborated-type-specifier type.
8904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    QualType T = SemaRef.Context.getTypeDeclType(Tag);
8912494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    return SemaRef.Context.getElaboratedType(Keyword,
8922494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                         QualifierLoc.getNestedNameSpecifier(),
8932494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                             T);
894dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8962fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// \brief Build a new pack expansion type.
8972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  ///
8982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// By default, builds a new PackExpansionType type from the given pattern.
8992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
9002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType RebuildPackExpansionType(QualType Pattern,
9012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                    SourceRange PatternRange,
902cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    SourceLocation EllipsisLoc,
903cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    llvm::Optional<unsigned> NumExpansions) {
904cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                        NumExpansions);
9062fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
9072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
908d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier, a flag
909d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// indicating whether the "template" keyword was provided, and the template
910d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// that the template name refers to.
911d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
912d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, builds the new template name directly. Subclasses may override
913d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// this routine to provide different behavior.
914fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
915d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   bool TemplateKW,
916d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   TemplateDecl *Template);
917d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
918d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier and the
919d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// name that is referred to as a template.
920d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
921d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
922d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
923d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// template name. Subclasses may override this routine to provide different
924d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// behavior.
925fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
926fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   const IdentifierInfo &Name,
927fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   SourceLocation NameLoc,
92843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   QualType ObjectType,
92943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   NamedDecl *FirstQualifierInScope);
9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
931ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// \brief Build a new template name given a nested name specifier and the
932ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// overloaded operator name that is referred to as a template.
933ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  ///
934ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// By default, performs semantic analysis to determine whether the name can
935ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
936ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// template name. Subclasses may override this routine to provide different
937ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// behavior.
938fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
939ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   OverloadedOperatorKind Operator,
940fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   SourceLocation NameLoc,
941ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   QualType ObjectType);
9421aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
9431aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// \brief Build a new template name given a template template parameter pack
9441aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// and the
9451aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  ///
9461aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
9471aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
9481aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// template name. Subclasses may override this routine to provide different
9491aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// behavior.
9501aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
9511aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                   const TemplateArgument &ArgPack) {
9521aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
9531aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  }
9541aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
95543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new compound statement.
95643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
95743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
95843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
95960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
96043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       MultiStmtArg Statements,
96143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       SourceLocation RBraceLoc,
96243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       bool IsStmtExpr) {
9639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
96443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       IsStmtExpr);
96543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
96643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
96743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new case statement.
96843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
96943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
97043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
97160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
9729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *LHS,
97343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EllipsisLoc,
9749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *RHS,
97543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation ColonLoc) {
9769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
97743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   ColonLoc);
97843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to a new case statement.
98143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
98243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
98343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
98460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
9859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().ActOnCaseStmtBody(S, Body);
9869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return S;
98743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new default statement.
99043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
99143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
99243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
99360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      SourceLocation ColonLoc,
9959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      Stmt *SubStmt) {
9969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      /*CurScope=*/0);
99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new label statement.
100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
100243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
100343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
100457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
100557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                              SourceLocation ColonLoc, Stmt *SubStmt) {
100657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new "if" statement.
101043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
101143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
101243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
101360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
101457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                           VarDecl *CondVar, Stmt *Then,
101557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                           SourceLocation ElseLoc, Stmt *Else) {
101644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis    return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
101743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Start building a new switch statement.
102043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
102143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
102243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
102360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
102457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                    Expr *Cond, VarDecl *CondVar) {
10259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1026d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                            CondVar);
102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to the switch statement.
103043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
103143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
103360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
103457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                   Stmt *Switch, Stmt *Body) {
10359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
103643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
103843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new while statement.
103943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
104043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
104143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
104257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
104357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                              VarDecl *CondVar, Stmt *Body) {
10449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
104543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
104743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new do-while statement.
104843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
104943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
105043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
105160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1052ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                           SourceLocation WhileLoc, SourceLocation LParenLoc,
1053ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                           Expr *Cond, SourceLocation RParenLoc) {
10549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
10559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Cond, RParenLoc);
105643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
105743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
105843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new for statement.
105943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
106043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
106143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1062ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1063ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            Stmt *Init, Sema::FullExprArg Cond,
1064ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            VarDecl *CondVar, Sema::FullExprArg Inc,
1065ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            SourceLocation RParenLoc, Stmt *Body) {
10669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1067ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                  CondVar, Inc, RParenLoc, Body);
106843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new goto statement.
107143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
107243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
107343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1074ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1075ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                             LabelDecl *Label) {
107657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
107743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
107843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
107943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new indirect goto statement.
108043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
108143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
108243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
108360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1084ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                     SourceLocation StarLoc,
1085ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                     Expr *Target) {
10869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
108743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new return statement.
109043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
109143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
109243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1093ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
10949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnReturnStmt(ReturnLoc, Result);
109543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
109743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new declaration statement.
109843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
109943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
110043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
110160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   SourceLocation StartLoc,
110343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EndLoc) {
1104406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith    Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1105406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith    return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
110643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1108703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// \brief Build a new inline asm statement.
1109703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  ///
1110703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// By default, performs semantic analysis to build the new statement.
1111703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// Subclasses may override this routine to provide different behavior.
111260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
1113703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsSimple,
1114703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool IsVolatile,
1115703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumOutputs,
1116703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  unsigned NumInputs,
1117ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson                                  IdentifierInfo **Names,
1118703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Constraints,
1119703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Exprs,
11209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Expr *AsmString,
1121703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  MultiExprArg Clobbers,
1122703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  SourceLocation RParenLoc,
1123703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  bool MSAsm) {
1124c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1125703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  NumInputs, Names, move(Constraints),
11269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                  Exprs, AsmString, Clobbers,
1127703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                  RParenLoc, MSAsm);
1128703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
11294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
11304dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @try statement.
11314dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
113460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
11359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *TryBody,
11368f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                        MultiStmtArg CatchStmts,
11379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *Finally) {
11389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
11399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Finally);
11404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
11414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
1142be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Rebuild an Objective-C exception declaration.
1143be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1144be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new declaration.
1145be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1146be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1147be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                    TypeSourceInfo *TInfo, QualType T) {
1148ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    return getSema().BuildObjCExceptionDecl(TInfo, T,
1149ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getInnerLocStart(),
1150ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getLocation(),
1151ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getIdentifier());
1152be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
1153c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1154be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Build a new Objective-C @catch statement.
1155be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1156be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1157be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
115860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1159be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          SourceLocation RParenLoc,
1160be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          VarDecl *Var,
11619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Stmt *Body) {
1162be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
11639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Var, Body);
1164be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
1165c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// \brief Build a new Objective-C @finally statement.
11674dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11694dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
117060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
11719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Stmt *Body) {
11729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
11734dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
1174c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11758fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @throw statement.
1176d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  ///
1177d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
1178d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
117960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
11809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Operand) {
11819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1182d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
1183c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11848fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// \brief Build a new Objective-C @synchronized statement.
11858fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  ///
11868fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
11878fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
118860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
11899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *Object,
11909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Stmt *Body) {
11919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
11929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Body);
11938fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  }
1194c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor
1195f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Build a new Objective-C @autoreleasepool statement.
1196f85e193739c953358c865005855253af4f68a497John McCall  ///
1197f85e193739c953358c865005855253af4f68a497John McCall  /// By default, performs semantic analysis to build the new statement.
1198f85e193739c953358c865005855253af4f68a497John McCall  /// Subclasses may override this routine to provide different behavior.
1199f85e193739c953358c865005855253af4f68a497John McCall  StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1200f85e193739c953358c865005855253af4f68a497John McCall                                            Stmt *Body) {
1201f85e193739c953358c865005855253af4f68a497John McCall    return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1202f85e193739c953358c865005855253af4f68a497John McCall  }
1203990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall
1204990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  /// \brief Build the collection operand to a new Objective-C fast
1205990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  /// enumeration statement.
1206990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  ///
1207990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  /// By default, performs semantic analysis to build the new statement.
1208990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  /// Subclasses may override this routine to provide different behavior.
1209990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1210990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall                                             Expr *collection) {
1211990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall    return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1212990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  }
1213f85e193739c953358c865005855253af4f68a497John McCall
1214c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// \brief Build a new Objective-C fast enumeration statement.
1215c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  ///
1216c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1217c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
121860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1219f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation LParenLoc,
1220f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Element,
1221f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Expr *Collection,
1222f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation RParenLoc,
1223f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Body) {
1224c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor    return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
12259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Element,
12269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Collection,
1227c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                RParenLoc,
12289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Body);
1229c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  }
1230c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
123143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ exception declaration.
123243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
123343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new decaration.
123443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1235ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1236a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                                TypeSourceInfo *Declarator,
1237ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                SourceLocation StartLoc,
1238ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                SourceLocation IdLoc,
1239ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                IdentifierInfo *Id) {
1240efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1241efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor                                                       StartLoc, IdLoc, Id);
1242efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    if (Var)
1243efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor      getSema().CurContext->addDecl(Var);
1244efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    return Var;
124543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
124643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
124743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ catch statement.
124843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
124943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
125043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
125160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1252f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 VarDecl *ExceptionDecl,
1253f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 Stmt *Handler) {
12549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
12559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Handler));
125643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
125843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ try statement.
125943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
126043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
126143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
126260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1263f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               Stmt *TryBlock,
1264f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               MultiStmtArg Handlers) {
12659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
126643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1268ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// \brief Build a new C++0x range-based for statement.
1269ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ///
1270ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// By default, performs semantic analysis to build the new statement.
1271ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// Subclasses may override this routine to provide different behavior.
1272ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1273ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    SourceLocation ColonLoc,
1274ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Stmt *Range, Stmt *BeginEnd,
1275ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Expr *Cond, Expr *Inc,
1276ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Stmt *LoopVar,
1277ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    SourceLocation RParenLoc) {
1278ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1279ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                          Cond, Inc, LoopVar, RParenLoc);
1280ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
1281ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
1282ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// \brief Attach body to a C++0x range-based for statement.
1283ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ///
1284ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// By default, performs semantic analysis to finish the new statement.
1285ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// Subclasses may override this routine to provide different behavior.
1286ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1287ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return getSema().FinishCXXForRangeStmt(ForRange, Body);
1288ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
1289ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
129028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHTryStmt(bool IsCXXTry,
129128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation TryLoc,
129228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *TryBlock,
129328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Handler) {
129428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
129528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
129628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
129728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
129828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                  Expr *FilterExpr,
129928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                  Stmt *Block) {
130028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
130128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
130228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
130328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
130428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                   Stmt *Block) {
130528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHFinallyBlock(Loc,Block);
130628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
130728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression that references a declaration.
1309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
131260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1313f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        LookupResult &R,
1314f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        bool RequiresADL) {
1315f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1316f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1317f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1318f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1319f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Build a new expression that references a declaration.
1320f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  ///
1321f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// By default, performs semantic analysis to build the new expression.
1322f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Subclasses may override this routine to provide different behavior.
132340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1324f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                ValueDecl *VD,
1325f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                const DeclarationNameInfo &NameInfo,
1326f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                TemplateArgumentListInfo *TemplateArgs) {
1327a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    CXXScopeSpec SS;
132840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    SS.Adopt(QualifierLoc);
1329dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
1330dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: loses template args.
13312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
13322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression in parentheses.
13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
133960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                    SourceLocation RParen) {
13419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1344a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Build a new pseudo-destructor expression.
13451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1346a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1347a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
134860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1349f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation OperatorLoc,
1350f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            bool isArrow,
1351f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            CXXScopeSpec &SS,
1352f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            TypeSourceInfo *ScopeType,
1353f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation CCLoc,
1354f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation TildeLoc,
1355a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed);
13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary operator expression.
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
136160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
13622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                        UnaryOperatorKind Opc,
13639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *SubExpr) {
13649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
13661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build a new builtin offsetof expression.
13688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
13708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
137160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
13728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       TypeSourceInfo *Type,
1373f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                       Sema::OffsetOfComponent *Components,
13748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       unsigned NumComponents,
13758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       SourceLocation RParenLoc) {
13768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
13778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          NumComponents, RParenLoc);
13788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1379c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1380f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// \brief Build a new sizeof, alignof or vec_step expression with a
1381f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// type argument.
13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1385f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1386f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceLocation OpLoc,
1387f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         UnaryExprOrTypeTrait ExprKind,
1388f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceRange R) {
1389f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1392f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// \brief Build a new sizeof, alignof or vec step expression with an
1393f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// expression argument.
13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1397f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1398f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         UnaryExprOrTypeTrait ExprKind,
1399f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceRange R) {
140060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1401e72c55b9a11be9f00fa3f66f7ad6b73b2814e963Chandler Carruth      = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1403f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
14041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new array subscript expression.
14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
141260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1413b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LBracketLoc,
14149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *RHS,
1415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RBracketLoc) {
14169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
14179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             LBracketLoc, RHS,
1418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             RBracketLoc);
1419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new call expression.
14221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
142560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1426b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Args,
1427e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   SourceLocation RParenLoc,
1428e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   Expr *ExecConfig = 0) {
14299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
1430e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   move(Args), RParenLoc, ExecConfig);
1431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member access expression.
14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
143760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1438f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               bool isArrow,
143940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                               NestedNameSpecifierLoc QualifierLoc,
1440f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               const DeclarationNameInfo &MemberNameInfo,
1441f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               ValueDecl *Member,
1442f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FoundDecl,
1443d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                        const TemplateArgumentListInfo *ExplicitTemplateArgs,
1444f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FirstQualifierInScope) {
1445d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    if (!Member->getDeclName()) {
1446f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // We have a reference to an unnamed field.  This is always the
1447f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // base of an anonymous struct/union member access, i.e. the
1448f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // field is always of record type.
144940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1450f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      assert(Member->getType()->isRecordType() &&
1451f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             "unnamed member not of record type?");
14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1453429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      ExprResult BaseResult =
1454429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley        getSema().PerformObjectMemberConversion(Base,
1455429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                                QualifierLoc.getNestedNameSpecifier(),
1456429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                                FoundDecl, Member);
1457429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      if (BaseResult.isInvalid())
1458f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
1459429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      Base = BaseResult.take();
1460f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      MemberExpr *ME =
14629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        new (getSema().Context) MemberExpr(Base, isArrow,
14632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           Member, MemberNameInfo,
1464f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           cast<FieldDecl>(Member)->getType(),
1465f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           VK, OK_Ordinary);
1466d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      return getSema().Owned(ME);
1467d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    }
14681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    CXXScopeSpec SS;
147040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    SS.Adopt(QualifierLoc);
147183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
1472429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1473429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (BaseResult.isInvalid())
1474429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      return ExprError();
1475429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    Base = BaseResult.take();
14769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    QualType BaseType = Base->getType();
1477aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
14786bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // FIXME: this involves duplicating earlier analysis in a lot of
14796bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // cases; we should avoid this when possible.
14802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
14816bb8017bb9e828d118e15e59d71c66bba323c364John McCall    R.addDecl(FoundDecl);
1482c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    R.resolveKind();
1483c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
14849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1485129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, FirstQualifierInScope,
1486c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                              R, ExplicitTemplateArgs);
1487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new binary operator expression.
14901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
149360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
14942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                         BinaryOperatorKind Opc,
14959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *LHS, Expr *RHS) {
14969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new conditional operator expression.
15001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
150360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildConditionalOperator(Expr *Cond,
150456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        SourceLocation QuestionLoc,
150556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        Expr *LHS,
150656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        SourceLocation ColonLoc,
150756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        Expr *RHS) {
15089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
15099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        LHS, RHS);
1510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C-style cast expression.
15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
151660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
15179d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                         TypeSourceInfo *TInfo,
1518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc,
15199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *SubExpr) {
1520b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall    return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
15219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubExpr);
1522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new compound literal expression.
15251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
152860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
152942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall                                              TypeSourceInfo *TInfo,
1530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation RParenLoc,
15319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Init) {
153242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
15339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Init);
1534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new extended vector element access expression.
15371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
154060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildExtVectorElementExpr(Expr *Base,
1541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation OpLoc,
1542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation AccessorLoc,
1543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               IdentifierInfo &Accessor) {
1544aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
1545129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    CXXScopeSpec SS;
15462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
15479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1548129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              OpLoc, /*IsArrow*/ false,
1549129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              SS, /*FirstQualifierInScope*/ 0,
15502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                              NameInfo,
1551129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              /* TemplateArgs */ 0);
1552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new initializer list expression.
15551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
155860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildInitList(SourceLocation LBraceLoc,
1559c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             MultiExprArg Inits,
1560c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             SourceLocation RBraceLoc,
1561c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             QualType ResultTy) {
156260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1563e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1564e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    if (Result.isInvalid() || ResultTy->isDependentType())
1565e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor      return move(Result);
1566c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1567e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // Patch in the result type we were given, which may have been computed
1568e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // when the initial InitListExpr was built.
1569e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1570e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    ILE->setType(ResultTy);
1571e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    return move(Result);
1572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new designated initializer expression.
15751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
157860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             MultiExprArg ArrayExprs,
1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation EqualOrColonLoc,
1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             bool GNUSyntax,
15829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *Init) {
158360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
15859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Init);
1586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1587f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.release();
1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return move(Result);
1591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new value-initialized expression.
15941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds the implicit value initialization without performing
1596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// any semantic analysis. Subclasses may override this routine to provide
1597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
159860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildImplicitValueInitExpr(QualType T) {
1599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new \c va_arg expression.
16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
160660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
16079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SubExpr, TypeSourceInfo *TInfo,
16082cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    SourceLocation RParenLoc) {
16092cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara    return getSema().BuildVAArgExpr(BuiltinLoc,
16109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    SubExpr, TInfo,
16112cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    RParenLoc);
1612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression list in parentheses.
16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
161860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        MultiExprArg SubExprs,
1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1621c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1622f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian                                               move(SubExprs));
1623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new address-of-label expression.
16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis, using the name of the label
1628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// rather than attempting to map the label statement itself.
1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
163060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1631ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                  SourceLocation LabelLoc, LabelDecl *Label) {
163257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
1633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new GNU statement expression.
16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
163960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
16409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Stmt *SubStmt,
1641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
16429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new __builtin_choose_expr expression.
1646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
164960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
16509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Cond, Expr *LHS, Expr *RHS,
1651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                     SourceLocation RParenLoc) {
1652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.ActOnChooseExpr(BuiltinLoc,
16539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Cond, LHS, RHS,
1654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   RParenLoc);
1655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1657f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// \brief Build a new generic selection expression.
1658f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ///
1659f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// By default, performs semantic analysis to build the new expression.
1660f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// Subclasses may override this routine to provide different behavior.
1661f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1662f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         SourceLocation DefaultLoc,
1663f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         SourceLocation RParenLoc,
1664f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         Expr *ControllingExpr,
1665f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         TypeSourceInfo **Types,
1666f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         Expr **Exprs,
1667f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         unsigned NumAssocs) {
1668f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1669f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                ControllingExpr, Types, Exprs,
1670f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                NumAssocs);
1671f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
1672f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new overloaded operator call expression.
1674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// The semantic analysis provides the behavior of template instantiation,
1677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// copying with transformations that turn what looks like an overloaded
16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// operator call into a use of a builtin operator, performing
1679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument-dependent lookup, etc. Subclasses may override this routine to
1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
168160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation OpLoc,
16839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Callee,
16849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *First,
16859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Second);
16861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++ "named" cast expression, such as static_cast or
1688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// reinterpret_cast.
1689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine dispatches to one of the more-specific routines
16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
169360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           Stmt::StmtClass Class,
1695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
16969d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
16999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    switch (Class) {
1702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXStaticCastExprClass:
17039d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
17059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
1706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXDynamicCastExprClass:
17089d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                    RAngleLoc, LParenLoc,
17109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    SubExpr, RParenLoc);
17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXReinterpretCastExprClass:
17139d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                        RAngleLoc, LParenLoc,
17159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                        SubExpr,
1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        RParenLoc);
17171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXConstCastExprClass:
17199d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
17201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
17219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
17221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    default:
1724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      assert(false && "Invalid C++ named cast");
1725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      break;
1726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
17271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1728f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
1729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ static_cast expression.
1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
173560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LAngleLoc,
17379d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                            TypeSourceInfo *TInfo,
1738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RAngleLoc,
1739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LParenLoc,
17409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Expr *SubExpr,
1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RParenLoc) {
1742c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
17439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1744c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1745c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ dynamic_cast expression.
1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
175260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LAngleLoc,
17549d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                             TypeSourceInfo *TInfo,
1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RAngleLoc,
1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LParenLoc,
17579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *SubExpr,
1758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RParenLoc) {
1759c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
17609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1761c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1762c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ reinterpret_cast expression.
1766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
176960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LAngleLoc,
17719d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                                 TypeSourceInfo *TInfo,
1772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RAngleLoc,
1773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LParenLoc,
17749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SubExpr,
1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RParenLoc) {
1776c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
17779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1778c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1779c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ const_cast expression.
1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
178660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
17889d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
17919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1793c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
17949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1795c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1796c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ functional-style cast expression.
1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1803ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1804ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation LParenLoc,
1805ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          Expr *Sub,
1806ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation RParenLoc) {
1807ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1808f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                               MultiExprArg(&Sub, 1),
1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(type) expression.
1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
181660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
181757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
181857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        TypeSourceInfo *Operand,
1819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
1820c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
182157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
1822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
182401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(expr) expression.
1826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
182960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
183057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
18319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand,
1832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
18339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
183457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
183701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(type) expression.
183801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
183901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
184001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
184101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
184201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
184301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        TypeSourceInfo *Operand,
184401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
184501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
184601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
184701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
184801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
184901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(expr) expression.
185001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
185101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
185201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
185301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
185401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
185501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        Expr *Operand,
185601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
185701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
185801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
185901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
186001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "this" expression.
1862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new "this" expression without performing any
18641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// semantic analysis. Subclasses may override this routine to provide
1865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
186660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1867ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                QualType ThisType,
1868ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                bool isImplicit) {
1869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().Owned(
1870828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                      new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1871828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                                                          isImplicit));
1872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ throw expression.
1875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1878bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1879bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor                                 bool IsThrownVariableInScope) {
1880bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor    return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
1881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ default-argument expression.
1884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new default-argument expression, which does not
1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// require any semantic analysis. Subclasses may override this routine to
1887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
188860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1889036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                            ParmVarDecl *Param) {
1890036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1891036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                                     Param));
1892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ zero-initialization expression.
1895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1898ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1899ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1900ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1901ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
19021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                               MultiExprArg(getSema(), 0, 0),
1903ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               RParenLoc);
1904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "new" expression.
1907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
191060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
19111bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               bool UseGlobal,
19121bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementLParen,
19131bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg PlacementArgs,
19141bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementRParen,
19151bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceRange TypeIdParens,
19161bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               QualType AllocatedType,
19171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               TypeSourceInfo *AllocatedTypeInfo,
19181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               Expr *ArraySize,
19191bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorLParen,
19201bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg ConstructorArgs,
19211bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation ConstructorRParen) {
19221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getSema().BuildCXXNew(StartLoc, UseGlobal,
1923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementLParen,
1924b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(PlacementArgs),
1925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementRParen,
19264bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                 TypeIdParens,
19271bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedType,
19281bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedTypeInfo,
19299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 ArraySize,
1930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorLParen,
1931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 move(ConstructorArgs),
1932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 ConstructorRParen);
1933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "delete" expression.
1936b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
193960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsGlobalDelete,
1941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsArrayForm,
19429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand) {
1943b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
19449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Operand);
1945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary type trait expression.
1948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
195160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
19523d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation StartLoc,
19533d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   TypeSourceInfo *T,
19543d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation RParenLoc) {
19553d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor    return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
1956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
19586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// \brief Build a new binary type trait expression.
19596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ///
19606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// By default, performs semantic analysis to build the new expression.
19616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Subclasses may override this routine to provide different behavior.
19626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
19636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation StartLoc,
19646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *LhsT,
19656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *RhsT,
19666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation RParenLoc) {
19676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
19686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
19696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
197021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// \brief Build a new array type trait expression.
197121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ///
197221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// By default, performs semantic analysis to build the new expression.
197321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// Subclasses may override this routine to provide different behavior.
197421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
197521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   SourceLocation StartLoc,
197621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   TypeSourceInfo *TSInfo,
197721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   Expr *DimExpr,
197821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   SourceLocation RParenLoc) {
197921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
198021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
198121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
1982552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// \brief Build a new expression trait expression.
1983552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ///
1984552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// By default, performs semantic analysis to build the new expression.
1985552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// Subclasses may override this routine to provide different behavior.
1986552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1987552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   SourceLocation StartLoc,
1988552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   Expr *Queried,
1989552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   SourceLocation RParenLoc) {
1990552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1991552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
1992552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
19931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new (previously unresolved) declaration reference
1994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// expression.
1995b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1997b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
199800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  ExprResult RebuildDependentScopeDeclRefExpr(
199900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
20002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                       const DeclarationNameInfo &NameInfo,
2001f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
2002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
200300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    SS.Adopt(QualifierLoc);
2004f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2005f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (TemplateArgs)
20062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
2007f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                    *TemplateArgs);
2008f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
20092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
2010b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new template-id expression.
2013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
201660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2017f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         LookupResult &R,
2018f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                         bool RequiresADL,
2019d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                              const TemplateArgumentListInfo &TemplateArgs) {
2020f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
2021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
202760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstructExpr(QualType T,
20284411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                           SourceLocation Loc,
2029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           CXXConstructorDecl *Constructor,
2030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           bool IsElidable,
20318c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           MultiExprArg Args,
20328c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           bool RequiresZeroInit,
2033428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                             CXXConstructExpr::ConstructionKind ConstructKind,
2034428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           SourceRange ParenRange) {
2035ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
2036c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
20374411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                          ConvertedArgs))
2038f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2039c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
20404411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor    return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
20418c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                           move_arg(ConvertedArgs),
2042428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           RequiresZeroInit, ConstructKind,
2043428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           ParenRange);
2044b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2046b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
2050ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2051ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
2052ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           MultiExprArg Args,
2053ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
2054ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
2055b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
2056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
2057b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
2058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2059b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2060b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2062b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2063b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
2064ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2065ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation LParenLoc,
2066ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               MultiExprArg Args,
2067ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation RParenLoc) {
2068ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
2069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
2070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move(Args),
2071b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
2072b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2074b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member reference expression.
2075b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2077b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
207860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
20797c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                QualType BaseType,
20807c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                bool IsArrow,
20817c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                SourceLocation OperatorLoc,
20827c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
2083129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            NamedDecl *FirstQualifierInScope,
20842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                   const DeclarationNameInfo &MemberNameInfo,
2085129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
2086b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
20877c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    SS.Adopt(QualifierLoc);
20881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2090aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
2091129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            SS, FirstQualifierInScope,
20922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            MemberNameInfo,
20932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            TemplateArgs);
2094b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2096129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Build a new member reference expression.
20973b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  ///
20983b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
20993b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
210060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
2101aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                               QualType BaseType,
2102129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               SourceLocation OperatorLoc,
2103129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               bool IsArrow,
21044c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
2105c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                               NamedDecl *FirstQualifierInScope,
2106129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                               LookupResult &R,
2107129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                const TemplateArgumentListInfo *TemplateArgs) {
21083b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    CXXScopeSpec SS;
21094c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    SS.Adopt(QualifierLoc);
21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2112aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
2113c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            SS, FirstQualifierInScope,
2114c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            R, TemplateArgs);
21153b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
21161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21172e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// \brief Build a new noexcept expression.
21182e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ///
21192e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// By default, performs semantic analysis to build the new expression.
21202e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// Subclasses may override this routine to provide different behavior.
21212e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
21222e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
21232e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
21242e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2125ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Build a new expression to compute the length of a parameter pack.
2126ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2127ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation PackLoc,
2128ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation RParenLoc,
2129ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   unsigned Length) {
2130ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2131ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                                OperatorLoc, Pack, PackLoc,
2132ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                                RParenLoc, Length);
2133ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2134ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new Objective-C @encode expression.
2136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
213960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
214081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                         TypeSourceInfo *EncodeTypeInfo,
2141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc) {
214281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                           RParenLoc));
21441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
2145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
214692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C class message.
214760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
214892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2149f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                          SourceLocation SelectorLoc,
215092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
2151c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
215292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
215392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
215492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return SemaRef.BuildClassMessage(ReceiverTypeInfo,
215592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     ReceiverTypeInfo->getType(),
215692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     /*SuperLoc=*/SourceLocation(),
2157f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                     Sel, Method, LBracLoc, SelectorLoc,
2158f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                     RBracLoc, move(Args));
215992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
216092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
216192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C instance message.
216260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(Expr *Receiver,
216392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2164f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                          SourceLocation SelectorLoc,
216592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
2166c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                          SourceLocation LBracLoc,
216792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
216892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
21699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildInstanceMessage(Receiver,
21709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Receiver->getType(),
217192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        /*SuperLoc=*/SourceLocation(),
2172f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                        Sel, Method, LBracLoc, SelectorLoc,
2173f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                        RBracLoc, move(Args));
217492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
217592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
2176f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C ivar reference expression.
2177f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2178f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2179f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
218060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2181f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          SourceLocation IvarLoc,
2182f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          bool IsArrow, bool IsFreeIvar) {
2183f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    // FIXME: We lose track of the IsFreeIvar bit.
2184f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
2185429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2186f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2187f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
218860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2189f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IvarLoc,
2190d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0,
2191ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall                                                         false);
2192429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2193f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2195f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
2196f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
2197c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2198429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2199c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IvarLoc, IsArrow, SS,
2200f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
2201c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2202f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2203f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2204e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor
2205e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// \brief Build a new Objective-C property reference expression.
2206e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  ///
2207e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2208e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
220960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
2210e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              ObjCPropertyDecl *Property,
2211e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              SourceLocation PropertyLoc) {
2212e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    CXXScopeSpec SS;
2213429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2214e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2215e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                   Sema::LookupMemberName);
2216e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    bool IsArrow = false;
221760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2218e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                                         /*FIME:*/PropertyLoc,
2219d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2220429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2221f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2222c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2223e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.get())
2224e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      return move(Result);
2225c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2226429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2227c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/PropertyLoc, IsArrow,
2228c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              SS,
2229e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*FirstQualifierInScope=*/0,
2230c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2231e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*TemplateArgs=*/0);
2232e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  }
2233c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
223412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// \brief Build a new Objective-C property reference expression.
22359cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  ///
22369cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
223712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// Subclasses may override this routine to provide different behavior.
223812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
223912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Getter,
224012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Setter,
224112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        SourceLocation PropertyLoc) {
224212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // Since these expressions can only be value-dependent, we do not
224312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // need to perform semantic analysis again.
224412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return Owned(
224512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
224612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  VK_LValue, OK_ObjCProperty,
224712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  PropertyLoc, Base));
22489cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  }
22499cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor
2250f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C "isa" expression.
2251f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2252f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2253f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
225460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2255f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                      bool IsArrow) {
2256f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
2257429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2258f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2259f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
226060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2261f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IsaLoc,
2262d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2263429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2264f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
2265c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2266f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
2267f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      return move(Result);
2268c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2269429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2270c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              /*FIXME:*/IsaLoc, IsArrow, SS,
2271f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
2272c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                              R,
2273f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2274f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2275c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new shuffle vector expression.
2277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
228060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2281f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      MultiExprArg SubExprs,
2282f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      SourceLocation RParenLoc) {
2283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Find the declaration for __builtin_shufflevector
22841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const IdentifierInfo &Name
2285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.Context.Idents.get("__builtin_shufflevector");
2286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
22891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2290b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Build a reference to the __builtin_shufflevector builtin
2291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
2292429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Callee
2293429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2294429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                                        VK_LValue, BuiltinLoc));
2295429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    Callee = SemaRef.UsualUnaryConversions(Callee.take());
2296429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Callee.isInvalid())
2297429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      return ExprError();
22981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Build the CallExpr
2300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    unsigned NumSubExprs = SubExprs.size();
2301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Expr **Subs = (Expr **)SubExprs.release();
2302429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult TheCall = SemaRef.Owned(
2303429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
2304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                       Subs, NumSubExprs,
23055291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor                                                   Builtin->getCallResultType(),
2306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            Expr::getValueKindForType(Builtin->getResultType()),
2307429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                     RParenLoc));
23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Type-check the __builtin_shufflevector expression.
2310429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
2311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
231243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
23138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Build a new template argument pack expansion.
23148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
23158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
23168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// for a template argument. Subclasses may override this routine to provide
23178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// different behavior.
23188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2319cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           SourceLocation EllipsisLoc,
2320cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
23218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    switch (Pattern.getArgument().getKind()) {
23227a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    case TemplateArgument::Expression: {
23237a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      ExprResult Result
232467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
232567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                       EllipsisLoc, NumExpansions);
23267a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      if (Result.isInvalid())
23277a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor        return TemplateArgumentLoc();
23287a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor
23297a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      return TemplateArgumentLoc(Result.get(), Result.get());
23307a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    }
2331dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
23328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Template:
2333a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor      return TemplateArgumentLoc(TemplateArgument(
2334a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                          Pattern.getArgument().getAsTemplate(),
23352be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor                                                  NumExpansions),
2336b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                 Pattern.getTemplateQualifierLoc(),
2337a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 Pattern.getTemplateNameLoc(),
2338a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 EllipsisLoc);
23398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
23408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Null:
23418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Integral:
23428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Declaration:
23438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Pack:
2344a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    case TemplateArgument::TemplateExpansion:
23458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm_unreachable("Pack expansion pattern has no parameter packs");
23468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
23478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Type:
23488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (TypeSourceInfo *Expansion
23498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor            = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2350cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           EllipsisLoc,
2351cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           NumExpansions))
23528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
23538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                   Expansion);
23548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      break;
23558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
23568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
23578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return TemplateArgumentLoc();
23588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
23598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
2360dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// \brief Build a new expression pack expansion.
2361dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  ///
2362dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
2363dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// for an expression. Subclasses may override this routine to provide
2364dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// different behavior.
236567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
236667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                  llvm::Optional<unsigned> NumExpansions) {
236767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2368dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  }
2369dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
237043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate:
2371c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2372c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     QualType ObjectType,
2373c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     NamedDecl *FirstQualifierInScope,
2374c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     CXXScopeSpec &SS);
2375b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
2376b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2377b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             QualType ObjectType,
2378b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             NamedDecl *FirstQualifierInScope,
2379b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             CXXScopeSpec &SS);
2380577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor};
2381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
238243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
238360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
238443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!S)
238543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return SemaRef.Owned(S);
23861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
238743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  switch (S->getStmtClass()) {
238843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::NoStmtClass: break;
23891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
239043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform individual statement nodes
239143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                                              \
239243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
239363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node)
239443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent)
23954bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
23961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
239743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform expressions by calling TransformExpr.
239843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)
23997381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
240043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class:
24014bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
240243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    {
240360d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
240443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      if (E.isInvalid())
2405f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
24061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
240843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    }
24091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
24101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
241243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
24131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2415670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived>
241660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!E)
2418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(E);
2419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  switch (E->getStmtClass()) {
2421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::NoStmtClass: break;
2422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break;
24237381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
2424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                                              \
2425454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall    case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
24264bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
24271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
24281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
2430657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor}
2431657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor
2432657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived>
2433aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2434aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            unsigned NumInputs,
2435aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool IsCall,
2436686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                      SmallVectorImpl<Expr *> &Outputs,
2437aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool *ArgChanged) {
2438aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  for (unsigned I = 0; I != NumInputs; ++I) {
2439aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    // If requested, drop call arguments that need to be dropped.
2440aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2441aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      if (ArgChanged)
2442aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor        *ArgChanged = true;
2443aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2444aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      break;
2445aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    }
2446aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2447dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2448dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      Expr *Pattern = Expansion->getPattern();
2449dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2450686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2451dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2452dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2453dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2454dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
2455dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // be expanded.
2456dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      bool Expand = true;
2457d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
245867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> OrigNumExpansions
245967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = Expansion->getNumExpansions();
246067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
2461dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2462dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Pattern->getSourceRange(),
2463dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Unexpanded.data(),
2464dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Unexpanded.size(),
2465d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand, RetainExpansion,
2466d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
2467dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        return true;
2468dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2469dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (!Expand) {
2470dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // The transform has determined that we should perform a simple
2471dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // transformation on the pack expansion, producing another pack
2472dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // expansion.
2473dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2474dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2475dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (OutPattern.isInvalid())
2476dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2477dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2478dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
247967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                Expansion->getEllipsisLoc(),
248067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                           NumExpansions);
2481dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2482dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2483dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2484dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (ArgChanged)
2485dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          *ArgChanged = true;
2486dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2487dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        continue;
2488dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2489c8fc90a854b4ccba21c85884676a80334159dd94John McCall
2490c8fc90a854b4ccba21c85884676a80334159dd94John McCall      // Record right away that the argument was changed.  This needs
2491c8fc90a854b4ccba21c85884676a80334159dd94John McCall      // to happen even if the array expands to nothing.
2492c8fc90a854b4ccba21c85884676a80334159dd94John McCall      if (ArgChanged) *ArgChanged = true;
2493dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2494dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // The transform has determined that we should perform an elementwise
2495dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // expansion of the pattern. Do so.
2496cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
2497dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2498dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().TransformExpr(Pattern);
2499dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2500dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2501dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
250277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.get()->containsUnexpandedParameterPack()) {
250367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor          Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
250467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                     OrigNumExpansions);
250577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.isInvalid())
250677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
250777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
250877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
2509dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2510dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2511dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2512dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      continue;
2513dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    }
2514dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
2515aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2516aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.isInvalid())
2517aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return true;
2518aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2519aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.get() != Inputs[I] && ArgChanged)
2520aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      *ArgChanged = true;
2521aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2522aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    Outputs.push_back(Result.get());
2523aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
2524aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2525aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  return false;
2526aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor}
2527aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2528aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived>
2529c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc
2530c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2531c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                    NestedNameSpecifierLoc NNS,
2532c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                     QualType ObjectType,
2533c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                             NamedDecl *FirstQualifierInScope) {
2534686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2535c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2536c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor       Qualifier = Qualifier.getPrefix())
2537c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Qualifiers.push_back(Qualifier);
2538c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2539c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  CXXScopeSpec SS;
2540c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  while (!Qualifiers.empty()) {
2541c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2542c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2543c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2544c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    switch (QNNS->getKind()) {
2545c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Identifier:
2546c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2547c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              *QNNS->getAsIdentifier(),
2548c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              Q.getLocalBeginLoc(),
2549c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              Q.getLocalEndLoc(),
2550c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              ObjectType, false, SS,
2551c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              FirstQualifierInScope, false))
2552c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        return NestedNameSpecifierLoc();
2553c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2554c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2555c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2556c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Namespace: {
2557c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      NamespaceDecl *NS
2558c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        = cast_or_null<NamespaceDecl>(
2559c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                    getDerived().TransformDecl(
2560c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                          Q.getLocalBeginLoc(),
2561c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                       QNNS->getAsNamespace()));
2562c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2563c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2564c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
2565c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2566c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::NamespaceAlias: {
2567c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      NamespaceAliasDecl *Alias
2568c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        = cast_or_null<NamespaceAliasDecl>(
2569c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                      getDerived().TransformDecl(Q.getLocalBeginLoc(),
2570c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                 QNNS->getAsNamespaceAlias()));
2571c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2572c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                Q.getLocalEndLoc());
2573c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2574c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
2575c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2576c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Global:
2577c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      // There is no meaningful transformation that one could perform on the
2578c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      // global scope.
2579c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2580c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2581c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2582c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::TypeSpecWithTemplate:
2583c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::TypeSpec: {
2584c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2585c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              FirstQualifierInScope, SS);
2586c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2587c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (!TL)
2588c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        return NestedNameSpecifierLoc();
2589c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2590c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2591c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor          (SemaRef.getLangOptions().CPlusPlus0x &&
2592c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor           TL.getType()->isEnumeralType())) {
2593c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        assert(!TL.getType().hasLocalQualifiers() &&
2594c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor               "Can't get cv-qualifiers here");
2595c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2596c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                  Q.getLocalEndLoc());
2597c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        break;
2598c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      }
259900c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      // If the nested-name-specifier is an invalid type def, don't emit an
260000c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      // error because a previous error should have already been emitted.
260100c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
260200c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
260300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu        SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
260400c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu          << TL.getType() << SS.getRange();
260500c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      }
2606c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      return NestedNameSpecifierLoc();
2607c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
26087c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    }
2609c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
26107c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    // The qualifier-in-scope and object type only apply to the leftmost entity.
2611c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    FirstQualifierInScope = 0;
26127c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    ObjectType = QualType();
2613c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  }
2614c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2615c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // Don't rebuild the nested-name-specifier if we don't have to.
2616c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2617c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      !getDerived().AlwaysRebuild())
2618c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    return NNS;
2619c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2620c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // If we can re-use the source-location data from the original
2621c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // nested-name-specifier, do so.
2622c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (SS.location_size() == NNS.getDataLength() &&
2623c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2624c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2625c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2626c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // Allocate new nested-name-specifier location information.
2627c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  return SS.getWithLocInContext(SemaRef.Context);
2628c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor}
2629c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2630c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived>
26312577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo
26322577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived>
263343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
26342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name = NameInfo.getName();
263581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  if (!Name)
26362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo();
263781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
263881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  switch (Name.getNameKind()) {
263981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::Identifier:
264081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCZeroArgSelector:
264181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCOneArgSelector:
264281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCMultiArgSelector:
264381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXOperatorName:
26443e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  case DeclarationName::CXXLiteralOperatorName:
264581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXUsingDirective:
26462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NameInfo;
26471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
264881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConstructorName:
264981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXDestructorName:
265081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConversionFunctionName: {
26512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *NewTInfo;
26522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CanQualType NewCanTy;
26532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
265443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewTInfo = getDerived().TransformType(OldTInfo);
265543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NewTInfo)
265643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall        return DeclarationNameInfo();
265743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
26582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
26592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    else {
26602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewTInfo = 0;
26612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
266243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      QualType NewT = getDerived().TransformType(Name.getCXXNameType());
26632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      if (NewT.isNull())
26642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        return DeclarationNameInfo();
26652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewCanTy = SemaRef.Context.getCanonicalType(NewT);
26662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
26671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationName NewName
26692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
26702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                           NewCanTy);
26712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NewNameInfo(NameInfo);
26722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setName(NewName);
26732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setNamedTypeInfo(NewTInfo);
26742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NewNameInfo;
267581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  }
26761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
26771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  assert(0 && "Unknown name kind.");
26792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return DeclarationNameInfo();
268081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor}
268181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
268281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived>
26831eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
2684fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2685fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              TemplateName Name,
2686fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              SourceLocation NameLoc,
2687fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              QualType ObjectType,
2688fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              NamedDecl *FirstQualifierInScope) {
2689fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2690fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *Template = QTN->getTemplateDecl();
2691fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    assert(Template && "qualified template name must refer to a template");
2692fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2693fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *TransTemplate
2694fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2695fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                                              Template));
2696fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransTemplate)
2697fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2698fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2699fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2700fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        SS.getScopeRep() == QTN->getQualifier() &&
2701fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransTemplate == Template)
2702fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2703fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2704fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2705fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            TransTemplate);
2706fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2707fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2708fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2709fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (SS.getScopeRep()) {
2710fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      // These apply to the scope specifier, not the template.
2711fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      ObjectType = QualType();
2712fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      FirstQualifierInScope = 0;
2713fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    }
2714fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2715fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2716fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        SS.getScopeRep() == DTN->getQualifier() &&
2717fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        ObjectType.isNull())
2718fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2719fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2720fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (DTN->isIdentifier()) {
2721fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return getDerived().RebuildTemplateName(SS,
2722fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              *DTN->getIdentifier(),
2723fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              NameLoc,
2724fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              ObjectType,
2725fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              FirstQualifierInScope);
2726fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    }
2727fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2728fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2729fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            ObjectType);
2730fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2731fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2732fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2733fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *TransTemplate
2734fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2735fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                                              Template));
2736fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransTemplate)
2737fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2738fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2739fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2740fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransTemplate == Template)
2741fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2742fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2743fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return TemplateName(TransTemplate);
2744fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2745fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2746fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (SubstTemplateTemplateParmPackStorage *SubstPack
2747fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = Name.getAsSubstTemplateTemplateParmPack()) {
2748fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateTemplateParmDecl *TransParam
2749fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    = cast_or_null<TemplateTemplateParmDecl>(
2750fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor            getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2751fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransParam)
2752fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
2753fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2754fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2755fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransParam == SubstPack->getParameterPack())
2756fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
2757fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2758fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(TransParam,
2759fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SubstPack->getArgumentPack());
2760fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
2761fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2762fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  // These should be getting filtered out before they reach the AST.
2763fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  llvm_unreachable("overloaded function decl survived to here");
2764fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  return TemplateName();
2765fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor}
2766fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2767fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived>
2768833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc(
2769833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgument &Arg,
2770833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2771833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation Loc = getDerived().getBaseLocation();
2772670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  switch (Arg.getKind()) {
2773670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Null:
27749f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("null template argument in TreeTransform");
2775833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2776833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2777833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
2778833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg,
2779a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall               SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
2780c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2781833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2782833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2783788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
2784b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor  case TemplateArgument::TemplateExpansion: {
2785b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    NestedNameSpecifierLocBuilder Builder;
2786b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    TemplateName Template = Arg.getAsTemplate();
2787b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2788b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2789b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2790b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2791b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
2792b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (Arg.getKind() == TemplateArgument::Template)
2793b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Output = TemplateArgumentLoc(Arg,
2794b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Builder.getWithLocInContext(SemaRef.Context),
2795b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Loc);
2796b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    else
2797b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Output = TemplateArgumentLoc(Arg,
2798b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Builder.getWithLocInContext(SemaRef.Context),
2799b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Loc, Loc);
2800b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
2801a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    break;
2802b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor  }
2803a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2804833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
2805833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2806833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2807833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2808833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
2809670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Integral:
2810833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
2811828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2812833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2813833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
2814833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
2815833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2816833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived>
2817833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument(
2818833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgumentLoc &Input,
2819833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2820833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgument &Arg = Input.getArgument();
2821833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
2822833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
2823833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
2824833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = Input;
2825833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
28261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2827670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Type: {
2828a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *DI = Input.getTypeSourceInfo();
2829833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (DI == NULL)
2830a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall      DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2831833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2832833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    DI = getDerived().TransformType(DI);
2833833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!DI) return true;
2834833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2835833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2836833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2837670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2839670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Declaration: {
2840833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // FIXME: we should never have to transform one of these.
2841972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    DeclarationName Name;
2842972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2843972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor      Name = ND->getDeclName();
2844788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemporaryBase Rebase(*this, Input.getLocation(), Name);
28457c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2846833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!D) return true;
2847833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2848828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Expr *SourceExpr = Input.getSourceDeclExpression();
2849828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    if (SourceExpr) {
2850828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      EnterExpressionEvaluationContext Unevaluated(getSema(),
2851f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                   Sema::Unevaluated);
285260d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(SourceExpr);
28539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      SourceExpr = (E.isInvalid() ? 0 : E.take());
2854828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    }
2855828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
2856828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2857833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2858670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2860788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template: {
2861b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2862b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (QualifierLoc) {
2863b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2864b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      if (!QualifierLoc)
2865b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor        return true;
2866b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    }
2867b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor
28681d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    CXXScopeSpec SS;
28691d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    SS.Adopt(QualifierLoc);
2870788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemplateName Template
28711d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor      = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
28721d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor                                           Input.getTemplateNameLoc());
2873788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    if (Template.isNull())
2874788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      return true;
2875c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2876b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
2877788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateNameLoc());
2878788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return false;
2879788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  }
2880a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2881a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor  case TemplateArgument::TemplateExpansion:
2882a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    llvm_unreachable("Caller should expand pack expansions");
2883a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2884670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Expression: {
2885670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    // Template argument expressions are not potentially evaluated.
28861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EnterExpressionEvaluationContext Unevaluated(getSema(),
2887f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                                 Sema::Unevaluated);
28881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2889833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Expr *InputExpr = Input.getSourceExpression();
2890833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2891833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2892223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner    ExprResult E = getDerived().TransformExpr(InputExpr);
2893833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (E.isInvalid()) return true;
28949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
2895833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2896670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
28971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2898670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Pack: {
2899686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<TemplateArgument, 4> TransformedArgs;
2900670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    TransformedArgs.reserve(Arg.pack_size());
29011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
2902670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor                                      AEnd = Arg.pack_end();
2903670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor         A != AEnd; ++A) {
29041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2905833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // FIXME: preserve source information here when we start
2906833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // caring about parameter packs.
2907833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2908828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc InputArg;
2909828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc OutputArg;
2910828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      getDerived().InventTemplateArgumentLoc(*A, InputArg);
2911828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
2912833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall        return true;
2913833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2914828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TransformedArgs.push_back(OutputArg.getArgument());
2915670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    }
2916910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
2917910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    TemplateArgument *TransformedArgsPtr
2918910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2919910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2920910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor              TransformedArgsPtr);
2921910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2922910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                                  TransformedArgs.size()),
2923910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                 Input.getLocInfo());
2924833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2925670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
2926670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
29271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2928670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Work around bogus GCC warning
2929833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return true;
2930670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor}
2931670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
29327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information
29337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator.
29347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator>
29357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator {
29367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TreeTransform<Derived> &Self;
29377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  InputIterator Iter;
29387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic:
29407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc value_type;
29417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc reference;
29427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef typename std::iterator_traits<InputIterator>::difference_type
29437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    difference_type;
29447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef std::input_iterator_tag iterator_category;
29457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class pointer {
29477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Arg;
2948fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
29507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
29517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    const TemplateArgumentLoc *operator->() const { return &Arg; }
29537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
29547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator() { }
29567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
29587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                             InputIterator Iter)
29597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    : Self(Self), Iter(Iter) { }
29607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator &operator++() {
29627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++Iter;
29637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return *this;
2964fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  }
2965fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator operator++(int) {
29677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocInventIterator Old(*this);
29687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++(*this);
29697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Old;
29707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  reference operator*() const {
29737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Result;
29747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    Self.InventTemplateArgumentLoc(*Iter, Result);
29757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Result;
29767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  pointer operator->() const { return pointer(**this); }
29797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator==(const TemplateArgumentLocInventIterator &X,
29817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
29827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter == Y.Iter;
29837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
2984fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
29857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator!=(const TemplateArgumentLocInventIterator &X,
29867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
29877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter != Y.Iter;
29887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
29897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor};
29907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
29917f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived>
29927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator>
29937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
29947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                        InputIterator Last,
29957f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor                                            TemplateArgumentListInfo &Outputs) {
29967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  for (; First != Last; ++First) {
29977f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    TemplateArgumentLoc Out;
29987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc In = *First;
29998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().getKind() == TemplateArgument::Pack) {
30018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Unpack argument packs, which we translate them into separate
30028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // arguments.
30037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // FIXME: We could do much better if we could guarantee that the
30047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // TemplateArgumentLocInfo for the pack expansion would be usable for
30057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // all of the template arguments in the argument pack.
30067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      typedef TemplateArgumentLocInventIterator<Derived,
30077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                TemplateArgument::pack_iterator>
30087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        PackLocIterator;
30097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      if (TransformTemplateArguments(PackLocIterator(*this,
30107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                 In.getArgument().pack_begin()),
30117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     PackLocIterator(*this,
30127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                   In.getArgument().pack_end()),
30137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     Outputs))
30147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return true;
30158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
30178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
30188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().isPackExpansion()) {
30208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // We have a pack expansion, for which we will be substituting into
30218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // the pattern.
30228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      SourceLocation Ellipsis;
3023cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> OrigNumExpansions;
30248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      TemplateArgumentLoc Pattern
3025cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3026cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                     getSema().Context);
30278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
3028686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      SmallVector<UnexpandedParameterPack, 2> Unexpanded;
30298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
30308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
30318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
30338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // be expanded.
30348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      bool Expand = true;
3035d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3036cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
30378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (getDerived().TryExpandParameterPacks(Ellipsis,
30388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Pattern.getSourceRange(),
30398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.data(),
30408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Unexpanded.size(),
3041d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand,
3042d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3043d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
30448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return true;
30458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (!Expand) {
30478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // The transform has determined that we should perform a simple
30488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // transformation on the pack expansion, producing another pack
30498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // expansion.
30508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        TemplateArgumentLoc OutPattern;
30518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
30528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
30538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
3055cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3056cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                NumExpansions);
30578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (Out.getArgument().isNull())
30588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
30618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        continue;
30628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
30638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // The transform has determined that we should perform an elementwise
30658491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // expansion of the pattern. Do so.
3066cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
30678491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
30688491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
30708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
30718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
307277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.getArgument().containsUnexpandedParameterPack()) {
3073cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3074cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                  OrigNumExpansions);
307577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.getArgument().isNull())
307677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
307777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
307877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor
30798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
30808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
30818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
30823cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
30833cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
30843cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
30853cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
30863cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
30873cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
30883cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
30893cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
3090cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3091cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                OrigNumExpansions);
30923cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (Out.getArgument().isNull())
30933cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
30943cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
30953cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        Outputs.addArgument(Out);
30963cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
3097d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
30988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
30998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
31008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
31018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    // The simple case:
31028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (getDerived().TransformTemplateArgument(In, Out))
31037f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor      return true;
31047f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
31057f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    Outputs.addArgument(Out);
31067f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  }
31077f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
31087f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  return false;
31097f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
31107f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor}
31117f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
3112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
3113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation
3114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
3115577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
311743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) {
3118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (getDerived().AlreadyTransformed(T))
3119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T;
31201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3121a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Temporary workaround.  All of these transformations should
3122a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // eventually turn into transformations on TypeLocs.
3123c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3124c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor                                                getDerived().getBaseLocation());
3125c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
312643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
31271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3128a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (!NewDI)
3129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
31301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return NewDI->getType();
3132577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
313543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3136a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlreadyTransformed(DI->getType()))
3137a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return DI;
31381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3139a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLocBuilder TLB;
31401bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
3141a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLoc TL = DI->getTypeLoc();
3142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TLB.reserve(TL.getFullDataSize());
31431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
314443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, TL);
3145a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return 0;
31471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3148a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
315343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  switch (T.getTypeLocClass()) {
3155a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
3156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \
3157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  case TypeLoc::CLASS: \
315843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
3160a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3161577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
31629f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("unhandled type loc!");
3163a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return QualType();
3164577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
31651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types
3167a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers
3168a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function
3169a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but
3170a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients.
31711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
31721eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3173a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
317443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               QualifiedTypeLoc T) {
3175a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers Quals = T.getType().getLocalQualifiers();
3176a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
317743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3178a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3179577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
31801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3181a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Silently suppress qualifiers if the result type can't be qualified.
3182a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: this is the right thing for template instantiation, but
3183a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // probably not for other clients.
3184a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result->isFunctionType() || Result->isReferenceType())
3185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return Result;
31861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3187f85e193739c953358c865005855253af4f68a497John McCall  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3188e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  // resulting type.
3189e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  if (Quals.hasObjCLifetime()) {
3190e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3191e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      Quals.removeObjCLifetime();
31924020caec546d221170072d2388b57d151cb26111Douglas Gregor    else if (Result.getObjCLifetime()) {
3193e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      // Objective-C ARC:
3194e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      //   A lifetime qualifier applied to a substituted template parameter
3195e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      //   overrides the lifetime qualifier from the template argument.
3196e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      if (const SubstTemplateTypeParmType *SubstTypeParam
3197e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3198e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        QualType Replacement = SubstTypeParam->getReplacementType();
3199e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Qualifiers Qs = Replacement.getQualifiers();
3200e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Qs.removeObjCLifetime();
3201e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Replacement
3202e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor          = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3203e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                             Qs);
3204e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Result = SemaRef.Context.getSubstTemplateTypeParmType(
3205e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                        SubstTypeParam->getReplacedParameter(),
3206e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                                              Replacement);
3207e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        TLB.TypeWasModifiedSafely(Result);
3208e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      } else {
32094020caec546d221170072d2388b57d151cb26111Douglas Gregor        // Otherwise, complain about the addition of a qualifier to an
32104020caec546d221170072d2388b57d151cb26111Douglas Gregor        // already-qualified type.
32114020caec546d221170072d2388b57d151cb26111Douglas Gregor        SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
3212b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis        SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
32134020caec546d221170072d2388b57d151cb26111Douglas Gregor          << Result << R;
32144020caec546d221170072d2388b57d151cb26111Douglas Gregor
3215e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Quals.removeObjCLifetime();
3216e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      }
3217e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    }
3218e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  }
32192865474261a608c7873b87ba4af110d17907896dJohn McCall  if (!Quals.empty()) {
32202865474261a608c7873b87ba4af110d17907896dJohn McCall    Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
32212865474261a608c7873b87ba4af110d17907896dJohn McCall    TLB.push<QualifiedTypeLoc>(Result);
32222865474261a608c7873b87ba4af110d17907896dJohn McCall    // No location information to preserve.
32232865474261a608c7873b87ba4af110d17907896dJohn McCall  }
3224a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3225a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3226a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
322843fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
3229b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc
3230b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
323143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
323243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
3233b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                   CXXScopeSpec &SS) {
3234b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  QualType T = TL.getType();
323543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
3236b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TL;
3237b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
323843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeLocBuilder TLB;
323943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result;
3240b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
324143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (isa<TemplateSpecializationType>(T)) {
3242b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateSpecializationTypeLoc SpecTL
3243b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = cast<TemplateSpecializationTypeLoc>(TL);
3244b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
324543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateName Template =
3246b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      getDerived().TransformTemplateName(SS,
3247b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getTypePtr()->getTemplateName(),
3248b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getTemplateNameLoc(),
324943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         ObjectType, UnqualLookup);
3250b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    if (Template.isNull())
3251b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return TypeLoc();
3252b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3253b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3254b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                              Template);
325543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else if (isa<DependentTemplateSpecializationType>(T)) {
3256b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
3257b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = cast<DependentTemplateSpecializationTypeLoc>(TL);
3258a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
3259b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateName Template
3260b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = getDerived().RebuildTemplateName(SS,
3261b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         *SpecTL.getTypePtr()->getIdentifier(),
3262b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getNameLoc(),
3263b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         ObjectType, UnqualLookup);
3264a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    if (Template.isNull())
3265b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return TypeLoc();
3266b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3267b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3268b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                                       SpecTL,
3269087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                     Template,
3270087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       SS);
327143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else {
327243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    // Nothing special needs to be done for these.
3273b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformType(TLB, TL);
327443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
3275b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3276b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  if (Result.isNull())
3277b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TypeLoc();
3278b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
3279b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
328043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
328143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
3282c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived>
3283b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo *
3284b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3285c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   QualType ObjectType,
3286c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   NamedDecl *UnqualLookup,
3287c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   CXXScopeSpec &SS) {
3288c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // FIXME: Painfully copy-paste from the above!
3289c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3290b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  QualType T = TSInfo->getType();
3291c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (getDerived().AlreadyTransformed(T))
3292b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TSInfo;
3293c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3294c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  TypeLocBuilder TLB;
3295c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  QualType Result;
3296c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3297b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  TypeLoc TL = TSInfo->getTypeLoc();
3298c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (isa<TemplateSpecializationType>(T)) {
3299c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    TemplateSpecializationTypeLoc SpecTL
3300c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      = cast<TemplateSpecializationTypeLoc>(TL);
3301c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3302b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateName Template
3303b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    = getDerived().TransformTemplateName(SS,
3304fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getTypePtr()->getTemplateName(),
3305fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getTemplateNameLoc(),
3306c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                         ObjectType, UnqualLookup);
3307c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    if (Template.isNull())
3308b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return 0;
3309c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3310c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3311c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                              Template);
3312c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  } else if (isa<DependentTemplateSpecializationType>(T)) {
3313c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
3314c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      = cast<DependentTemplateSpecializationTypeLoc>(TL);
3315c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3316a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    TemplateName Template
3317fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = getDerived().RebuildTemplateName(SS,
33187c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                         *SpecTL.getTypePtr()->getIdentifier(),
3319fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getNameLoc(),
33207c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                         ObjectType, UnqualLookup);
3321a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    if (Template.isNull())
3322b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return 0;
3323a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
3324c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3325a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                                       SpecTL,
3326087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       Template,
3327087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       SS);
3328c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  } else {
3329c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    // Nothing special needs to be done for these.
3330c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformType(TLB, TL);
3331c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  }
3332c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3333c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (Result.isNull())
3334b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return 0;
3335c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3336b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3337c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor}
3338c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3339a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline
3340a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3341a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TyLoc NewT = TLB.push<TyLoc>(T.getType());
3342a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewT.setNameLoc(T.getNameLoc());
3343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return T.getType();
3344a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3345a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3346a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
334843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      BuiltinTypeLoc T) {
3349ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3350ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  NewT.setBuiltinLoc(T.getBuiltinLoc());
3351ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (T.needsExtraLocalData())
3352ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3353ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  return T.getType();
3354577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3355577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
33561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3357a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
335843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ComplexTypeLoc T) {
3359a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: recurse?
3360a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, T);
3361a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
33621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3363a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3364a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
336543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      PointerTypeLoc TL) {
3366c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType PointeeType
3367c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
336892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (PointeeType.isNull())
336992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return QualType();
337092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
337192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  QualType Result = TL.getType();
3372c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (PointeeType->getAs<ObjCObjectType>()) {
337392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // A dependent pointer type 'T *' has is being transformed such
337492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // that an Objective-C class type is being replaced for 'T'. The
337592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // resulting pointer type is an ObjCObjectPointerType, not a
337692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // PointerType.
3377c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
3378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3379c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3380c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NewT.setStarLoc(TL.getStarLoc());
338192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return Result;
338292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
338343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
338492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (getDerived().AlwaysRebuild() ||
338592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      PointeeType != TL.getPointeeLoc().getType()) {
338692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
338792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Result.isNull())
338892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      return QualType();
338992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
3390f85e193739c953358c865005855253af4f68a497John McCall
3391f85e193739c953358c865005855253af4f68a497John McCall  // Objective-C ARC can add lifetime qualifiers to the type that we're
3392f85e193739c953358c865005855253af4f68a497John McCall  // pointing to.
3393f85e193739c953358c865005855253af4f68a497John McCall  TLB.TypeWasModifiedSafely(Result->getPointeeType());
3394f85e193739c953358c865005855253af4f68a497John McCall
339592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
339692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3397c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Result;
3398577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
34001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
34011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3402a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
340343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  BlockPointerTypeLoc TL) {
3404db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  QualType PointeeType
3405c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    = getDerived().TransformType(TLB, TL.getPointeeLoc());
3406c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (PointeeType.isNull())
3407c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return QualType();
3408c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3409c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  QualType Result = TL.getType();
3410c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (getDerived().AlwaysRebuild() ||
3411c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      PointeeType != TL.getPointeeLoc().getType()) {
3412c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Result = getDerived().RebuildBlockPointerType(PointeeType,
3413db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor                                                  TL.getSigilLoc());
3414db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor    if (Result.isNull())
3415db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor      return QualType();
3416db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  }
3417db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor
341839968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3419db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3420db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  return Result;
3421a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
342385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type.  Note that somewhat paradoxically we
342485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value
342585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type;  we only care if the type was *written* as an l-value type
342685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type.
342785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived>
342885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType
342985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
343043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ReferenceTypeLoc TL) {
343185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  const ReferenceType *T = TL.getTypePtr();
343285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
343385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // Note that this works with the pointee-as-written.
343485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
343585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (PointeeType.isNull())
343685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return QualType();
343785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
343885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType Result = TL.getType();
343985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (getDerived().AlwaysRebuild() ||
344085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      PointeeType != T->getPointeeTypeAsWritten()) {
344185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildReferenceType(PointeeType,
344285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               T->isSpelledAsLValue(),
344385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               TL.getSigilLoc());
344485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    if (Result.isNull())
344585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      return QualType();
344685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
344785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3448f85e193739c953358c865005855253af4f68a497John McCall  // Objective-C ARC can add lifetime qualifiers to the type that we're
3449f85e193739c953358c865005855253af4f68a497John McCall  // referring to.
3450f85e193739c953358c865005855253af4f68a497John McCall  TLB.TypeWasModifiedSafely(
3451f85e193739c953358c865005855253af4f68a497John McCall                     Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3452f85e193739c953358c865005855253af4f68a497John McCall
345385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // r-value references can be rebuilt as l-value references.
345485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  ReferenceTypeLoc NewTL;
345585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (isa<LValueReferenceType>(Result))
345685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
345785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  else
345885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
345985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
346085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
346185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  return Result;
346285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall}
346385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3464a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3465a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3466a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
346743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 LValueReferenceTypeLoc TL) {
346843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3469a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
34701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3472a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3473a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
347443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 RValueReferenceTypeLoc TL) {
347543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3476577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
34771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3478577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
34791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3480a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
348143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   MemberPointerTypeLoc TL) {
3482a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3483577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (PointeeType.isNull())
3484577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
34851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3486b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3487b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo* NewClsTInfo = 0;
3488b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  if (OldClsTInfo) {
3489b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3490b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (!NewClsTInfo)
3491b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return QualType();
3492b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
3493b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
3494b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  const MemberPointerType *T = TL.getTypePtr();
3495b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  QualType OldClsType = QualType(T->getClass(), 0);
3496b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  QualType NewClsType;
3497b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  if (NewClsTInfo)
3498b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsType = NewClsTInfo->getType();
3499b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  else {
3500b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsType = getDerived().TransformType(OldClsType);
3501b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (NewClsType.isNull())
3502b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return QualType();
3503b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
35041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3505a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3506a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3507a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      PointeeType != T->getPointeeType() ||
3508b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      NewClsType != OldClsType) {
3509b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
351085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getStarLoc());
3511a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3513a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3514577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3516a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
3517b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  NewTL.setClassTInfo(NewClsTInfo);
3518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3519a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3520577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
35221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
35231eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3524a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
352543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ConstantArrayTypeLoc TL) {
3526f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ConstantArrayType *T = TL.getTypePtr();
3527a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3528577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3529577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3531a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3532a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3533a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3534a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildConstantArrayType(ElementType,
3535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
3536a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSize(),
353785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             T->getIndexTypeCVRQualifiers(),
353885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3539a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3540a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3541a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3542c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3543a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3544a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3545a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
35461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3547a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = TL.getSizeExpr();
3548a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Size) {
3549f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3550a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3551a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3552a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
3553a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3554a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3555577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3557577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3558577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType(
3559a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                              TypeLocBuilder &TLB,
356043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              IncompleteArrayTypeLoc TL) {
3561f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const IncompleteArrayType *T = TL.getTypePtr();
3562a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3563577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3566a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3568a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3569a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildIncompleteArrayType(ElementType,
3570a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                     T->getSizeModifier(),
357185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                           T->getIndexTypeCVRQualifiers(),
357285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                     TL.getBracketsRange());
3573a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3574a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3575a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3576c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3577a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3578a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3579a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3580a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(0);
3581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3582a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
35841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3586a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3587a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
358843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   VariableArrayTypeLoc TL) {
3589f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VariableArrayType *T = TL.getTypePtr();
3590a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3592577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
35931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3594670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3595f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3596670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
359760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
3598a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
3599a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
3600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Size = SizeResult.take();
3603a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3604a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3605a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3606a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
3607a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
3608a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildVariableArrayType(ElementType,
3609a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
36109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Size,
3611a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                             T->getIndexTypeCVRQualifiers(),
361285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3613a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3614a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
3616c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3617a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3618a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3619a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3620a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
36211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3622a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
36241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3626a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3627a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
362843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             DependentSizedArrayTypeLoc TL) {
3629f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedArrayType *T = TL.getTypePtr();
3630a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3634670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Array bounds are not potentially evaluated contexts
3635f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
36361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // Prefer the expression from the TypeLoc;  the other may have been uniqued.
36383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *origSize = TL.getSizeExpr();
36393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!origSize) origSize = T->getSizeExpr();
36403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
36413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExprResult sizeResult
36423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    = getDerived().TransformExpr(origSize);
36433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (sizeResult.isInvalid())
3644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *size = sizeResult.get();
3647a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3648a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3649a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3650a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
36513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      size != origSize) {
3652a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3653a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                         T->getSizeModifier(),
36543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                                                         size,
3655a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                T->getIndexTypeCVRQualifiers(),
365685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                        TL.getBracketsRange());
3657a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
36601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3661a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // We might have any sort of array type now, but fortunately they
3662a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // all have the same location layout.
3663a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3664a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3665a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
36663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  NewTL.setSizeExpr(size);
3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3668a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
36701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                      TypeLocBuilder &TLB,
367443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentSizedExtVectorTypeLoc TL) {
3675f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedExtVectorType *T = TL.getTypePtr();
3676a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3677a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: ext vector locs should be nested
3678577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3682670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Vector sizes are not potentially evaluated contexts
3683f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
3684670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
368560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (Size.isInvalid())
3687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3691eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      ElementType != T->getElementType() ||
3692eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      Size.get() != T->getSizeExpr()) {
3693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
36949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                             Size.take(),
3695577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                         T->getAttributeLoc());
3696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3697a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3698a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3699a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3700a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Result might be dependent or not.
3701a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (isa<DependentSizedExtVectorType>(Result)) {
3702a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    DependentSizedExtVectorTypeLoc NewTL
3703a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3704a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3705a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  } else {
3706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3709a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3711577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
37121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3714a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
371543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     VectorTypeLoc TL) {
3716f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3717577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3718577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3720577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3721a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3722a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3723a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
372482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3725e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                            T->getVectorKind());
3726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3727a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3728a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3729c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3730a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3731a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
37321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3733a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3734577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
37351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3737a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
373843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        ExtVectorTypeLoc TL) {
3739f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3742577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
37431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3744a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3745a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3746a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildExtVectorType(ElementType,
3748a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               T->getNumElements(),
3749a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               /*FIXME*/ SourceLocation());
3750a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3751a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3752a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3753c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3754a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3755a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
37561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3757a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3758577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3759577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
37601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
376121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl *
37626a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3763fb44de956f27875def889482b5393475060392afJohn McCall                                                   int indexAdjustment,
37646a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
376521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
37666a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  TypeSourceInfo *NewDI = 0;
37676a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37686a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
37696a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    // If we're substituting into a pack expansion type and we know the
37706a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc OldTL = OldDI->getTypeLoc();
37716a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
37726a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37736a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLocBuilder TLB;
37746a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc NewTL = OldDI->getTypeLoc();
37756a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TLB.reserve(NewTL.getFullDataSize());
37766a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37776a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    QualType Result = getDerived().TransformType(TLB,
37786a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                               OldExpansionTL.getPatternLoc());
37796a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
37806a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
37816a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37826a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    Result = RebuildPackExpansionType(Result,
37836a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                OldExpansionTL.getPatternLoc().getSourceRange(),
37846a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      OldExpansionTL.getEllipsisLoc(),
37856a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      NumExpansions);
37866a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
37876a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
37886a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor
37896a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc NewExpansionTL
37906a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      = TLB.push<PackExpansionTypeLoc>(Result);
37916a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
37926a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
37936a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  } else
37946a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = getDerived().TransformType(OldDI);
379521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (!NewDI)
379621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return 0;
379721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
3798fb44de956f27875def889482b5393475060392afJohn McCall  if (NewDI == OldDI && indexAdjustment == 0)
379921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return OldParm;
3800fb44de956f27875def889482b5393475060392afJohn McCall
3801fb44de956f27875def889482b5393475060392afJohn McCall  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3802fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getDeclContext(),
3803fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getInnerLocStart(),
3804fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getLocation(),
3805fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getIdentifier(),
3806fb44de956f27875def889482b5393475060392afJohn McCall                                             NewDI->getType(),
3807fb44de956f27875def889482b5393475060392afJohn McCall                                             NewDI,
3808fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getStorageClass(),
3809fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getStorageClassAsWritten(),
3810fb44de956f27875def889482b5393475060392afJohn McCall                                             /* DefArg */ NULL);
3811fb44de956f27875def889482b5393475060392afJohn McCall  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3812fb44de956f27875def889482b5393475060392afJohn McCall                        OldParm->getFunctionScopeIndex() + indexAdjustment);
3813fb44de956f27875def889482b5393475060392afJohn McCall  return newParm;
381421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
381521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
381621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
381721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>::
3818a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  TransformFunctionTypeParams(SourceLocation Loc,
3819a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              ParmVarDecl **Params, unsigned NumParams,
3820a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              const QualType *ParamTypes,
3821686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                              SmallVectorImpl<QualType> &OutParamTypes,
3822686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                              SmallVectorImpl<ParmVarDecl*> *PVars) {
3823fb44de956f27875def889482b5393475060392afJohn McCall  int indexAdjustment = 0;
3824fb44de956f27875def889482b5393475060392afJohn McCall
3825a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  for (unsigned i = 0; i != NumParams; ++i) {
3826a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (ParmVarDecl *OldParm = Params[i]) {
3827fb44de956f27875def889482b5393475060392afJohn McCall      assert(OldParm->getFunctionScopeIndex() == i);
3828fb44de956f27875def889482b5393475060392afJohn McCall
38296a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      llvm::Optional<unsigned> NumExpansions;
3830406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      ParmVarDecl *NewParm = 0;
3831603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (OldParm->isParameterPack()) {
3832603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We have a function parameter pack that may need to be expanded.
3833686775deca8b8685eb90801495880e3abdd844c2Chris Lattner        SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3834603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3835603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Find the parameter packs that could be expanded.
3836c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3837c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3838c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc Pattern = ExpansionTL.getPatternLoc();
3839c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3840406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3841406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor
3842603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Determine whether we should expand the parameter packs.
3843603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        bool ShouldExpand = false;
3844d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor        bool RetainExpansion = false;
38456a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        llvm::Optional<unsigned> OrigNumExpansions
38466a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor          = ExpansionTL.getTypePtr()->getNumExpansions();
38476a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        NumExpansions = OrigNumExpansions;
3848c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3849c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor                                                 Pattern.getSourceRange(),
3850603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.data(),
3851603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                                 Unexpanded.size(),
3852d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 ShouldExpand,
3853d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 RetainExpansion,
3854d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 NumExpansions)) {
3855603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          return true;
3856603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3857603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3858603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        if (ShouldExpand) {
3859603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // Expand the function parameter pack into multiple, separate
3860603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // parameters.
386112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor          getDerived().ExpandingFunctionParameterPack(OldParm);
3862cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          for (unsigned I = 0; I != *NumExpansions; ++I) {
3863603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3864603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            ParmVarDecl *NewParm
38656a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
3866fb44de956f27875def889482b5393475060392afJohn McCall                                                        indexAdjustment++,
38676a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3868603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            if (!NewParm)
3869603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor              return true;
3870603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3871a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            OutParamTypes.push_back(NewParm->getType());
3872a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            if (PVars)
3873a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor              PVars->push_back(NewParm);
3874603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          }
3875d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3876d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // If we're supposed to retain a pack expansion, do so by temporarily
3877d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // forgetting the partially-substituted parameter pack.
3878d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          if (RetainExpansion) {
3879d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3880d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ParmVarDecl *NewParm
38816a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
3882fb44de956f27875def889482b5393475060392afJohn McCall                                                        indexAdjustment++,
38836a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                                        OrigNumExpansions);
3884d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (!NewParm)
3885d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              return true;
3886d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3887d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            OutParamTypes.push_back(NewParm->getType());
3888d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (PVars)
3889d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              PVars->push_back(NewParm);
3890d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          }
3891d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3892fb44de956f27875def889482b5393475060392afJohn McCall          // The next parameter should have the same adjustment as the
3893fb44de956f27875def889482b5393475060392afJohn McCall          // last thing we pushed, but we post-incremented indexAdjustment
3894fb44de956f27875def889482b5393475060392afJohn McCall          // on every push.  Also, if we push nothing, the adjustment should
3895fb44de956f27875def889482b5393475060392afJohn McCall          // go down by one.
3896fb44de956f27875def889482b5393475060392afJohn McCall          indexAdjustment--;
3897fb44de956f27875def889482b5393475060392afJohn McCall
3898603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // We're done with the pack expansion.
3899603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          continue;
3900603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3901603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3902603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We'll substitute the parameter now without expanding the pack
3903603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // expansion.
3904406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3905406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3906fb44de956f27875def889482b5393475060392afJohn McCall                                                          indexAdjustment,
3907406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor                                                          NumExpansions);
3908406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      } else {
3909406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3910fb44de956f27875def889482b5393475060392afJohn McCall                                                          indexAdjustment,
3911406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor                                                  llvm::Optional<unsigned>());
3912603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3913406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor
391421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      if (!NewParm)
391521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3916603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3917a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      OutParamTypes.push_back(NewParm->getType());
3918a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (PVars)
3919a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor        PVars->push_back(NewParm);
3920603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      continue;
3921603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    }
3922a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3923a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // Deal with the possibility that we don't have a parameter
3924a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // declaration for this parameter.
3925a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    QualType OldType = ParamTypes[i];
3926603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    bool IsPackExpansion = false;
3927cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    llvm::Optional<unsigned> NumExpansions;
3928406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor    QualType NewType;
3929603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (const PackExpansionType *Expansion
3930603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                       = dyn_cast<PackExpansionType>(OldType)) {
3931603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We have a function parameter pack that may need to be expanded.
3932603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      QualType Pattern = Expansion->getPattern();
3933686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3934603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3935603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3936603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // Determine whether we should expand the parameter packs.
3937603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      bool ShouldExpand = false;
3938d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3939a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
3940603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.data(),
3941603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                               Unexpanded.size(),
3942d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               ShouldExpand,
3943d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3944d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions)) {
394521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
3946603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3947603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3948603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (ShouldExpand) {
3949603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Expand the function parameter pack into multiple, separate
3950603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // parameters.
3951cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        for (unsigned I = 0; I != *NumExpansions; ++I) {
3952603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3953603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          QualType NewType = getDerived().TransformType(Pattern);
3954603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          if (NewType.isNull())
3955603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            return true;
3956603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3957a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          OutParamTypes.push_back(NewType);
3958a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          if (PVars)
3959a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            PVars->push_back(0);
3960603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
3961603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3962603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We're done with the pack expansion.
3963603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        continue;
3964603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
3965603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
39663cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
39673cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
39683cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
39693cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
39703cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        QualType NewType = getDerived().TransformType(Pattern);
39713cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (NewType.isNull())
39723cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
39733cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor
39743cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        OutParamTypes.push_back(NewType);
39753cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (PVars)
39763cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          PVars->push_back(0);
39773cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
3978d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
3979603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We'll substitute the parameter now without expanding the pack
3980603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // expansion.
3981603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      OldType = Expansion->getPattern();
3982603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      IsPackExpansion = true;
3983406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3984406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      NewType = getDerived().TransformType(OldType);
3985406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor    } else {
3986406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      NewType = getDerived().TransformType(OldType);
3987a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    }
3988603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3989603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (NewType.isNull())
3990603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      return true;
39911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3992603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (IsPackExpansion)
3993cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NewType = getSema().Context.getPackExpansionType(NewType,
3994cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                       NumExpansions);
3995603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3996a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    OutParamTypes.push_back(NewType);
3997a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (PVars)
3998a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      PVars->push_back(0);
3999577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
40001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4001fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG
4002fb44de956f27875def889482b5393475060392afJohn McCall  if (PVars) {
4003fb44de956f27875def889482b5393475060392afJohn McCall    for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4004fb44de956f27875def889482b5393475060392afJohn McCall      if (ParmVarDecl *parm = (*PVars)[i])
4005fb44de956f27875def889482b5393475060392afJohn McCall        assert(parm->getFunctionScopeIndex() == i);
4006603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor  }
4007fb44de956f27875def889482b5393475060392afJohn McCall#endif
4008fb44de956f27875def889482b5393475060392afJohn McCall
4009fb44de956f27875def889482b5393475060392afJohn McCall  return false;
4010fb44de956f27875def889482b5393475060392afJohn McCall}
401121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
401221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
401321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType
401421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
401543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   FunctionProtoTypeLoc TL) {
40167e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // Transform the parameters and return type.
40177e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
40187e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // We instantiate in source order, with the return type first followed by
40197e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // the parameters, because users tend to expect this (even if they shouldn't
40207e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // rely on it!).
40217e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
4022dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // When the function has a trailing return type, we instantiate the
4023dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // parameters before the return type,  since the return type can then refer
4024dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // to the parameters themselves (via decltype, sizeof, etc.).
4025dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
4026686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<QualType, 4> ParamTypes;
4027686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<ParmVarDecl*, 4> ParamDecls;
4028f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionProtoType *T = TL.getTypePtr();
40297e010a04fef171049291d8cb3047f118566da090Douglas Gregor
4030dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  QualType ResultType;
4031dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4032dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  if (TL.getTrailingReturn()) {
4033a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4034a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
4035a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
4036a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
4037a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
4038dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4039dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4040dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4041dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
4042dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4043dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
4044dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  else {
4045dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4046dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
4047dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4048dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4049a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4050a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
4051a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
4052a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                             TL.getTypePtr()->arg_type_begin(),
4053a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
4054dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4055dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
4056dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4057a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4058a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4059a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType() ||
4060bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor      T->getNumArgs() != ParamTypes.size() ||
4061a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4062a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionProtoType(ResultType,
4063a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.data(),
4064a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.size(),
4065a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->isVariadic(),
4066fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getTypeQuals(),
4067c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                   T->getRefQualifier(),
4068fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getExtInfo());
4069a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4070a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4071a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
40721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4073a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4074796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4075796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4076dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(TL.getTrailingReturn());
4077a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4078a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setArg(i, ParamDecls[i]);
4079a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4080a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4081577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
40821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4083577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4084577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4085a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                 TypeLocBuilder &TLB,
408643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 FunctionNoProtoTypeLoc TL) {
4087f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionNoProtoType *T = TL.getTypePtr();
4088a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4089a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (ResultType.isNull())
4090a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4091a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4092a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4093a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4094a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType())
4095a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4096a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4097a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4098796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4099796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4100dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  NewTL.setTrailingReturn(false);
4101a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4102a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4103577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4105ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType
4106ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
410743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 UnresolvedUsingTypeLoc TL) {
4108f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const UnresolvedUsingType *T = TL.getTypePtr();
41097c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4110ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (!D)
4111ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return QualType();
4112ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4113ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType Result = TL.getType();
4114ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4115ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Result = getDerived().RebuildUnresolvedUsingType(D);
4116ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    if (Result.isNull())
4117ed97649e9574b9d854fa4d6109c9333ae0993554John McCall      return QualType();
4118ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
4119ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4120ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // We might get an arbitrary type spec type back.  We should at
4121ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // least always get a type spec type, though.
4122ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4123ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  NewTL.setNameLoc(TL.getNameLoc());
4124ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4125ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return Result;
4126ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
4127ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
413043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypedefTypeLoc TL) {
4131f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypedefType *T = TL.getTypePtr();
4132162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *Typedef
4133162e1c1b487352434552147967c3dd296ebee2f7Richard Smith    = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4134162e1c1b487352434552147967c3dd296ebee2f7Richard Smith                                                               T->getDecl()));
4135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Typedef)
4136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
41371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4139a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4140a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Typedef != T->getDecl()) {
4141a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildTypedefType(Typedef);
4142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4144a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4145a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
41481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
415443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypeOfExprTypeLoc TL) {
4155670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // typeof expressions are not potentially evaluated contexts
4156f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
41571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
415860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4159577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
4160577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
4161577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4162a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4163a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4164cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      E.get() != TL.getUnderlyingExpr()) {
41652a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4167a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4168577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4169a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
41701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4171a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4172cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
4173cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
4174cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
4175a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4176a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4177577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
41781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
41791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4180a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
418143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     TypeOfTypeLoc TL) {
4182cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4183cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4184cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (!New_Under_TI)
4185577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
41861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4188cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4189cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4190a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4191a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4192a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
41931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4195cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
4196cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
4197cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
4198cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setUnderlyingTInfo(New_Under_TI);
4199a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4200a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4201577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
42021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
420543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                       DecltypeTypeLoc TL) {
4206f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DecltypeType *T = TL.getTypePtr();
4207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4208670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // decltype expressions are not potentially evaluated contexts
4209f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
42101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
421160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4212577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
4213577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
42141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      E.get() != T->getUnderlyingExpr()) {
42182a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4219a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4220a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4221577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4222a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
4223a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4224a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4225a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
42261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4228577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4229577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4230577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4231ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType(
4232ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                            TypeLocBuilder &TLB,
4233ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                     UnaryTransformTypeLoc TL) {
4234ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType Result = TL.getType();
4235ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  if (Result->isDependentType()) {
4236ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    const UnaryTransformType *T = TL.getTypePtr();
4237ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    QualType NewBase =
4238ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4239ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    Result = getDerived().RebuildUnaryTransformType(NewBase,
4240ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    T->getUTTKind(),
4241ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    TL.getKWLoc());
4242ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    if (Result.isNull())
4243ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      return QualType();
4244ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
4245ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
4246ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4247ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setKWLoc(TL.getKWLoc());
4248ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setParensRange(TL.getParensRange());
4249ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4250ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  return Result;
4251ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
4252ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
4253ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived>
425434b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
425534b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                   AutoTypeLoc TL) {
425634b41d939a1328f484511c6002ba2456db879a29Richard Smith  const AutoType *T = TL.getTypePtr();
425734b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType OldDeduced = T->getDeducedType();
425834b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType NewDeduced;
425934b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (!OldDeduced.isNull()) {
426034b41d939a1328f484511c6002ba2456db879a29Richard Smith    NewDeduced = getDerived().TransformType(OldDeduced);
426134b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (NewDeduced.isNull())
426234b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
426334b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
426434b41d939a1328f484511c6002ba2456db879a29Richard Smith
426534b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType Result = TL.getType();
426634b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
426734b41d939a1328f484511c6002ba2456db879a29Richard Smith    Result = getDerived().RebuildAutoType(NewDeduced);
426834b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (Result.isNull())
426934b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
427034b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
427134b41d939a1328f484511c6002ba2456db879a29Richard Smith
427234b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
427334b41d939a1328f484511c6002ba2456db879a29Richard Smith  NewTL.setNameLoc(TL.getNameLoc());
427434b41d939a1328f484511c6002ba2456db879a29Richard Smith
427534b41d939a1328f484511c6002ba2456db879a29Richard Smith  return Result;
427634b41d939a1328f484511c6002ba2456db879a29Richard Smith}
427734b41d939a1328f484511c6002ba2456db879a29Richard Smith
427834b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived>
4279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
428043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     RecordTypeLoc TL) {
4281f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const RecordType *T = TL.getTypePtr();
4282577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  RecordDecl *Record
42837c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
42847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                          T->getDecl()));
4285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Record)
4286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
42871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Record != T->getDecl()) {
4291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildRecordType(Record);
4292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
42951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
4298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4300577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4303a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
430443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   EnumTypeLoc TL) {
4305f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const EnumType *T = TL.getTypePtr();
4306577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  EnumDecl *Enum
43077c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
43087c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                        T->getDecl()));
4309577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Enum)
4310577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
43111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4312a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4313a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4314a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Enum != T->getDecl()) {
4315a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildEnumType(Enum);
4316a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4317a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4318a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4319a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4320a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4321a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
43221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4323a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4324577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43257da2431c23ef1ee8acb114e39692246e1801afc2John McCall
43263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived>
43273cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType(
43283cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         TypeLocBuilder &TLB,
432943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         InjectedClassNameTypeLoc TL) {
43303cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
43313cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                       TL.getTypePtr()->getDecl());
43323cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  if (!D) return QualType();
43333cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
43343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
43353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
43363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  return T;
43373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
43383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
4339577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4340577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4341a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                TypeLocBuilder &TLB,
434243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TemplateTypeParmTypeLoc TL) {
4343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
4344577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4345577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
43461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
434749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4348a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                         TypeLocBuilder &TLB,
434943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         SubstTemplateTypeParmTypeLoc TL) {
43500b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  const SubstTemplateTypeParmType *T = TL.getTypePtr();
43510b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43520b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Substitute into the replacement type, which itself might involve something
43530b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // that needs to be transformed. This only tends to occur with default
43540b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // template arguments of template template parameters.
43550b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
43560b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  QualType Replacement = getDerived().TransformType(T->getReplacementType());
43570b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  if (Replacement.isNull())
43580b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    return QualType();
43590b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43600b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Always canonicalize the replacement type.
43610b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  Replacement = SemaRef.Context.getCanonicalType(Replacement);
43620b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  QualType Result
43630b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
43640b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor                                                   Replacement);
43650b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
43660b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Propagate type-source information.
43670b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  SubstTemplateTypeParmTypeLoc NewTL
43680b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
43690b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  NewTL.setNameLoc(TL.getNameLoc());
43700b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  return Result;
43710b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
437249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
437349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
437449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived>
4375c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4376c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          TypeLocBuilder &TLB,
4377c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          SubstTemplateTypeParmPackTypeLoc TL) {
4378c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  return TransformTypeSpecType(TLB, TL);
4379c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}
4380c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
4381c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived>
4382833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
438343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        TypeLocBuilder &TLB,
438443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                           TemplateSpecializationTypeLoc TL) {
438543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
4386828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
43871d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  // The nested-name-specifier never matters in a TemplateSpecializationType,
43881d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  // because we can't have a dependent nested-name-specifier anyway.
43891d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  CXXScopeSpec SS;
439043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TemplateName Template
43911d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    = getDerived().TransformTemplateName(SS, T->getTemplateName(),
43921d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor                                         TL.getTemplateNameLoc());
439343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Template.isNull())
439443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4395833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
439643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4397dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor}
439843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
43997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace {
44007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \brief Simple iterator that traverses the template arguments in a
44017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// container that provides a \c getArgLoc() member function.
44027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
44037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// This iterator is intended to be used with the iterator form of
44047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \c TreeTransform<Derived>::TransformTemplateArguments().
44057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename ArgLocContainer>
44067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class TemplateArgumentLocContainerIterator {
44077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgLocContainer *Container;
44087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    unsigned Index;
44097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
44117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc value_type;
44127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc reference;
44137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef int difference_type;
44147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef std::input_iterator_tag iterator_category;
44157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    class pointer {
44177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLoc Arg;
44187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    public:
44207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
44217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      const TemplateArgumentLoc *operator->() const {
44237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return &Arg;
44247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      }
44257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    };
44267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator() {}
44297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
44317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                 unsigned Index)
44327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      : Container(&Container), Index(Index) { }
44337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator &operator++() {
44357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++Index;
44367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return *this;
44377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator operator++(int) {
44407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLocContainerIterator Old(*this);
44417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++(*this);
44427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Old;
44437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc operator*() const {
44467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Container->getArgLoc(Index);
44477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    pointer operator->() const {
44507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return pointer(Container->getArgLoc(Index));
44517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4454f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
44557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return X.Container == Y.Container && X.Index == Y.Index;
44567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4459f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
44607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return !(X == Y);
44617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
44627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
44637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}
44647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
44657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor
446643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived>
4467577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4468833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                        TypeLocBuilder &TLB,
4469833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                           TemplateSpecializationTypeLoc TL,
447043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TemplateName Template) {
4471d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo NewTemplateArgs;
4472d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4473d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
44747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
44757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgIterator;
44767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
44777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
44787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              NewTemplateArgs))
44797f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    return QualType();
44801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4481833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  // FIXME: maybe don't rebuild if all the template arguments are the same.
4482833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
4483833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType Result =
4484833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getDerived().RebuildTemplateSpecializationType(Template,
4485833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                   TL.getTemplateNameLoc(),
4486d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NewTemplateArgs);
44871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4488833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  if (!Result.isNull()) {
44893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // Specializations of template template parameters are represented as
44903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // TemplateSpecializationTypes, and substitution of type alias templates
44913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // within a dependent context can transform them into
44923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // DependentTemplateSpecializationTypes.
44933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    if (isa<DependentTemplateSpecializationType>(Result)) {
44943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      DependentTemplateSpecializationTypeLoc NewTL
44953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
44963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setKeywordLoc(TL.getTemplateNameLoc());
44973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setQualifierLoc(NestedNameSpecifierLoc());
44983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setNameLoc(TL.getTemplateNameLoc());
44993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setLAngleLoc(TL.getLAngleLoc());
45003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setRAngleLoc(TL.getRAngleLoc());
45013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
45023e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
45033e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      return Result;
45043e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    }
45053e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
4506833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TemplateSpecializationTypeLoc NewTL
4507833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4508833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4509833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setLAngleLoc(TL.getLAngleLoc());
4510833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setRAngleLoc(TL.getRAngleLoc());
4511833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4512833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4513833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
45141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4515833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return Result;
4516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
45171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4518a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived>
4519a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4520a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                     TypeLocBuilder &TLB,
4521a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                     DependentTemplateSpecializationTypeLoc TL,
4522087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                     TemplateName Template,
4523087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                     CXXScopeSpec &SS) {
4524a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  TemplateArgumentListInfo NewTemplateArgs;
4525a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4526a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4527a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  typedef TemplateArgumentLocContainerIterator<
4528a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor            DependentTemplateSpecializationTypeLoc> ArgIterator;
4529a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4530a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
4531a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                              NewTemplateArgs))
4532a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    return QualType();
4533a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4534a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  // FIXME: maybe don't rebuild if all the template arguments are the same.
4535a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4536a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4537a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    QualType Result
4538a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = getSema().Context.getDependentTemplateSpecializationType(
4539a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                TL.getTypePtr()->getKeyword(),
4540a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                         DTN->getQualifier(),
4541a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                         DTN->getIdentifier(),
4542a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                               NewTemplateArgs);
4543a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4544a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    DependentTemplateSpecializationTypeLoc NewTL
4545a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4546a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setKeywordLoc(TL.getKeywordLoc());
454794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
454894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
4549a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setNameLoc(TL.getNameLoc());
4550a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setLAngleLoc(TL.getLAngleLoc());
4551a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setRAngleLoc(TL.getRAngleLoc());
4552a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4553a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4554a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    return Result;
4555a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4556a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4557a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  QualType Result
4558a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    = getDerived().RebuildTemplateSpecializationType(Template,
4559a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                     TL.getNameLoc(),
4560a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                     NewTemplateArgs);
4561a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4562a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (!Result.isNull()) {
4563a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    /// FIXME: Wrap this in an elaborated-type-specifier?
4564a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    TemplateSpecializationTypeLoc NewTL
4565a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4566a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setTemplateNameLoc(TL.getNameLoc());
4567a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setLAngleLoc(TL.getLAngleLoc());
4568a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setRAngleLoc(TL.getRAngleLoc());
4569a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4570a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4571a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4572a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
4573a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  return Result;
4574a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor}
4575a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
45761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4577a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4578465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
457943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ElaboratedTypeLoc TL) {
4580f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ElaboratedType *T = TL.getTypePtr();
4581465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
45829e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
4583465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // NOTE: the qualifier in an ElaboratedType is optional.
45849e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  if (TL.getQualifierLoc()) {
45859e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    QualifierLoc
45869e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
45879e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    if (!QualifierLoc)
4588465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      return QualType();
4589465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
45901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
459143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
459243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (NamedT.isNull())
459343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4594a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar
45953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  // C++0x [dcl.type.elab]p2:
45963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   If the identifier resolves to a typedef-name or the simple-template-id
45973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   resolves to an alias template specialization, the
45983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   elaborated-type-specifier is ill-formed.
45991804174e1591bf59118f317775b48edd0382c3f0Richard Smith  if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
46001804174e1591bf59118f317775b48edd0382c3f0Richard Smith    if (const TemplateSpecializationType *TST =
46011804174e1591bf59118f317775b48edd0382c3f0Richard Smith          NamedT->getAs<TemplateSpecializationType>()) {
46021804174e1591bf59118f317775b48edd0382c3f0Richard Smith      TemplateName Template = TST->getTemplateName();
46031804174e1591bf59118f317775b48edd0382c3f0Richard Smith      if (TypeAliasTemplateDecl *TAT =
46041804174e1591bf59118f317775b48edd0382c3f0Richard Smith          dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
46051804174e1591bf59118f317775b48edd0382c3f0Richard Smith        SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
46061804174e1591bf59118f317775b48edd0382c3f0Richard Smith                     diag::err_tag_reference_non_tag) << 4;
46071804174e1591bf59118f317775b48edd0382c3f0Richard Smith        SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
46081804174e1591bf59118f317775b48edd0382c3f0Richard Smith      }
46093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    }
46103e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  }
46113e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
4612a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4613a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
46149e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      QualifierLoc != TL.getQualifierLoc() ||
4615e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      NamedT != T->getNamedType()) {
461621e413fe6305a198564d436ac515497716c47844John McCall    Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
46179e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                                T->getKeyword(),
46189e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                                QualifierLoc, NamedT);
4619a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4620a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4621a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4623465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4624e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  NewTL.setKeywordLoc(TL.getKeywordLoc());
46259e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NewTL.setQualifierLoc(QualifierLoc);
4626a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
46281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
46309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType(
46319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                TypeLocBuilder &TLB,
46329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                AttributedTypeLoc TL) {
46339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  const AttributedType *oldType = TL.getTypePtr();
46349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
46359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (modifiedType.isNull())
46369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return QualType();
46379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType result = TL.getType();
46399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // FIXME: dependent operand expressions?
46419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (getDerived().AlwaysRebuild() ||
46429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      modifiedType != oldType->getModifiedType()) {
46439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // TODO: this is really lame; we should really be rebuilding the
46449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // equivalent type from first principles.
46459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    QualType equivalentType
46469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      = getDerived().TransformType(oldType->getEquivalentType());
46479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (equivalentType.isNull())
46489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      return QualType();
46499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
46509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               modifiedType,
46519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               equivalentType);
46529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
46539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
46559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  newTL.setAttrNameLoc(TL.getAttrNameLoc());
46569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrOperand())
46579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
46589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrExprOperand())
46599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrExprOperand(TL.getAttrExprOperand());
46609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  else if (TL.hasAttrEnumOperand())
46619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
46629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  return result;
46649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
46659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
46669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived>
4667075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType
4668075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4669075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                                           ParenTypeLoc TL) {
4670075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4671075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (Inner.isNull())
4672075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType();
4673075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4674075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Result = TL.getType();
4675075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (getDerived().AlwaysRebuild() ||
4676075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      Inner != TL.getInnerLoc().getType()) {
4677075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Result = getDerived().RebuildParenType(Inner);
4678075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    if (Result.isNull())
4679075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      return QualType();
4680075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
4681075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4682075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4683075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setLParenLoc(TL.getLParenLoc());
4684075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setRParenLoc(TL.getRParenLoc());
4685075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  return Result;
4686075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
4687075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4688075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived>
46894714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
469043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      DependentNameTypeLoc TL) {
4691f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentNameType *T = TL.getTypePtr();
4692833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
46932494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  NestedNameSpecifierLoc QualifierLoc
46942494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
46952494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  if (!QualifierLoc)
4696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
46971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
469833500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType Result
46992494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    = getDerived().RebuildDependentNameType(T->getKeyword(),
470033500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getKeywordLoc(),
47012494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            QualifierLoc,
47022494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            T->getIdentifier(),
470333500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getNameLoc());
4704a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
4705a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4707e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4708e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    QualType NamedT = ElabT->getNamedType();
470933500955d731c73717af52088b7fc0e7a85681e7John McCall    TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
471033500955d731c73717af52088b7fc0e7a85681e7John McCall
4711e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4712e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
47139e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
471433500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
4715e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4716e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setKeywordLoc(TL.getKeywordLoc());
47172494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
4718e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setNameLoc(TL.getNameLoc());
4719e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
4720a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4721577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
47221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
472433500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>::
472533500955d731c73717af52088b7fc0e7a85681e7John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
472643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL) {
472794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
472894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (TL.getQualifierLoc()) {
472994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualifierLoc
473094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
473194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (!QualifierLoc)
4732a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      return QualType();
4733a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
4734a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
473543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived()
473694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor           .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
473743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
473843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
473943fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
474043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::
474194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
474294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                   DependentTemplateSpecializationTypeLoc TL,
474394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                       NestedNameSpecifierLoc QualifierLoc) {
474494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  const DependentTemplateSpecializationType *T = TL.getTypePtr();
474594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
474694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  TemplateArgumentListInfo NewTemplateArgs;
474794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
474894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
474994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
475094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  typedef TemplateArgumentLocContainerIterator<
475194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  DependentTemplateSpecializationTypeLoc> ArgIterator;
475294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
475394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
475494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                              NewTemplateArgs))
475594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return QualType();
475694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
475794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  QualType Result
475894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
475994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                              QualifierLoc,
476094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            T->getIdentifier(),
476194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            TL.getNameLoc(),
476294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            NewTemplateArgs);
476394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (Result.isNull())
476494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return QualType();
476594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
476694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
476794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualType NamedT = ElabT->getNamedType();
476894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
476994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Copy information relevant to the template specialization.
477094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    TemplateSpecializationTypeLoc NamedTL
47710a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4772a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    NamedTL.setTemplateNameLoc(TL.getNameLoc());
477394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NamedTL.setLAngleLoc(TL.getLAngleLoc());
477494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NamedTL.setRAngleLoc(TL.getRAngleLoc());
4775944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47760a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
477794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
477894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Copy information relevant to the elaborated type.
477994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
478094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setKeywordLoc(TL.getKeywordLoc());
478194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
47820a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor  } else if (isa<DependentTemplateSpecializationType>(Result)) {
47830a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
47840a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4785944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    SpecTL.setKeywordLoc(TL.getKeywordLoc());
47860a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setQualifierLoc(QualifierLoc);
4787a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    SpecTL.setNameLoc(TL.getNameLoc());
47880a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setLAngleLoc(TL.getLAngleLoc());
47890a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setRAngleLoc(TL.getRAngleLoc());
4790944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47910a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
479294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  } else {
47930a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    TemplateSpecializationTypeLoc SpecTL
47940a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(Result);
4795a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth    SpecTL.setTemplateNameLoc(TL.getNameLoc());
47960a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setLAngleLoc(TL.getLAngleLoc());
47970a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setRAngleLoc(TL.getRAngleLoc());
4798944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
47990a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
480094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  }
480194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  return Result;
480294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor}
480394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
480494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived>
48057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
48067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor                                                      PackExpansionTypeLoc TL) {
48072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Pattern
48082fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    = getDerived().TransformType(TLB, TL.getPatternLoc());
48092fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (Pattern.isNull())
48102fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    return QualType();
48112fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
48122fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  QualType Result = TL.getType();
48132fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (getDerived().AlwaysRebuild() ||
48142fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      Pattern != TL.getPatternLoc().getType()) {
48152fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    Result = getDerived().RebuildPackExpansionType(Pattern,
48162fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                           TL.getPatternLoc().getSourceRange(),
4817cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                   TL.getEllipsisLoc(),
4818cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           TL.getTypePtr()->getNumExpansions());
48192fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    if (Result.isNull())
48202fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      return QualType();
48212fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
48222fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
48232fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
48242fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  NewT.setEllipsisLoc(TL.getEllipsisLoc());
48252fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  return Result;
48267536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}
48277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
48287536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived>
4829a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4830a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
483143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ObjCInterfaceTypeLoc TL) {
4832ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCInterfaceType is never dependent.
4833c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4834c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return TL.getType();
4835c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4837c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived>
4838c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType
4839c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
484043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjCObjectTypeLoc TL) {
4841c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // ObjCObjectType is never dependent.
4842c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4843ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
4844577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
48451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4847a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4848a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
484943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ObjCObjectPointerTypeLoc TL) {
4850ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCObjectPointerType is never dependent.
4851c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
4852ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
485324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}
485424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis
4855577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
485643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation
485743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
485843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
485960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48601eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
48613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
486243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
486343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
486443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
486560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
486643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
486743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().TransformCompoundStmt(S, false);
486843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
486943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
487043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
487160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
48721eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
487343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              bool IsStmtExpr) {
48747114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  bool SubStmtInvalid = false;
487543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool SubStmtChanged = false;
4876ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Statements(getSema());
487743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
487843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       B != BEnd; ++B) {
487960d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Result = getDerived().TransformStmt(*B);
48807114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    if (Result.isInvalid()) {
48817114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Immediately fail if this was a DeclStmt, since it's very
48827114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // likely that this will cause problems for future statements.
48837114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      if (isa<DeclStmt>(*B))
48847114cbab7eb6e8b714eb22f014327daf2c741c08John McCall        return StmtError();
48857114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
48867114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Otherwise, just keep processing substatements and fail later.
48877114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      SubStmtInvalid = true;
48887114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      continue;
48897114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
48901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
489143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    SubStmtChanged = SubStmtChanged || Result.get() != *B;
489243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Statements.push_back(Result.takeAs<Stmt>());
489343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
48941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48957114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  if (SubStmtInvalid)
48967114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    return StmtError();
48977114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
489843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
489943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !SubStmtChanged)
49003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
490143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
490243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
490343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          move_arg(Statements),
490443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          S->getRBracLoc(),
490543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          IsStmtExpr);
490643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
490843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
490960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49101eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
491160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS, RHS;
4912264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  {
4913264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // The case value expressions are not potentially evaluated.
4914f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
49151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4916264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the left-hand case value.
4917264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    LHS = getDerived().TransformExpr(S->getLHS());
4918264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (LHS.isInvalid())
4919f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
49201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4921264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the right-hand case value (for the GNU case-range extension).
4922264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    RHS = getDerived().TransformExpr(S->getRHS());
4923264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (RHS.isInvalid())
4924f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4925264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  }
49261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
492743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Build the case statement.
492843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Case statements are always rebuilt so that they will attached to their
492943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transformed switch statement.
493060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
49319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       LHS.get(),
493243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getEllipsisLoc(),
49339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       RHS.get(),
493443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getColonLoc());
493543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Case.isInvalid())
4936f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
493843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the case
493960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
494043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4941f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
494343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Attach the body to the case statement
49449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
494543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
494643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
494743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
494860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49491eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
495043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the default case
495160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
495243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4953f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
495543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Default statements are always rebuilt
495643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
49579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubStmt.get());
495843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
496160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
496360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
496443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
4965f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
49661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
496757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
496857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getDecl());
496957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
497057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
497157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
497257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
497343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // FIXME: Pass the real colon location in.
4974ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  return getDerived().RebuildLabelStmt(S->getIdentLoc(),
497557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       cast<LabelDecl>(LD), SourceLocation(),
497657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       SubStmt.get());
497743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
49781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
497943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
498060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
49811eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
498243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
498360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
49848cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  VarDecl *ConditionVar = 0;
49858cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  if (S->getConditionVariable()) {
4986c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
49878cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor      = cast_or_null<VarDecl>(
4988aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
4989aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
4990aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
49918cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    if (!ConditionVar)
4992f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
499399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
49948cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
4995c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
499699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
4997f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
4998eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
4999eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor    // Convert the condition to a boolean value.
5000afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
50018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
50028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5003afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5004f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5005eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
50069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
5007afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
500899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
5009c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
50109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
50119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5012f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5013eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
501443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "then" branch.
501560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Then = getDerived().TransformStmt(S->getThen());
501643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Then.isInvalid())
5017f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
501943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "else" branch.
502060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Else = getDerived().TransformStmt(S->getElse());
502143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Else.isInvalid())
5022f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
502443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
50259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
502699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
502743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Then.get() == S->getThen() &&
502843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Else.get() == S->getElse())
50293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
50301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5031eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
503244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                    Then.get(),
50339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    S->getElseLoc(), Else.get());
503443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
503543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
503643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
503760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50381eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
503943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition.
504060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
5041d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  VarDecl *ConditionVar = 0;
5042d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  if (S->getConditionVariable()) {
5043c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
5044d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor      = cast_or_null<VarDecl>(
5045aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5046aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5047aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
5048d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    if (!ConditionVar)
5049f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
505099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
5051d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5052c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
505399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5054f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
505599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
50561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
505743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Rebuild the switch statement.
505860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Switch
50599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5060586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                          ConditionVar);
506143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Switch.isInvalid())
5062f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
506443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body of the switch statement.
506560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
506643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5067f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
50681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
506943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Complete the switch statement.
50709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
50719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Body.get());
507243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
50731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
507443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
507560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
507743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
507860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
50795656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  VarDecl *ConditionVar = 0;
50805656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  if (S->getConditionVariable()) {
5081c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
50825656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      = cast_or_null<VarDecl>(
5083aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5084aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5085aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
50865656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    if (!ConditionVar)
5087f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
508899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
50895656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5090c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
509199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5093afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
5094afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
5095afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
50968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
50978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5098afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5099f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
51009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE;
5101afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
510299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
51031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
51059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5106f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5107eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
510843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
510960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
511043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5111f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
51149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
511599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
51179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(S);
51181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5119eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
51209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       ConditionVar, Body.get());
512143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
512343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
512460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
512543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
512643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
512760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
512843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5129f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5131eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  // Transform the condition
513260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(S->getCond());
5133eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  if (Cond.isInvalid())
5134f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5135eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
513643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
513743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Cond.get() == S->getCond() &&
513843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
51393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
51401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
51429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    /*FIXME:*/S->getWhileLoc(), Cond.get(),
514343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    S->getRParenLoc());
514443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
514643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
514760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
51481eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) {
514943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the initialization statement
515060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Init = getDerived().TransformStmt(S->getInit());
515143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Init.isInvalid())
5152f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
515443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
515560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
515699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  VarDecl *ConditionVar = 0;
515799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  if (S->getConditionVariable()) {
5158c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ConditionVar
515999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      = cast_or_null<VarDecl>(
5160aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5161aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5162aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
516399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (!ConditionVar)
5164f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
516599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
516699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
5167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
516899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5169f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5170afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
5171afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
5172afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
51738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
51748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5175afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5176f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5177afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
51789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
5179afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
518099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
51811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
51839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5184f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5185eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
518643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the increment
518760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Inc = getDerived().TransformExpr(S->getInc());
518843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Inc.isInvalid())
5189f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
51929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (S->getInc() && !FullInc.get())
5193f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5194eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
519543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
519660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
519743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5198f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
520043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
520143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Init.get() == S->getInit() &&
52029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
520343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Inc.get() == S->getInc() &&
520443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
52053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
52061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
520743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
52089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Init.get(), FullCond, ConditionVar,
52099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     FullInc, S->getRParenLoc(), Body.get());
521043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
521143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
521243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
521360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52141eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
521557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
521657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getLabel());
521757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
521857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
521957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
522043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Goto statements must always be rebuilt, to resolve the label.
52211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
522257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                      cast<LabelDecl>(LD));
522343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
522443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
522543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
522660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52271eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
522860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Target = getDerived().TransformExpr(S->getTarget());
522943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Target.isInvalid())
5230f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
52311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
523243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
523343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Target.get() == S->getTarget())
52343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
523543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
523643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
52379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Target.get());
523843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
523943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
524043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
524160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
52433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
524443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
524643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
524760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52481eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
52493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
525043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
525243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
525360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
525560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = getDerived().TransformExpr(S->getRetValue());
525643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Result.isInvalid())
5257f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
525843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
52591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: We always rebuild the return statement because there is no way
526043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // to tell whether the return type of the function has changed.
52619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
526243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
526443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
526560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
526743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool DeclChanged = false;
5268686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Decl *, 4> Decls;
526943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
527043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       D != DEnd; ++D) {
5271aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor    Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5272aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                         *D);
527343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (!Transformed)
5274f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
52751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
527643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Transformed != *D)
527743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      DeclChanged = true;
52781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
527943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Decls.push_back(Transformed);
528043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
52811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
528243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() && !DeclChanged)
52833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
52841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
528643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getStartLoc(), S->getEndLoc());
528743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
528943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
529060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
529143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
5292c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5293ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Constraints(getSema());
5294ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Exprs(getSema());
5295686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<IdentifierInfo *, 4> Names;
5296a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson
529760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AsmString;
5298ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Clobbers(getSema());
5299703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5300703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  bool ExprsChanged = false;
5301c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5302703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the outputs.
5303703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5304ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getOutputIdentifier(I));
5305c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5306703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
53073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getOutputConstraintLiteral(I));
5308c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5309703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the output expr.
5310703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *OutputExpr = S->getOutputExpr(I);
531160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(OutputExpr);
5312703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
5313f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5314c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5315703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != OutputExpr;
5316c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
5318703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
5319c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5320703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the inputs.
5321703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5322ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getInputIdentifier(I));
5323c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5324703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
53253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getInputConstraintLiteral(I));
5326c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5327703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the input expr.
5328703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *InputExpr = S->getInputExpr(I);
532960d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(InputExpr);
5330703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
5331f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5332c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5333703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != InputExpr;
5334c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
5336703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
5337c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5338703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
53393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5340703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5341703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the clobbers.
5342703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
53433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Clobbers.push_back(S->getClobber(I));
5344703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5345703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // No need to transform the asm string literal.
5346703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  AsmString = SemaRef.Owned(S->getAsmString());
5347703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5348703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5349703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isSimple(),
5350703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isVolatile(),
5351703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumOutputs(),
5352703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getNumInputs(),
5353a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson                                     Names.data(),
5354703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Constraints),
5355703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Exprs),
53569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     AsmString.get(),
5357703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     move_arg(Clobbers),
5358703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->getRParenLoc(),
5359703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson                                     S->isMSAsm());
536043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
536143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
536243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
536343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
536460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
53651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
53664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body of the @try.
536760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
53684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (TryBody.isInvalid())
5369f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5370c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53718f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  // Transform the @catch statements (if present).
53728f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  bool AnyCatchChanged = false;
5373ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> CatchStmts(SemaRef);
53748f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
537560d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
53764dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Catch.isInvalid())
5377f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
53788f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    if (Catch.get() != S->getCatchStmt(I))
53798f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      AnyCatchChanged = true;
53808f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    CatchStmts.push_back(Catch.release());
53814dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
5382c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53834dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the @finally statement (if present).
538460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Finally;
53854dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (S->getFinallyStmt()) {
53864dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    Finally = getDerived().TransformStmt(S->getFinallyStmt());
53874dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Finally.isInvalid())
5388f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
53894dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
53904dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
53914dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
53924dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
53934dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      TryBody.get() == S->getTryBody() &&
53948f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      !AnyCatchChanged &&
53954dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Finally.get() == S->getFinallyStmt())
53963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5397c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
53984dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
53999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
54009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           move_arg(CatchStmts), Finally.get());
540143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
540343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
540460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54051eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5406be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  // Transform the @catch parameter, if there is one.
5407be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *Var = 0;
5408be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (VarDecl *FromVar = S->getCatchParamDecl()) {
5409be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    TypeSourceInfo *TSInfo = 0;
5410be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (FromVar->getTypeSourceInfo()) {
5411be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5412be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (!TSInfo)
5413f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5414be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
5415c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5416be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    QualType T;
5417be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (TSInfo)
5418be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = TSInfo->getType();
5419be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    else {
5420be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = getDerived().TransformType(FromVar->getType());
5421be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (T.isNull())
5422f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5423be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
5424c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5425be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5426be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (!Var)
5427f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5428be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
5429c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
543060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5431be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (Body.isInvalid())
5432f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5433c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5434c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5435be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                             S->getRParenLoc(),
54369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Var, Body.get());
543743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
543943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
544060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
54424dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body.
544360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
54444dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (Body.isInvalid())
5445f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5446c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
54484dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
54494dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Body.get() == S->getFinallyBody())
54503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
54514dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
54524dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
54534dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
54549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                               Body.get());
545543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
545743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
545860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54591eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
546060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand;
5461d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (S->getThrowExpr()) {
5462d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    Operand = getDerived().TransformExpr(S->getThrowExpr());
5463d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    if (Operand.isInvalid())
5464f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5465d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
5466c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5467d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5468d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor      Operand.get() == S->getThrowExpr())
54693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return getSema().Owned(S);
5470c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
547243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
547443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
547560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
547643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
54771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCAtSynchronizedStmt *S) {
54788fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the object we are locking.
547960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
54808fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Object.isInvalid())
5481f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5482c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54838fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the body.
548460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
54858fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Body.isInvalid())
5486f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5487c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
54888fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // If nothing change, just retain the current statement.
54898fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
54908fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Object.get() == S->getSynchExpr() &&
54918fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Body.get() == S->getSynchBody())
54923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
54938fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor
54948fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Build a new statement.
54958fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
54969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    Object.get(), Body.get());
549743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
549843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
549943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
550060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
5501f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5502f85e193739c953358c865005855253af4f68a497John McCall                                              ObjCAutoreleasePoolStmt *S) {
5503f85e193739c953358c865005855253af4f68a497John McCall  // Transform the body.
5504f85e193739c953358c865005855253af4f68a497John McCall  StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5505f85e193739c953358c865005855253af4f68a497John McCall  if (Body.isInvalid())
5506f85e193739c953358c865005855253af4f68a497John McCall    return StmtError();
5507f85e193739c953358c865005855253af4f68a497John McCall
5508f85e193739c953358c865005855253af4f68a497John McCall  // If nothing changed, just retain this statement.
5509f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
5510f85e193739c953358c865005855253af4f68a497John McCall      Body.get() == S->getSubStmt())
5511f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(S);
5512f85e193739c953358c865005855253af4f68a497John McCall
5513f85e193739c953358c865005855253af4f68a497John McCall  // Build a new statement.
5514f85e193739c953358c865005855253af4f68a497John McCall  return getDerived().RebuildObjCAutoreleasePoolStmt(
5515f85e193739c953358c865005855253af4f68a497John McCall                        S->getAtLoc(), Body.get());
5516f85e193739c953358c865005855253af4f68a497John McCall}
5517f85e193739c953358c865005855253af4f68a497John McCall
5518f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
5519f85e193739c953358c865005855253af4f68a497John McCallStmtResult
552043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt(
55211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCForCollectionStmt *S) {
5522c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the element statement.
552360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Element = getDerived().TransformStmt(S->getElement());
5524c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Element.isInvalid())
5525f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5526c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5527c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the collection expression.
552860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5529c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Collection.isInvalid())
5530f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5531990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5532990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall                                                            Collection.take());
5533990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall  if (Collection.isInvalid())
5534990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall    return StmtError();
5535c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5536c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the body.
553760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
5538c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Body.isInvalid())
5539f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5540c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5541c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // If nothing changed, just retain this statement.
5542c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
5543c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Element.get() == S->getElement() &&
5544c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Collection.get() == S->getCollection() &&
5545c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Body.get() == S->getBody())
55463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5547c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5548c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Build a new statement.
5549c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5550c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   /*FIXME:*/S->getForLoc(),
55519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Element.get(),
55529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Collection.get(),
5553c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   S->getRParenLoc(),
55549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Body.get());
555543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
555643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
555743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
555843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
555960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
556043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
556143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the exception declaration, if any.
556243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  VarDecl *Var = 0;
556343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (S->getExceptionDecl()) {
556443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    VarDecl *ExceptionDecl = S->getExceptionDecl();
556583cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    TypeSourceInfo *T = getDerived().TransformType(
556683cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getTypeSourceInfo());
556783cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    if (!T)
5568f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
55691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
557083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
5571ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getInnerLocStart(),
5572ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getLocation(),
5573ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getIdentifier());
5574ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor    if (!Var || Var->isInvalidDecl())
5575f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
557643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
55771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
557843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the actual exception handler.
557960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5580ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor  if (Handler.isInvalid())
5581f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
55821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
558343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
558443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !Var &&
558543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Handler.get() == S->getHandlerBlock())
55863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
558743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
558843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
558943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          Var,
55909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Handler.get());
559143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
55921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
559343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
559460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
559543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
559643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the try block itself.
559760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBlock
559843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    = getDerived().TransformCompoundStmt(S->getTryBlock());
559943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (TryBlock.isInvalid())
5600f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
56011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
560243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the handlers.
560343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool HandlerChanged = false;
5604ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Stmt*> Handlers(SemaRef);
560543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
560660d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Handler
560743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      = getDerived().TransformCXXCatchStmt(S->getHandler(I));
560843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Handler.isInvalid())
5609f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
56101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
561143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
561243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Handlers.push_back(Handler.takeAs<Stmt>());
561343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
56141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
561543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
561643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      TryBlock.get() == S->getTryBlock() &&
561743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !HandlerChanged)
56183fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
561943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
56209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
56211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        move_arg(Handlers));
562243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
56231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5624ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived>
5625ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult
5626ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5627ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5628ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Range.isInvalid())
5629ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5630ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5631ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5632ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (BeginEnd.isInvalid())
5633ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5634ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5635ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ExprResult Cond = getDerived().TransformExpr(S->getCond());
5636ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Cond.isInvalid())
5637ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5638ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5639ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ExprResult Inc = getDerived().TransformExpr(S->getInc());
5640ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Inc.isInvalid())
5641ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5642ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5643ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5644ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (LoopVar.isInvalid())
5645ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5646ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5647ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult NewStmt = S;
5648ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (getDerived().AlwaysRebuild() ||
5649ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Range.get() != S->getRangeStmt() ||
5650ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      BeginEnd.get() != S->getBeginEndStmt() ||
5651ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Cond.get() != S->getCond() ||
5652ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Inc.get() != S->getInc() ||
5653ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      LoopVar.get() != S->getLoopVarStmt())
5654ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5655ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getColonLoc(), Range.get(),
5656ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  BeginEnd.get(), Cond.get(),
5657ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  Inc.get(), LoopVar.get(),
5658ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getRParenLoc());
5659ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5660ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult Body = getDerived().TransformStmt(S->getBody());
5661ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Body.isInvalid())
5662ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5663ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5664ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // Body has changed but we didn't rebuild the for-range statement. Rebuild
5665ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // it now so we have a new statement to attach the body to.
5666ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Body.get() != S->getBody() && NewStmt.get() == S)
5667ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5668ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getColonLoc(), Range.get(),
5669ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  BeginEnd.get(), Cond.get(),
5670ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  Inc.get(), LoopVar.get(),
5671ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getRParenLoc());
5672ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5673ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (NewStmt.get() == S)
5674ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return SemaRef.Owned(S);
5675ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5676ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5677ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
5678ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
567928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
568028bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
568128bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
568228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult TryBlock; //  = getDerived().TransformCompoundStmt(S->getTryBlock());
568328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(TryBlock.isInvalid()) return StmtError();
568428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
568528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
568628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(!getDerived().AlwaysRebuild() &&
568728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley     TryBlock.get() == S->getTryBlock() &&
568828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley     Handler.get() == S->getHandler())
568928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SemaRef.Owned(S);
569028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
569128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
569228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        S->getTryLoc(),
569328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        TryBlock.take(),
569428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        Handler.take());
569528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
569628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
569728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
569828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
569928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
570028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
570128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(Block.isInvalid()) return StmtError();
570228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
570328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
570428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                            Block.take());
570528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
570628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
570728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
570828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
570928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
571028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
571128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(FilterExpr.isInvalid()) return StmtError();
571228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
571328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
571428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(Block.isInvalid()) return StmtError();
571528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
571628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
571728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                           FilterExpr.take(),
571828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                           Block.take());
571928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
572028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
572128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
572228bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
572328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
572428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(isa<SEHFinallyStmt>(Handler))
572528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
572628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  else
572728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
572828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
572928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
573043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
5731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation
5732577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
57331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
573460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5735454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
57363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
57371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
57381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
574060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5741454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
574240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
574340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  if (E->getQualifierLoc()) {
574440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    QualifierLoc
574540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
574640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!QualifierLoc)
5747f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5748a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5749dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5750dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *ND
57517c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
57527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getDecl()));
5753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!ND)
5754f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
57551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5756ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  DeclarationNameInfo NameInfo = E->getNameInfo();
5757ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  if (NameInfo.getName()) {
5758ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5759ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    if (!NameInfo.getName())
5760f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
5761ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  }
57622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
57632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!getDerived().AlwaysRebuild() &&
576440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      QualifierLoc == E->getQualifierLoc() &&
5765a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ND == E->getDecl() &&
57662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NameInfo.getName() == E->getDecl()->getDeclName() &&
5767096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
57681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5769dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // Mark it referenced in the new context regardless.
5770dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: this is a bit instantiation-specific.
5771dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5772a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
57733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5774a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
5775dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5776dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
5777096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
5778dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TemplateArgs = &TransArgs;
5779dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
5780dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
5781fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5782fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
5783fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
5784fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
5785dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
5786dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
578740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
578840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                                         TemplateArgs);
5789577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
57901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
579260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5793454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
57943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5795577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
57961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
579860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5799454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
58003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
580460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5805454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
58063fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
581060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5811454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
58123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
581660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5817454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
58183fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
5819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
582260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5823f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5824f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult ControllingExpr =
5825f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    getDerived().TransformExpr(E->getControllingExpr());
5826f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  if (ControllingExpr.isInvalid())
5827f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return ExprError();
5828f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5829686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Expr *, 4> AssocExprs;
5830686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<TypeSourceInfo *, 4> AssocTypes;
5831f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5832f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5833f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (TS) {
5834f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5835f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      if (!AssocType)
5836f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne        return ExprError();
5837f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      AssocTypes.push_back(AssocType);
5838f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    } else {
5839f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      AssocTypes.push_back(0);
5840f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    }
5841f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5842f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5843f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (AssocExpr.isInvalid())
5844f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      return ExprError();
5845f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    AssocExprs.push_back(AssocExpr.release());
5846f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
5847f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5848f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5849f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getDefaultLoc(),
5850f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getRParenLoc(),
5851f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  ControllingExpr.release(),
5852f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  AssocTypes.data(),
5853f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  AssocExprs.data(),
5854f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getNumAssocs());
5855f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}
5856f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
5857f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived>
5858f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult
5859454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
586060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5862f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
58653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
5868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       E->getRParen());
5869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
5870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
58711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
587260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5873454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
587460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
5876f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
58771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
58793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
58801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getOpcode(),
58839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get());
5884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
58851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
588760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
58888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
58898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform the type.
58908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
58918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!Type)
5892f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
5893c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
58948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform all of the components into components similar to what the
58958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // parser uses.
5896c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // FIXME: It would be slightly more efficient in the non-dependent case to
5897c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // just map FieldDecls, rather than requiring the rebuilder to look for
5898c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // the fields again. However, __builtin_offsetof is rare enough in
58998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // template code that we don't care.
59008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool ExprChanged = false;
5901f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::OffsetOfComponent Component;
59028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef OffsetOfExpr::OffsetOfNode Node;
5903686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Component, 4> Components;
59048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
59058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const Node &ON = E->getComponent(I);
59068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Component Comp;
590772be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor    Comp.isBrackets = true;
590806dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara    Comp.LocStart = ON.getSourceRange().getBegin();
590906dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara    Comp.LocEnd = ON.getSourceRange().getEnd();
59108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    switch (ON.getKind()) {
59118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Array: {
59128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
591360d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(FromIndex);
59148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (Index.isInvalid())
5915f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
5916c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      ExprChanged = ExprChanged || Index.get() != FromIndex;
59188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = true;
59199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Comp.U.E = Index.get();
59208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
59218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5922c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Field:
59248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Identifier:
59258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = false;
59268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.U.IdentInfo = ON.getFieldName();
592729d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor      if (!Comp.U.IdentInfo)
592829d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor        continue;
5929c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
5931c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5932cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    case Node::Base:
5933cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      // Will be recomputed during the rebuild.
5934cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      continue;
59358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
5936c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Components.push_back(Comp);
59388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
5939c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // If nothing changed, retain the existing expression.
59418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
59428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Type == E->getTypeSourceInfo() &&
59438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      !ExprChanged)
59443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
5945c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
59468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Build a new offsetof expression.
59478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
59488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          Components.data(), Components.size(),
59498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          E->getRParenLoc());
59507cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}
59517cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
59527cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived>
59537cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult
59547cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
59557cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  assert(getDerived().AlreadyTransformed(E->getType()) &&
59567cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall         "opaque value expression requires transformation");
59577cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  return SemaRef.Owned(E);
59588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
59598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
59608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived>
596160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
5962f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5963f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                UnaryExprOrTypeTraitExpr *E) {
5964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isArgumentType()) {
5965a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *OldT = E->getArgumentTypeInfo();
59665557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor
5967a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *NewT = getDerived().TransformType(OldT);
59685ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!NewT)
5969f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
59701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59715ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!getDerived().AlwaysRebuild() && OldT == NewT)
59723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
59731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5974f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5975f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                    E->getKind(),
5976f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                    E->getSourceRange());
5977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
59781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
597960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr;
59801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  {
5981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // C++0x [expr.sizeof]p1:
5982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   The operand is either an expression, which is an unevaluated operand
5983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    //   [...]
5984f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
59851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (SubExpr.isInvalid())
5988f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
59891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5990b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
59913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
5992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
59931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5994f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5995f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getOperatorLoc(),
5996f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getKind(),
5997f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getSourceRange());
5998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
59991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
600160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6002454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
600360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6005f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
600760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6008b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6009f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
60153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
6018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           /*FIXME:*/E->getLHS()->getLocStart(),
60199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                RHS.get(),
6020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getRBracketLoc());
6021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
602460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6025454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the callee.
602760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
6029f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform arguments.
6032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgChanged = false;
6033ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
6034aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6035aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
6036aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6037aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
6040b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgChanged)
60413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6043b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Wrong source location information for the '('.
60441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLParenLoc
6045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = ((Expr *)Callee.get())->getSourceRange().getBegin();
60469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      move_arg(Args),
6048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
6049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
60501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
605260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6053454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
605460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6055b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
6056f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
605840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
605983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (E->hasQualifier()) {
606040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    QualifierLoc
606140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
606240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor
606340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!QualifierLoc)
6064f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
606583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
60661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6067f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *Member
60687c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
60697c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getMemberDecl()));
6070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Member)
6071f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60736bb8017bb9e828d118e15e59d71c66bba323c364John McCall  NamedDecl *FoundDecl = E->getFoundDecl();
60746bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (FoundDecl == E->getMemberDecl()) {
60756bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = Member;
60766bb8017bb9e828d118e15e59d71c66bba323c364John McCall  } else {
60776bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = cast_or_null<NamedDecl>(
60786bb8017bb9e828d118e15e59d71c66bba323c364John McCall                   getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
60796bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!FoundDecl)
6080f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
60816bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
60826bb8017bb9e828d118e15e59d71c66bba323c364John McCall
6083b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase() &&
608540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      QualifierLoc == E->getQualifierLoc() &&
60868a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor      Member == E->getMemberDecl() &&
60876bb8017bb9e828d118e15e59d71c66bba323c364John McCall      FoundDecl == E->getFoundDecl() &&
6088096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
6089c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
60901f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // Mark it referenced in the new context regardless.
60911f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // FIXME: this is a bit instantiation-specific.
60921f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
60933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
60941f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson  }
6095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6096d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs;
6097096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
6098d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
6099d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
6100fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6101fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
6102fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
6103fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
61048a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor  }
6105c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6106b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bogus source location for the operator
6107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeOperatorLoc
6108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6109b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6110c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
6111c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
6112c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
6113c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
6114c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
6115c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
61169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6117b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isArrow(),
611840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                                        QualifierLoc,
61192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                        E->getMemberNameInfo(),
61208a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor                                        Member,
61216bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        FoundDecl,
6122096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                        (E->hasExplicitTemplateArgs()
6123d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                           ? &TransArgs : 0),
6124c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                        FirstQualifierInScope);
6125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
612860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6129454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
613060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6132f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
613460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6136f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
61413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
61449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            LHS.get(), RHS.get());
6145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
61471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
614860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator(
6150454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CompoundAssignOperator *E) {
6151454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformBinaryOperator(E);
6152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
615556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>::
615656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
615756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // Just rebuild the common and RHS expressions and see whether we
615856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // get any changes.
615956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
616056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
616156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (commonExpr.isInvalid())
616256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
616356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
616456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
616556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (rhs.isInvalid())
616656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
616756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
616856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (!getDerived().AlwaysRebuild() &&
616956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      commonExpr.get() == e->getCommon() &&
617056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      rhs.get() == e->getFalseExpr())
617156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return SemaRef.Owned(e);
617256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
617356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  return getDerived().RebuildConditionalOperator(commonExpr.take(),
617456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getQuestionLoc(),
617556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 0,
617656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getColonLoc(),
617756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 rhs.get());
617856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}
617956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
618056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived>
618160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6182454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
618360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
6184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
6185f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
618760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6189f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
619160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6193f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
6197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6198b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
61993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildConditionalOperator(Cond.get(),
620247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getQuestionLoc(),
62039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 LHS.get(),
620447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getColonLoc(),
62059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 RHS.get());
6206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
620960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6210454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6211a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // Implicit casts are eliminated during transformation, since they
6212a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // will be recomputed by semantic analysis after transformation.
62136eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return getDerived().TransformExpr(E->getSubExprAsWritten());
6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
621760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6218454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6219ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6220ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6221ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
6222ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
622360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
62246eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6226f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6229ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6230b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
62313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62339d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6234ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                            Type,
6235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc(),
62369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            SubExpr.get());
6237b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
624060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6241454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
624242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *OldT = E->getTypeSourceInfo();
624342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
624442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  if (!NewT)
6245f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
624760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6248b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
6249f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6251b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
625242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      OldT == NewT &&
6253b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInitializer())
62543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6255b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
62561d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // Note: the expression type doesn't necessarily match the
62571d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // type-as-written, but that's okay, because it should always be
62581d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // derivable from the initializer.
62591d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
626042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   /*FIXME:*/E->getInitializer()->getLocEnd(),
62629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Init.get());
6263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
626660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6267454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
626860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6269b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
6270f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase())
62743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bad source location
62771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeOperatorLoc
6278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
62799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessorLoc(),
6281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessor());
6282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
62831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6284b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
628560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6286454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool InitChanged = false;
62881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6289ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
6290aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6291aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  Inits, &InitChanged))
6292aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6293aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && !InitChanged)
62953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
6298e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                      E->getRBraceLoc(), E->getType());
6299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
630260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6303454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
6304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Designation Desig;
63051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
630643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the initializer value
630760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInit());
6308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
6309f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
631143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the designators.
6312ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
6313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ExprChanged = false;
6314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             DEnd = E->designators_end();
6316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       D != DEnd; ++D) {
6317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isFieldDesignator()) {
6318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Desig.AddDesignator(Designator::getField(D->getFieldName(),
6319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getDotLoc(),
6320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getFieldLoc()));
6321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
6322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
63231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isArrayDesignator()) {
632560d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
6326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Index.isInvalid())
6327f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
63281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Desig.AddDesignator(Designator::getArray(Index.get(),
6330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getLBracketLoc()));
63311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArrayExprs.push_back(Index.release());
6334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
6335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
63361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(D->isArrayRangeDesignator() && "New kind of designator?");
633860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Start
6339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Start.isInvalid())
6341f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
634360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
6344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (End.isInvalid())
6345f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Desig.AddDesignator(Designator::getArrayRange(Start.get(),
6348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  End.get(),
6349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getLBracketLoc(),
6350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getEllipsisLoc()));
63511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      End.get() != E->getArrayRangeEnd(*D);
63541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(Start.release());
6356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(End.release());
6357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
63581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInit() &&
6361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ExprChanged)
63623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getEqualOrColonLoc(),
63669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                E->usesGNUSyntax(), Init.get());
6367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
637060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr(
6372454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     ImplicitValueInitExpr *E) {
63735557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
6374c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
63755557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // FIXME: Will we ever have proper type location here? Will we actually
63765557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // need to transform the type?
6377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
6378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
6379f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType())
63833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildImplicitValueInitExpr(T);
6386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6388b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
638960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6390454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
63919bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
63929bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo)
6393f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
639560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6397f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
64002cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      TInfo == E->getWrittenTypeInfo() &&
6401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
64023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
64052cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                       TInfo, E->getRParenLoc());
6406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
640960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6410454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
6411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6412ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*, 4> Inits(SemaRef);
6413aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6414aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
6415aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
6416aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
6417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           move_arg(Inits),
6419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getRParenLoc());
6420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression.
6423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
6424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always
6425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to
6426b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis.
6427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
642860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6429454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
643057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
643157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        E->getLabel());
643257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
643357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return ExprError();
643457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner
6435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
643657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                           cast<LabelDecl>(LD));
6437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
644060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6441454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
644260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt
6443b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubStmt.isInvalid())
6445f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6447b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubStmt.get() == E->getSubStmt())
64493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
64529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      SubStmt.get(),
6453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
6454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
645760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6458454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
645960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
6460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
6461f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
646360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6464b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6465f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
646760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6469f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
6473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
64753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
64789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Cond.get(), LHS.get(), RHS.get(),
6479b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->getRParenLoc());
6480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
648360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6484454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
64853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
648960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6490454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
6491668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  switch (E->getOperator()) {
6492668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_New:
6493668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Delete:
6494668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_New:
6495668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_Delete:
6496668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
6497f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6498c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6499668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Call: {
6500668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // This is a call to an object's operator().
6501668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6502668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6503668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the object itself.
650460d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Object = getDerived().TransformExpr(E->getArg(0));
6505668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    if (Object.isInvalid())
6506f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6507668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6508668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // FIXME: Poor location information
6509668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    SourceLocation FakeLParenLoc
6510668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      = SemaRef.PP.getLocForEndOfToken(
6511668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                              static_cast<Expr *>(Object.get())->getLocEnd());
6512668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6513668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the call arguments.
6514ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall    ASTOwningVector<Expr*> Args(SemaRef);
6515aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6516aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                    Args))
6517aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return ExprError();
6518668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
65199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
6520668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        move_arg(Args),
6521668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        E->getLocEnd());
6522668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
6523668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6524668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6525668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_##Name:
6526668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6527668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def"
6528668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Subscript:
6529668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Handled below.
6530668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    break;
6531668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6532668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Conditional:
6533668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("conditional operator is not actually overloadable");
6534f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6535668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6536668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_None:
6537668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case NUM_OVERLOADED_OPERATORS:
6538668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("not an overloaded operator?");
6539f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6540668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
6541668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
654260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
6544f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
654660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult First = getDerived().TransformExpr(E->getArg(0));
6547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (First.isInvalid())
6548f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
655060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Second;
6551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->getNumArgs() == 2) {
6552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Second = getDerived().TransformExpr(E->getArg(1));
6553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Second.isInvalid())
6554f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
65561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
6559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      First.get() == E->getArg(0) &&
65601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
65613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
65621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 E->getOperatorLoc(),
65659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Callee.get(),
65669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 First.get(),
65679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Second.get());
6568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
657160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6572454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6573454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCallExpr(E);
6574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
6577e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult
6578e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6579e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform the callee.
6580e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6581e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (Callee.isInvalid())
6582e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6583e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6584e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform exec config.
6585e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6586e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (EC.isInvalid())
6587e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6588e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6589e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform arguments.
6590e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  bool ArgChanged = false;
6591e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ASTOwningVector<Expr*> Args(SemaRef);
6592e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6593e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                  &ArgChanged))
6594e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6595e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6596e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (!getDerived().AlwaysRebuild() &&
6597e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      Callee.get() == E->getCallee() &&
6598e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      !ArgChanged)
6599e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return SemaRef.Owned(E);
6600e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6601e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // FIXME: Wrong source location information for the '('.
6602e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  SourceLocation FakeLParenLoc
6603e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    = ((Expr *)Callee.get())->getSourceRange().getBegin();
6604e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6605e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      move_arg(Args),
6606e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      E->getRParenLoc(), EC.get());
6607e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}
6608e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6609e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived>
661060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6611454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
6612ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6613ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6614ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
6615ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor
661660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
66176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6619f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6622ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
66243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Poor source location information here.
66271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLAngleLoc
6628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRParenLoc
6631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(
6632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  E->getSubExpr()->getSourceRange().getEnd());
6633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
66341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              E->getStmtClass(),
6635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeLAngleLoc,
6636ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                              Type,
6637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
6638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
66399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              SubExpr.get(),
6640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRParenLoc);
6641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
664460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6645454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6646454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
665060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6651454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6652454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
665660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr(
6658454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CXXReinterpretCastExpr *E) {
6659454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
666360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6664454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6665454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
666960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr(
6671454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXFunctionalCastExpr *E) {
6672ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6673ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6674ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
66751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
667660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
66776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6679f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6682ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
66843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6686ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  return getDerived().RebuildCXXFunctionalCastExpr(Type,
6687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      /*FIXME:*/E->getSubExpr()->getLocStart(),
66889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr.get(),
6689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   E->getRParenLoc());
6690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
669360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6694454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
6695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isTypeOperand()) {
669657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    TypeSourceInfo *TInfo
669757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      = getDerived().TransformType(E->getTypeOperandSourceInfo());
669857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    if (!TInfo)
6699f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
67001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
670257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        TInfo == E->getTypeOperandSourceInfo())
67033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
67041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
670557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return getDerived().RebuildCXXTypeidExpr(E->getType(),
670657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             E->getLocStart(),
670757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             TInfo,
6708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getLocEnd());
6709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
67101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // We don't know whether the expression is potentially evaluated until
6712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // after we perform semantic analysis, so the expression is potentially
6713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // potentially evaluated.
67141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  EnterExpressionEvaluationContext Unevaluated(SemaRef,
6715f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                      Sema::PotentiallyPotentiallyEvaluated);
67161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
671760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6719f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getExprOperand())
67233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
672557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  return getDerived().RebuildCXXTypeidExpr(E->getType(),
672657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                           E->getLocStart(),
67279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get(),
6728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLocEnd());
6729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
673260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
673301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
673401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (E->isTypeOperand()) {
673501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    TypeSourceInfo *TInfo
673601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      = getDerived().TransformType(E->getTypeOperandSourceInfo());
673701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!TInfo)
673801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      return ExprError();
673901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
674001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!getDerived().AlwaysRebuild() &&
674101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet        TInfo == E->getTypeOperandSourceInfo())
67423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
674301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
67443c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor    return getDerived().RebuildCXXUuidofExpr(E->getType(),
674501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocStart(),
674601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             TInfo,
674701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocEnd());
674801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
674901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
675001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // We don't know whether the expression is potentially evaluated until
675101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // after we perform semantic analysis, so the expression is potentially
675201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // potentially evaluated.
675301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
675401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
675501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
675601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (SubExpr.isInvalid())
675701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return ExprError();
675801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
675901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (!getDerived().AlwaysRebuild() &&
676001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      SubExpr.get() == E->getExprOperand())
67613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
676201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
676301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  return getDerived().RebuildCXXUuidofExpr(E->getType(),
676401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocStart(),
676501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           SubExpr.get(),
676601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocEnd());
676701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}
676801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
676901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived>
677001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult
6771454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
67723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
677660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
6778454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXNullPtrLiteralExpr *E) {
67793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
678360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6784454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
6785ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  DeclContext *DC = getSema().getFunctionLevelDeclContext();
67867a614d8380297fcd2bc23986241905d97222948cRichard Smith  QualType T;
67877a614d8380297fcd2bc23986241905d97222948cRichard Smith  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
67887a614d8380297fcd2bc23986241905d97222948cRichard Smith    T = MD->getThisType(getSema().Context);
67897a614d8380297fcd2bc23986241905d97222948cRichard Smith  else
67907a614d8380297fcd2bc23986241905d97222948cRichard Smith    T = getSema().Context.getPointerType(
67917a614d8380297fcd2bc23986241905d97222948cRichard Smith      getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
67921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6793ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!getDerived().AlwaysRebuild() && T == E->getType())
67943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6796828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
6797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
680060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6801454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
680260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6804f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
68083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6810bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6811bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor                                          E->isThrownVariableInScope());
6812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
68131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
681560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6816454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
68171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParmVarDecl *Param
68187c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
68197c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           E->getParam()));
6820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Param)
6821f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
682353cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth  if (!getDerived().AlwaysRebuild() &&
6824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Param == E->getParam())
68253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
68261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6827036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
6828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
68291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
683160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6832ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6833ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXScalarValueInitExpr *E) {
6834ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6835ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
6836f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6837ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
6838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6839ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo())
68403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
68411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6842ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXScalarValueInitExpr(T,
6843ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
6844ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor                                                    E->getRParenLoc());
6845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
68461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
684860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6849454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
6850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the type that we're allocating
68511bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocTypeInfo
68521bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
68531bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  if (!AllocTypeInfo)
6854f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the size of the array we're allocating (if any).
685760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
6858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (ArraySize.isInvalid())
6859f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the placement arguments (if any).
6862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
6863ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> PlacementArgs(SemaRef);
6864aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getPlacementArgs(),
6865aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  E->getNumPlacementArgs(), true,
6866aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  PlacementArgs, &ArgumentChanged))
6867aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
68681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
686943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the constructor arguments (if any).
6870ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
6871aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6872aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     ConstructorArgs, &ArgumentChanged))
6873aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
68741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform constructor, new operator, and delete operator.
68761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  CXXConstructorDecl *Constructor = 0;
68771af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getConstructor()) {
68781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    Constructor = cast_or_null<CXXConstructorDecl>(
68797c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
68807c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
68811af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!Constructor)
6882f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68831af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
68841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
68851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorNew = 0;
68861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorNew()) {
68871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorNew = cast_or_null<FunctionDecl>(
68887c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(E->getLocStart(),
68897c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getOperatorNew()));
68901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorNew)
6891f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
68921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
68931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
68941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
68951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
68961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
68977c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
68987c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
68991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6900f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
69011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6902c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
69041bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor      AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
6905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArraySize.get() == E->getArraySize() &&
69061af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Constructor == E->getConstructor() &&
69071af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorNew == E->getOperatorNew() &&
69081af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete() &&
69091af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      !ArgumentChanged) {
69101af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
69111af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
69121af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (Constructor)
69131af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
69141af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorNew)
69151af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
69161af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
69171af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
69182ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor
69192ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor    if (E->isArray() && Constructor &&
69202ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        !E->getAllocatedType()->isDependentType()) {
69212ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor      QualType ElementType
69222ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        = SemaRef.Context.getBaseElementType(E->getAllocatedType());
69232ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor      if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
69242ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
69252ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
69262ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor          SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
69272ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        }
69282ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor      }
69292ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor    }
69302ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor
69313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
69321af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
69331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69341bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  QualType AllocType = AllocTypeInfo->getType();
69355b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  if (!ArraySize.get()) {
69365b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // If no array size was specified, but the new expression was
69375b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with an array type (e.g., "new T" where T is
69385b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with "int[4]"), extract the outer bound from the
69395b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // array type as our array size. We do this with constant and
69405b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // dependently-sized array types.
69415b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
69425b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    if (!ArrayT) {
69435b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      // Do nothing
69445b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const ConstantArrayType *ConsArrayT
69455b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                                     = dyn_cast<ConstantArrayType>(ArrayT)) {
6946c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      ArraySize
69479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
69489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               ConsArrayT->getSize(),
69499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               SemaRef.Context.getSizeType(),
69509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               /*FIXME:*/E->getLocStart()));
69515b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      AllocType = ConsArrayT->getElementType();
69525b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const DependentSizedArrayType *DepArrayT
69535b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                              = dyn_cast<DependentSizedArrayType>(ArrayT)) {
69545b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      if (DepArrayT->getSizeExpr()) {
69553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall        ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
69565b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor        AllocType = DepArrayT->getElementType();
69575b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      }
69585b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    }
69595b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  }
69601bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
6961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isGlobalNew(),
6963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
6964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(PlacementArgs),
6965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
69664bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                        E->getTypeIdParens(),
6967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        AllocType,
69681bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                        AllocTypeInfo,
69699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        ArraySize.get(),
6970d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                        /*FIXME:*/E->hasInitializer()
6971d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                          ? E->getLocStart()
6972d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                          : SourceLocation(),
6973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        move_arg(ConstructorArgs),
6974d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                        /*FIXME:*/E->hasInitializer()
6975d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                          ? E->getLocEnd()
6976d0e8b782787638bcc9c57022e47c28d3529f02d4Douglas Gregor                                          : SourceLocation());
6977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
698060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6981454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
698260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
6983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Operand.isInvalid())
6984f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
69851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform the delete operator, if known.
69871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
69881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
69891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
69907c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
69917c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
69921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
6993f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
69941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
6995c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
69971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Operand.get() == E->getArgument() &&
69981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete()) {
69991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
70001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
70011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
70021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
70035833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
70045833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    if (!E->getArgument()->isTypeDependent()) {
70055833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      QualType Destroyed = SemaRef.Context.getBaseElementType(
70065833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                                         E->getDestroyedType());
70075833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
70085833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
70095833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        SemaRef.MarkDeclarationReferenced(E->getLocStart(),
70105833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                          SemaRef.LookupDestructor(Record));
70115833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      }
70125833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    }
70135833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
70143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
70151af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
70161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7017b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isGlobalDelete(),
7019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isArrayForm(),
70209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Operand.get());
7021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
70221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
702460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7025a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
7026454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXPseudoDestructorExpr *E) {
702760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7028a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  if (Base.isInvalid())
7029f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
70301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7031b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ObjectTypePtr;
7032a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  bool MayBePseudoDestructor = false;
70339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7034a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              E->getOperatorLoc(),
7035a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        E->isArrow()? tok::arrow : tok::period,
7036a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              ObjectTypePtr,
7037a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              MayBePseudoDestructor);
7038a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (Base.isInvalid())
7039f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7040c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7041b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  QualType ObjectType = ObjectTypePtr.get();
7042f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7043f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  if (QualifierLoc) {
7044f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    QualifierLoc
7045f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7046f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    if (!QualifierLoc)
704743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      return ExprError();
704843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
7049f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  CXXScopeSpec SS;
7050f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  SS.Adopt(QualifierLoc);
70511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7052a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage Destroyed;
7053a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (E->getDestroyedTypeInfo()) {
7054a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    TypeSourceInfo *DestroyedTypeInfo
705543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7056b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                ObjectType, 0, SS);
7057a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!DestroyedTypeInfo)
7058f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7059a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = DestroyedTypeInfo;
7060a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else if (ObjectType->isDependentType()) {
7061a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // We aren't likely to be able to resolve the identifier down to a type
7062a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // now anyway, so just retain the identifier.
7063a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7064a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                            E->getDestroyedTypeLoc());
7065a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else {
7066a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // Look for a destructor known with the given name.
7067b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7068a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              *E->getDestroyedTypeIdentifier(),
7069a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                E->getDestroyedTypeLoc(),
7070a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                /*Scope=*/0,
7071a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                SS, ObjectTypePtr,
7072a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                false);
7073a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!T)
7074f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7075c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7076a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed
7077a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7078a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                 E->getDestroyedTypeLoc());
7079a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
708026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
708126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *ScopeTypeInfo = 0;
708226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (E->getScopeTypeInfo()) {
708343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
708426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    if (!ScopeTypeInfo)
7085f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7086a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
7087c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
70889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7089a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->getOperatorLoc(),
7090a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->isArrow(),
7091f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                                     SS,
709226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     ScopeTypeInfo,
709326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getColonColonLoc(),
7094fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                     E->getTildeLoc(),
7095a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                     Destroyed);
7096a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}
70971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7098a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived>
709960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7100ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr(
7101454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  UnresolvedLookupExpr *Old) {
7102f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7103f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                 Sema::LookupOrdinaryName);
7104f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7105f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Transform all the decls.
7106f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7107f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall         E = Old->decls_end(); I != E; ++I) {
71087c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
71097c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(Old->getNameLoc(),
71107c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                            *I));
71119f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
71129f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
71139f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
71149f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
71159f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
71169f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
7117f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
71189f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
7119f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7120f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // Expand using declarations.
7121f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (isa<UsingDecl>(InstD)) {
7122f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
7123f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7124f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall             E = UD->shadow_end(); I != E; ++I)
7125f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        R.addDecl(*I);
7126f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      continue;
7127f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    }
7128f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7129f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    R.addDecl(InstD);
7130f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
7131f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7132f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Resolve a kind, but don't do any further analysis.  If it's
7133f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // ambiguous, the callee needs to deal with it.
7134f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  R.resolveKind();
7135f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7136f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Rebuild the nested-name qualifier, if present.
7137f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  CXXScopeSpec SS;
71384c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  if (Old->getQualifierLoc()) {
71394c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    NestedNameSpecifierLoc QualifierLoc
71404c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
71414c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (!QualifierLoc)
7142f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7143c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
71444c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    SS.Adopt(QualifierLoc);
7145c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
7146c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7147c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (Old->getNamingClass()) {
714866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    CXXRecordDecl *NamingClass
714966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
715066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                            Old->getNameLoc(),
715166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
715266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
7153f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7154c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
715566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
7156f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
7157f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7158f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have no template arguments, it's a normal declaration name.
7159f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!Old->hasExplicitTemplateArgs())
7160f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7161f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7162f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have template arguments, rebuild them, then rebuild the
7163f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // templateid expression.
7164f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
7165fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7166fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              Old->getNumTemplateArgs(),
7167fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7168fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
7169f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7170f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7171f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                            TransArgs);
7172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
717560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7176454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
71773d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
71783d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  if (!T)
7179f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
71801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
71823d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      T == E->getQueriedTypeSourceInfo())
71833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
71841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocStart(),
7187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            T,
7188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocEnd());
7189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
719260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
71936ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
71946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
71956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!LhsT)
71966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
71976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
71986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
71996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!RhsT)
72006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
72016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
72026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!getDerived().AlwaysRebuild() &&
72036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
72046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SemaRef.Owned(E);
72056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
72066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
72076ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocStart(),
72086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            LhsT, RhsT,
72096ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocEnd());
72106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}
72116ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
72126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived>
72136ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult
721421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
721521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
721621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  if (!T)
721721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return ExprError();
721821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
721921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  if (!getDerived().AlwaysRebuild() &&
722021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      T == E->getQueriedTypeSourceInfo())
722121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return SemaRef.Owned(E);
722221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
722321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult SubExpr;
722421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  {
722521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
722621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
722721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    if (SubExpr.isInvalid())
722821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      return ExprError();
722921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
723021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
723121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      return SemaRef.Owned(E);
723221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
723321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
723421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  return getDerived().RebuildArrayTypeTrait(E->getTrait(),
723521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            E->getLocStart(),
723621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            T,
723721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            SubExpr.get(),
723821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            E->getLocEnd());
723921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley}
724021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
724121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived>
724221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult
7243552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7244552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult SubExpr;
7245552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  {
7246552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7247552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7248552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    if (SubExpr.isInvalid())
7249552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      return ExprError();
7250552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7251552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7252552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      return SemaRef.Owned(E);
7253552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
7254552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7255552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  return getDerived().RebuildExpressionTrait(
7256552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7257552622067dc45013d240f73952fece703f5e63bdJohn Wiegley}
7258552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7259552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived>
7260552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult
7261865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
72622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                               DependentScopeDeclRefExpr *E) {
726300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc
726400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
726500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  if (!QualifierLoc)
7266f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
726843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
726943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
727043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
727143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
72722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
72732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
72742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
7275f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
72761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7277f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!E->hasExplicitTemplateArgs()) {
7278f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!getDerived().AlwaysRebuild() &&
727900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor        QualifierLoc == E->getQualifierLoc() &&
72802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // Note: it is sufficient to compare the Name component of NameInfo:
72812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // if name has not changed, DNLoc has not changed either.
72822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getDeclName())
72833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
72841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
728500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
72862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                         NameInfo,
7287f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         /*TemplateArgs*/ 0);
7288f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor  }
7289d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
7290d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7291fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7292fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
7293fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7294fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
7295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
729600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
72972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
7298f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       &TransArgs);
7299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
730260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7303454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
7304321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // CXXConstructExprs are always implicit, so when we have a
7305321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // 1-argument construction we just transform that argument.
7306321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  if (E->getNumArgs() == 1 ||
7307321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor      (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7308321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor    return getDerived().TransformExpr(E->getArg(0));
7309321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor
7310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
7313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
7314f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
7317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
73187c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(E->getLocStart(),
73197c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
7320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
7321f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7324ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
7327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
7329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType() &&
7331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
7332c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor      !ArgumentChanged) {
73331af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark the constructor as referenced.
73341af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: Instantiation-specific
7335c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
73363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7337c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor  }
73381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73394411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
73404411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                              Constructor, E->isElidable(),
73418c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              move_arg(Args),
73428c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              E->requiresZeroInitialization(),
7343428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getConstructionKind(),
7344428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getParenRange());
7345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression.
7348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
73495132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
73505132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that.
7351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
735260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7353454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
73545132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
7355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73574765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should
73584765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated.
7359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
73604765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we
73615132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that.
7362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
736360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
73644765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
73655132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
7366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
736960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
7371ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXTemporaryObjectExpr *E) {
7372ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7373ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
7374f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7376b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
7377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
7378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                  getDerived().TransformDecl(E->getLocStart(),
73797c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
7380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
7381f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7384ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Args.reserve(E->getNumArgs());
7386aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7387aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
7388aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
73891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7391ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
7392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
739391be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      !ArgumentChanged) {
739491be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    // FIXME: Instantiation-specific
7395ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
73963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.MaybeBindToTemporary(E);
739791be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor  }
7398ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
7399ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXTemporaryObjectExpr(T,
7400ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
7401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    move_arg(Args),
7402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    E->getLocEnd());
7403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
74041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
740660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
7408454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  CXXUnresolvedConstructExpr *E) {
7409ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7410ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
7411f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
74121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7413b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7414ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7415aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->arg_size());
7416aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7417aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
7418aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7419aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
7420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7421ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
7422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
74233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
74241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: we're faking the locations of the commas
7426ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
7427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getLParenLoc(),
7428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        move_arg(Args),
7429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getRParenLoc());
7430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
74311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
743360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7434865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
74352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                             CXXDependentScopeMemberExpr *E) {
7436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the base of the expression.
743760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
7438aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *OldBase;
7439aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
7440aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType ObjectType;
7441aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->isImplicitAccess()) {
7442aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = E->getBase();
7443aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(OldBase);
7444aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7445f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
74461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7447aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    // Start the member reference and compute the object's type.
7448b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ObjectTy;
7449d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor    bool MayBePseudoDestructor = false;
74509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7451aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                E->getOperatorLoc(),
7452a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                      E->isArrow()? tok::arrow : tok::period,
7453d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                ObjectTy,
7454d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                MayBePseudoDestructor);
7455aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7456f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7457aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
7458b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ObjectType = ObjectTy.get();
7459aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
7460aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
7461aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = 0;
7462aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(E->getBaseType());
7463aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7464aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
74651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74666cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // Transform the first part of the nested-name-specifier that qualifies
74676cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // the member name.
7468c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierInScope
74696cd219879ffce00920189ec1dcea927a42602961Douglas Gregor    = getDerived().TransformFirstQualifierInScope(
74707c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                            E->getFirstQualifierFoundInScope(),
74717c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                            E->getQualifierLoc().getBeginLoc());
74721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
7474a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  if (E->getQualifier()) {
74757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    QualifierLoc
74767c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
74777c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     ObjectType,
74787c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     FirstQualifierInScope);
74797c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    if (!QualifierLoc)
7480f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7481a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  }
74821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
748343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
748443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
748543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
748643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
74872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
748843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
74892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
7490f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
74911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7492aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->hasExplicitTemplateArgs()) {
74933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // This is a reference to a member without an explicitly-specified
74943b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // template argument list. Optimize for this common case.
74953b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
7496aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        Base.get() == OldBase &&
7497aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        BaseType == E->getBaseType() &&
74987c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor        QualifierLoc == E->getQualifierLoc() &&
74992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getMember() &&
75003b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        FirstQualifierInScope == E->getFirstQualifierFoundInScope())
75013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
75021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
7504aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                       BaseType,
75053b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->isArrow(),
75063b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getOperatorLoc(),
75077c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                       QualifierLoc,
7508129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       FirstQualifierInScope,
75092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
7510129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       /*TemplateArgs*/ 0);
75113b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
75123b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor
7513d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7514fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7515fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
7516fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7517fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
75181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
7520aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                     BaseType,
7521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->isArrow(),
7522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->getOperatorLoc(),
75237c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     QualifierLoc,
75243b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                     FirstQualifierInScope,
75252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                     NameInfo,
7526129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                     &TransArgs);
7527129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}
7528129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7529129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived>
753060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7531454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
7532129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform the base of the expression.
753360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
7534aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
7535aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!Old->isImplicitAccess()) {
7536aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(Old->getBase());
7537aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
7538f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7539aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
7540aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
7541aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(Old->getBaseType());
7542aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
7543129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
75444c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
75454c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  if (Old->getQualifierLoc()) {
75464c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    QualifierLoc
75474c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
75484c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (!QualifierLoc)
7549f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7550129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7551129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
75522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  LookupResult R(SemaRef, Old->getMemberNameInfo(),
7553129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                 Sema::LookupOrdinaryName);
7554129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7555129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform all the decls.
7556129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7557129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         E = Old->decls_end(); I != E; ++I) {
75587c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
75597c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(Old->getMemberLoc(),
75607c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           *I));
75619f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
75629f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
75639f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
75649f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
75659f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
756634f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis      else {
756734f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis        R.clear();
7568f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
756934f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis      }
75709f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
7571129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7572129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    // Expand using declarations.
7573129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (isa<UsingDecl>(InstD)) {
7574129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
7575129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7576129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall             E = UD->shadow_end(); I != E; ++I)
7577129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall        R.addDecl(*I);
7578129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      continue;
7579129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
7580129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7581129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    R.addDecl(InstD);
7582129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7583129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7584129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  R.resolveKind();
7585129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
7586c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  // Determine the naming class.
7587042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth  if (Old->getNamingClass()) {
7588c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    CXXRecordDecl *NamingClass
7589c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
759066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                          Old->getMemberLoc(),
759166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
759266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
7593f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7594c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
759566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
7596c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  }
7597c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7598129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  TemplateArgumentListInfo TransArgs;
7599129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->hasExplicitTemplateArgs()) {
7600129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setLAngleLoc(Old->getLAngleLoc());
7601129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setRAngleLoc(Old->getRAngleLoc());
7602fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7603fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                Old->getNumTemplateArgs(),
7604fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
7605fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
7606129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
7607c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
7608c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
7609c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
7610c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
7611c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
7612c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
7613c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
76149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
7615aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  BaseType,
7616129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getOperatorLoc(),
7617129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->isArrow(),
76184c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                                  QualifierLoc,
7619c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                                  FirstQualifierInScope,
7620129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  R,
7621129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              (Old->hasExplicitTemplateArgs()
7622129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  ? &TransArgs : 0));
7623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
762660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
76272e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7628eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
76292e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
76302e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (SubExpr.isInvalid())
76312e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return ExprError();
76322e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
76332e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
76343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
76352e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
76362e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
76372e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}
76382e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
76392e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived>
76402e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult
7641be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
76424f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
76434f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (Pattern.isInvalid())
76444f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return ExprError();
76454f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
76464f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
76474f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return SemaRef.Owned(E);
76484f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
764967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
765067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                           E->getNumExpansions());
7651be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}
7652ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7653ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived>
7654ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult
7655ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7656ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // If E is not value-dependent, then nothing will change when we transform it.
7657ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: This is an instantiation-centric view.
7658ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (!E->isValueDependent())
7659ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
7660ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7661ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: None of the implementations of TryExpandParameterPacks can ever
7662ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // produce a diagnostic when given only a single unexpanded parameter pack,
7663ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // so
7664ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7665ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  bool ShouldExpand = false;
7666d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  bool RetainExpansion = false;
7667cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> NumExpansions;
7668ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7669ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                           &Unexpanded, 1,
7670d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           ShouldExpand, RetainExpansion,
7671d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           NumExpansions))
7672ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return ExprError();
7673ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7674d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  if (!ShouldExpand || RetainExpansion)
7675ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
7676be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
7677ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // We now know the length of the parameter pack, so build a new expression
7678ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // that stores that length.
7679ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7680ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                            E->getPackLoc(), E->getRParenLoc(),
7681cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                            *NumExpansions);
7682ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}
7683ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
7684be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived>
7685be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult
7686c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7687c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                          SubstNonTypeTemplateParmPackExpr *E) {
7688c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Default behavior is to do nothing with this transformation.
768991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  return SemaRef.Owned(E);
769091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall}
769191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
769291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCalltemplate<typename Derived>
769391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallExprResult
769491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallTreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
769591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                                          SubstNonTypeTemplateParmExpr *E) {
769691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  // Default behavior is to do nothing with this transformation.
7697c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  return SemaRef.Owned(E);
7698c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}
7699c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
7700c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived>
7701c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult
770203e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorTreeTransform<Derived>::TransformMaterializeTemporaryExpr(
770303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor                                                  MaterializeTemporaryExpr *E) {
770403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  return getDerived().TransformExpr(E->GetTemporaryExpr());
770503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor}
770603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor
770703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregortemplate<typename Derived>
770803e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorExprResult
7709454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
77103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
77131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
771460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7715454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
771681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  TypeSourceInfo *EncodedTypeInfo
771781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
771881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  if (!EncodedTypeInfo)
7719f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
77201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
772281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
77233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
772681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                            EncodedTypeInfo,
7727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc());
7728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
77291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
7731f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>::
7732f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7733f85e193739c953358c865005855253af4f68a497John McCall  ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7734f85e193739c953358c865005855253af4f68a497John McCall  if (result.isInvalid()) return ExprError();
7735f85e193739c953358c865005855253af4f68a497John McCall  Expr *subExpr = result.take();
7736f85e193739c953358c865005855253af4f68a497John McCall
7737f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
7738f85e193739c953358c865005855253af4f68a497John McCall      subExpr == E->getSubExpr())
7739f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(E);
7740f85e193739c953358c865005855253af4f68a497John McCall
7741f85e193739c953358c865005855253af4f68a497John McCall  return SemaRef.Owned(new(SemaRef.Context)
7742f85e193739c953358c865005855253af4f68a497John McCall      ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7743f85e193739c953358c865005855253af4f68a497John McCall}
7744f85e193739c953358c865005855253af4f68a497John McCall
7745f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
7746f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>::
7747f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7748f85e193739c953358c865005855253af4f68a497John McCall  TypeSourceInfo *TSInfo
7749f85e193739c953358c865005855253af4f68a497John McCall    = getDerived().TransformType(E->getTypeInfoAsWritten());
7750f85e193739c953358c865005855253af4f68a497John McCall  if (!TSInfo)
7751f85e193739c953358c865005855253af4f68a497John McCall    return ExprError();
7752f85e193739c953358c865005855253af4f68a497John McCall
7753f85e193739c953358c865005855253af4f68a497John McCall  ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7754f85e193739c953358c865005855253af4f68a497John McCall  if (Result.isInvalid())
7755f85e193739c953358c865005855253af4f68a497John McCall    return ExprError();
7756f85e193739c953358c865005855253af4f68a497John McCall
7757f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
7758f85e193739c953358c865005855253af4f68a497John McCall      TSInfo == E->getTypeInfoAsWritten() &&
7759f85e193739c953358c865005855253af4f68a497John McCall      Result.get() == E->getSubExpr())
7760f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(E);
7761f85e193739c953358c865005855253af4f68a497John McCall
7762f85e193739c953358c865005855253af4f68a497John McCall  return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7763f85e193739c953358c865005855253af4f68a497John McCall                                      E->getBridgeKeywordLoc(), TSInfo,
7764f85e193739c953358c865005855253af4f68a497John McCall                                      Result.get());
7765f85e193739c953358c865005855253af4f68a497John McCall}
7766f85e193739c953358c865005855253af4f68a497John McCall
7767f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
776860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7769454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
777092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Transform arguments.
777192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  bool ArgChanged = false;
7772ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> Args(SemaRef);
7773aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->getNumArgs());
7774aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7775aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
7776aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
7777aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
777892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
777992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Class message: transform the receiver type.
778092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    TypeSourceInfo *ReceiverTypeInfo
778192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      = getDerived().TransformType(E->getClassReceiverTypeInfo());
778292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!ReceiverTypeInfo)
7783f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7784c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
778592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // If nothing changed, just retain the existing message send.
778692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
778792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor        ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
77883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
778992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
779092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Build a new class message send.
779192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
779292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getSelector(),
7793f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                               E->getSelectorLoc(),
779492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getMethodDecl(),
779592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getLeftLoc(),
779692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               move_arg(Args),
779792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getRightLoc());
779892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
779992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
780092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Instance message: transform the receiver
780192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
780292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         "Only class and instance messages may be instantiated");
780360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Receiver
780492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    = getDerived().TransformExpr(E->getInstanceReceiver());
780592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (Receiver.isInvalid())
7806f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
780792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
780892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // If nothing changed, just retain the existing message send.
780992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
781092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
78113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7812c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
781392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Build a new instance message send.
78149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
781592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getSelector(),
7816f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis                                             E->getSelectorLoc(),
781792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getMethodDecl(),
781892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getLeftLoc(),
781992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             move_arg(Args),
782092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getRightLoc());
7821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
782460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7825454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
78263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
783060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7831454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
78323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
783660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7837454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
7838f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
783960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7840f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7841f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7842f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor
7843f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // We don't need to transform the ivar; it will never change.
7844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7845f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7846f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7847f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
78483fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7849c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
78509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
7851f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->getLocation(),
7852f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->isArrow(), E->isFreeIvar());
7853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
785660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7857454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
785812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // 'super' and types never change. Property never changes. Just
785912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // retain the existing expression.
786012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (!E->isObjectReceiver())
78613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
78628ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian
7863e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // Transform the base expression.
786460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7865e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (Base.isInvalid())
7866f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7867c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7868e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // We don't need to transform the property; it will never change.
7869c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7870e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // If nothing changed, just retain the existing expression.
7871e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7872e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      Base.get() == E->getBase())
78733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
787512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (E->isExplicitProperty())
787612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
787712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getExplicitProperty(),
787812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getLocation());
787912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall
788012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
788112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getType(),
788212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertyGetter(),
788312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertySetter(),
788412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getLocation());
7885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
78871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
788860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7889454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
7890f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
789160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7892f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
7893f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7894c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7895f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
7896f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
7897f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
78983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7899c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
79009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
7901f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                         E->isArrow());
7902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
79041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
790560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7906454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
7907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
7908ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall  ASTOwningVector<Expr*> SubExprs(SemaRef);
7909aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  SubExprs.reserve(E->getNumSubExprs());
7910aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7911aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  SubExprs, &ArgumentChanged))
7912aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
79131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7915b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
79163fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
79171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7918b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7919b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               move_arg(SubExprs),
7920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               E->getRParenLoc());
7921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
79231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
792460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7925454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
7926c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockDecl *oldBlock = E->getBlockDecl();
7927a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7928c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7929c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7930c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7931c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7932ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // We built a new blockScopeInfo in call to ActOnBlockStart
7933ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // in above, CapturesCXXThis need be set here from the block
7934ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  // expression.
7935ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian  blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7936ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian
7937686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<ParmVarDecl*, 4> params;
7938686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<QualType, 4> paramTypes;
7939a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
7940a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Parameter substitution.
7941c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7942c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_begin(),
7943c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_size(),
7944c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               0, paramTypes, &params))
7945a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return true;
7946c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
7947c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  const FunctionType *exprFunctionType = E->getFunctionType();
7948c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType exprResultType = exprFunctionType->getResultType();
7949c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!exprResultType.isNull()) {
7950c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    if (!exprResultType->isDependentType())
7951c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      blockScope->ReturnType = exprResultType;
7952c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    else if (exprResultType != getSema().Context.DependentTy)
7953c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      blockScope->ReturnType = getDerived().TransformType(exprResultType);
7954a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
7955a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7956a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type has not been determined yet, leave it as a dependent
7957a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // type; it'll get set when we process the body.
7958c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType.isNull())
7959c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->ReturnType = getSema().Context.DependentTy;
7960a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7961a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // Don't allow returning a objc interface by value.
7962c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType->isObjCObjectType()) {
7963c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    getSema().Diag(E->getCaretLocation(),
7964a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                   diag::err_object_cannot_be_passed_returned_by_value)
7965c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall      << 0 << blockScope->ReturnType;
7966a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return ExprError();
7967a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  }
7968711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7969c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType functionType = getDerived().RebuildFunctionProtoType(
7970c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        blockScope->ReturnType,
7971c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.data(),
7972c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.size(),
7973c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        oldBlock->isVariadic(),
7974c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                        0, RQ_None,
7975c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               exprFunctionType->getExtInfo());
7976c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->FunctionType = functionType;
7977711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7978711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Set the parameters on the block decl.
7979c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!params.empty())
7980c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->TheDecl->setParams(params.data(), params.size());
7981a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7982a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // If the return type wasn't explicitly set, it will have been marked as a
7983a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // dependent type (DependentTy); clear out the return type setting so
7984a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // we will deduce the return type when type-checking the block's body.
7985c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (blockScope->ReturnType == getSema().Context.DependentTy)
7986c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall    blockScope->ReturnType = QualType();
7987a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
7988711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Transform the body
7989c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  StmtResult body = getDerived().TransformStmt(E->getBody());
7990c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (body.isInvalid())
7991711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    return ExprError();
7992711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
7993c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG
7994c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // In builds with assertions, make sure that we captured everything we
7995c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // captured before.
7996fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor  if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7997fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor    for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7998fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor           e = oldBlock->capture_end(); i != e; ++i) {
7999fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      VarDecl *oldCapture = i->getVariable();
8000fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor
8001fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      // Ignore parameter packs.
8002fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      if (isa<ParmVarDecl>(oldCapture) &&
8003fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor          cast<ParmVarDecl>(oldCapture)->isParameterPack())
8004fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor        continue;
8005c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
8006fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      VarDecl *newCapture =
8007fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor        cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8008fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor                                                 oldCapture));
8009fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      assert(blockScope->CaptureMap.count(newCapture));
8010fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor    }
8011c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  }
8012c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif
8013c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
8014c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8015c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                    /*Scope=*/0);
8016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8017b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
801960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8020454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
8021a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  ValueDecl *ND
8022a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8023a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian                                                       E->getDecl()));
8024a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!ND)
8025f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
80262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
8027a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  if (!getDerived().AlwaysRebuild() &&
8028a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian      ND == E->getDecl()) {
8029a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // Mark it referenced in the new context regardless.
8030a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    // FIXME: this is a bit instantiation-specific.
8031a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian    SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8032a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
80333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
8034a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  }
8035a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian
80362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
803740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
80382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                         ND, NameInfo, 0);
8039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
80401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
804161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnertemplate<typename Derived>
804261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerExprResult
804361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
804461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  assert(false && "Cannot transform asType expressions yet");
804561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  return SemaRef.Owned(E);
804661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}
804761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner
8048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
8049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction
8050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
8051b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
805385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
805485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                    SourceLocation Star) {
80552865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildPointerType(PointeeType, Star,
8056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  getDerived().getBaseEntity());
8057b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
806085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
806185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                         SourceLocation Star) {
80622865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildBlockPointerType(PointeeType, Star,
8063b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       getDerived().getBaseEntity());
8064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8065b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
80671eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
806885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
806985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             bool WrittenAsLValue,
807085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             SourceLocation Sigil) {
80712865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
807285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    Sigil, getDerived().getBaseEntity());
8073b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8074b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
80751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
80761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
807785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
807885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 QualType ClassType,
807985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceLocation Sigil) {
80802865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
808185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        Sigil, getDerived().getBaseEntity());
8082577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8083577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8084577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
80851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
8086577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8087577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         ArrayType::ArraySizeModifier SizeMod,
8088577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         const llvm::APInt *Size,
8089577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         Expr *SizeExpr,
8090577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         unsigned IndexTypeQuals,
8091577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         SourceRange BracketsRange) {
8092577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (SizeExpr || !Size)
8093577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8094577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  IndexTypeQuals, BracketsRange,
8095577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  getDerived().getBaseEntity());
80961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType Types[] = {
80981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
80991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
81001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
8101577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  };
8102577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8103577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType SizeType;
8104577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  for (unsigned I = 0; I != NumTypes; ++I)
8105577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8106577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      SizeType = Types[I];
8107577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      break;
8108577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    }
81091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
81119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                           /*FIXME*/BracketsRange.getBegin());
81121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
8113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                IndexTypeQuals, BracketsRange,
81141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                getDerived().getBaseEntity());
8115577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8117577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
8120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 ArrayType::ArraySizeModifier SizeMod,
8121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 const llvm::APInt &Size,
812285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
812385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceRange BracketsRange) {
81241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
812585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        IndexTypeQuals, BracketsRange);
8126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81291eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
8131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
813285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
813385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   SourceRange BracketsRange) {
81341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
813585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                       IndexTypeQuals, BracketsRange);
8136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81391eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
8141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
81429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SizeExpr,
8143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 unsigned IndexTypeQuals,
8144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceRange BracketsRange) {
81451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
81469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
8147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
8148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81511eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81521eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
8153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
81549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Expr *SizeExpr,
8155577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                       unsigned IndexTypeQuals,
8156577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                   SourceRange BracketsRange) {
81571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
81589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
8159577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
8160577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8161577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8162577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8163577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
8164e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               unsigned NumElements,
8165e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               VectorType::VectorKind VecKind) {
8166577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  // FIXME: semantic checking!
8167e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
8168577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8170577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8171577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8172577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                      unsigned NumElements,
8173577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceLocation AttributeLoc) {
8174577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8175577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                          NumElements, true);
8176577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  IntegerLiteral *VectorSize
81779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
81789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             AttributeLoc);
81799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
8180577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8182577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
81831eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
81841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
81859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                           Expr *SizeExpr,
8186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                  SourceLocation AttributeLoc) {
81879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
8188577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
81891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
81921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          QualType *ParamTypes,
8193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                        unsigned NumParamTypes,
81941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          bool Variadic,
8195fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                          unsigned Quals,
8196c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                  RefQualifierKind RefQualifier,
8197fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                            const FunctionType::ExtInfo &Info) {
81981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
8199c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                   Quals, RefQualifier,
8200577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   getDerived().getBaseLocation(),
8201fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   getDerived().getBaseEntity(),
8202fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   Info);
8203577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
82041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8205577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8206a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return SemaRef.Context.getFunctionNoProtoType(T);
8208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
8209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
8210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
8211ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8212ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  assert(D && "no decl found");
8213ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (D->isInvalidDecl()) return QualType();
8214ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
821592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // FIXME: Doesn't account for ObjCInterfaceDecl!
8216ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeDecl *Ty;
8217ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (isa<UsingDecl>(D)) {
8218ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    UsingDecl *Using = cast<UsingDecl>(D);
8219ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(Using->isTypeName() &&
8220ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-typename using");
8221ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8222ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    // A valid resolved using typename decl points to exactly one type decl.
8223ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(++Using->shadow_begin() == Using->shadow_end());
8224ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
8225c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8226ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  } else {
8227ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8228ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-using decl");
8229ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<UnresolvedUsingTypenameDecl>(D);
8230ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
8231ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8232ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return SemaRef.Context.getTypeDeclType(Ty);
8233ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
8234ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
8235ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived>
82362a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
82372a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                       SourceLocation Loc) {
82382a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildTypeofExprType(E, Loc);
8239577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8240577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8241577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8242577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8243577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  return SemaRef.Context.getTypeOfType(Underlying);
8244577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8245577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8246577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
82472a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
82482a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                     SourceLocation Loc) {
82492a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildDecltypeType(E, Loc);
8250577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8251577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8252577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8253ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8254ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                            UnaryTransformType::UTTKind UKind,
8255ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                            SourceLocation Loc) {
8256ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8257ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
8258ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
8259ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived>
8260577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
8261833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                      TemplateName Template,
8262833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateNameLoc,
826367714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                     TemplateArgumentListInfo &TemplateArgs) {
8264d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
8265577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
82661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8267dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
82681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
8269fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8270d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            bool TemplateKW,
8271d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            TemplateDecl *Template) {
8272fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
8273d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                                  Template);
8274d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
8275d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
8276d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
82771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
8278fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8279fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            const IdentifierInfo &Name,
8280fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SourceLocation NameLoc,
828143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            QualType ObjectType,
828243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            NamedDecl *FirstQualifierInScope) {
8283fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  UnqualifiedId TemplateName;
8284fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName.setIdentifier(&Name, NameLoc);
8285d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
8286d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
8287fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       /*FIXME:*/SourceLocation(),
8288d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
8289fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       TemplateName,
8290b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
8291d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
8292d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
829343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return Template.get();
8294d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
82951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
8297ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName
8298fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8299ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            OverloadedOperatorKind Operator,
8300fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SourceLocation NameLoc,
8301ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            QualType ObjectType) {
8302ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  UnqualifiedId Name;
8303fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  // FIXME: Bogus location information.
8304fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8305fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
8306d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
8307d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
8308fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                       /*FIXME:*/SourceLocation(),
8309d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       SS,
8310d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Name,
8311b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
8312d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
8313d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
8314d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  return Template.template getAsVal<TemplateName>();
8315ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor}
8316c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8317ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived>
831860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   SourceLocation OpLoc,
83219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *OrigCallee,
83229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *First,
83239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *Second) {
83249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Callee = OrigCallee->IgnoreParenCasts();
83259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
83261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8327b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Determine whether this should be a builtin operation.
8328f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript) {
83299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
83309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType())
83319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinArraySubscriptExpr(First,
83329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Callee->getLocStart(),
83339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Second, OpLoc);
83341a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman  } else if (Op == OO_Arrow) {
83351a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman    // -> is never a builtin operation.
83369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
83379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  } else if (Second == 0 || isPostIncDec) {
83389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType()) {
8339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // The argument is not of overloadable type, so try to create a
8340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // built-in unary operation.
83412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      UnaryOperatorKind Opc
8342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor        = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
83431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
8345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
8346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  } else {
83479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
83489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType()) {
8349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // Neither of the arguments is an overloadable type, so try to
8350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // create a built-in binary operation.
83512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
835260d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Result
83539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
8354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Result.isInvalid())
8355f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
83561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      return move(Result);
8358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
8359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
83601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Compute the transformed set of functions (and function templates) to be
8362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // used during overload resolution.
83636e26689f5d513e24ad7783a4493201930fdeccc0John McCall  UnresolvedSet<16> Functions;
83641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
8366ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    assert(ULE->requiresADL());
8367ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
8368ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // FIXME: Do we have to check
8369ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // IsAcceptableNonMemberOperatorCandidate for each of these?
83706e26689f5d513e24ad7783a4493201930fdeccc0John McCall    Functions.append(ULE->decls_begin(), ULE->decls_end());
8371ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  } else {
83729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
8373ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
83741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Add any functions found via argument-dependent lookup.
83769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Args[2] = { First, Second };
83779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  unsigned NumArgs = 1 + (Second != 0);
83781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for unary operators.
8380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (NumArgs == 1 || isPostIncDec) {
83812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    UnaryOperatorKind Opc
8382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
83839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
8384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
83851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83865b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor  if (Op == OO_Subscript) {
83875b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    SourceLocation LBrace;
83885b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    SourceLocation RBrace;
83895b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor
83905b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
83915b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
83925b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        LBrace = SourceLocation::getFromRawEncoding(
83935b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor                    NameLoc.CXXOperatorName.BeginOpNameLoc);
83945b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        RBrace = SourceLocation::getFromRawEncoding(
83955b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor                    NameLoc.CXXOperatorName.EndOpNameLoc);
83965b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    } else {
83975b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        LBrace = Callee->getLocStart();
83985b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        RBrace = OpLoc;
83995b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    }
84005b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor
84015b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
84025b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor                                                      First, Second);
84035b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor  }
8404f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl
8405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for binary operators.
84062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
840760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result
8408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Result.isInvalid())
8410f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
84111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
84121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return move(Result);
8413b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
84141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
841526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived>
841660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
84179ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
841826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceLocation OperatorLoc,
841926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       bool isArrow,
8420f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                                       CXXScopeSpec &SS,
842126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     TypeSourceInfo *ScopeType,
842226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       SourceLocation CCLoc,
8423fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                       SourceLocation TildeLoc,
8424a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed) {
84259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  QualType BaseType = Base->getType();
84269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
842726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      (!isArrow && !BaseType->getAs<RecordType>()) ||
8428c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      (isArrow && BaseType->getAs<PointerType>() &&
8429bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif       !BaseType->getAs<PointerType>()->getPointeeType()
8430bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif                                              ->template getAs<RecordType>())){
843126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    // This pseudo-destructor expression is still a pseudo-destructor.
84329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
843326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             isArrow? tok::arrow : tok::period,
8434fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                             SS, ScopeType, CCLoc, TildeLoc,
8435a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                             Destroyed,
843626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             /*FIXME?*/true);
843726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
84382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
8439a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
84402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
84412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
84422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
84432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  NameInfo.setNamedTypeInfo(DestroyedType);
84442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
844526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  // FIXME: the ScopeType should be tacked onto SS.
84462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
84479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getSema().BuildMemberReferenceExpr(Base, BaseType,
844826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            OperatorLoc, isArrow,
844926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            SS, /*FIXME: FirstQualifier*/ 0,
84502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            NameInfo,
845126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            /*TemplateArgs*/ 0);
845226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor}
845326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
8454577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang
8455577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8456577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
8457