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"
34a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie#include "llvm/ADT/ArrayRef.h"
35a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h"
367e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h"
37577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm>
38577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
39577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang {
40781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema;
411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one
43577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another.
44577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of
461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide
471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template
48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the
49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the
50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar
51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and
52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters.
53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
54577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow
551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can
56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an
57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The
58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual.
59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which
61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node
62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions,
63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation
65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g.,
66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes
67577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create
68577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node.
69577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The
71670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(),
729151c11836f5fbb36cedfe4d22df7e00e77a1d42Douglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations.
75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
76577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the
77577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
7843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
79577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation
801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template
81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX
82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change.
83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps.
86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor///
87577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one
881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation
89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the
91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking
92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()).
93577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
94577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform {
95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief Private RAII object that helps us forget and then re-remember
96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// the template argument corresponding to a partially-substituted parameter
97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack.
98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  class ForgetPartiallySubstitutedPackRAII {
99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    Derived &Self;
100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    TemplateArgument Old;
1014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  public:
103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Old = Self.ForgetPartiallySubstitutedPack();
105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
1064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    ~ForgetPartiallySubstitutedPackRAII() {
108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      Self.RememberPartiallySubstitutedPack(Old);
109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    }
110d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  };
1114a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected:
113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &SemaRef;
1144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
115dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief The set of local declarations that have been transformed, for
116dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// cases where we are forced to build new declarations within the transformer
117dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// rather than in the subclass (e.g., lambda closure types).
118dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
1194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Initializes a new tree transformer.
122b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Derived &getDerived() { return static_cast<Derived&>(*this); }
126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the derived class.
1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Derived &getDerived() const {
1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return static_cast<const Derived&>(*this);
130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
13260d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline ExprResult Owned(Expr *E) { return E; }
13360d7b3a319d84d688752be3870615ac0f111fb16John McCall  static inline StmtResult Owned(Stmt *S) { return S; }
1349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall
135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Retrieves a reference to the semantic analysis object used for
136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// this tree transform.
137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  Sema &getSema() const { return SemaRef; }
1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Whether the transformation should always rebuild AST nodes, even
140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// if none of the children have changed.
141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this function to specify when the transformation
143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// should rebuild all AST nodes.
144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlwaysRebuild() { return false; }
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the location of the entity being transformed, if that
147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, returns no source-location information. Subclasses can
150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// provide an alternative implementation that provides better location
151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information.
152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  SourceLocation getBaseLocation() { return SourceLocation(); }
1531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Returns the name of the entity being transformed, if that
155577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// information was not available elsewhere in the AST.
156577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
157577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, returns an empty name. Subclasses can provide an alternative
158577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// implementation with a more precise name.
159577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  DeclarationName getBaseEntity() { return DeclarationName(); }
160577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Sets the "base" location and entity when that
162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// information is known based on another transformation.
163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, the source location and entity are ignored. Subclasses can
165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// override this function to provide a customized implementation.
166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  void setBase(SourceLocation Loc, DeclarationName Entity) { }
1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief RAII object that temporarily sets the base location and entity
169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// used for reporting diagnostics in types.
170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  class TemporaryBase {
171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TreeTransform &Self;
172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    SourceLocation OldLocation;
173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclarationName OldEntity;
1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  public:
176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TemporaryBase(TreeTransform &Self, SourceLocation Location,
1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                  DeclarationName Entity) : Self(Self) {
178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldLocation = Self.getDerived().getBaseLocation();
179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      OldEntity = Self.getDerived().getBaseEntity();
1804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
181ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor      if (Location.isValid())
182ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor        Self.getDerived().setBase(Location, Entity);
183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
1841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ~TemporaryBase() {
186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Self.getDerived().setBase(OldLocation, OldEntity);
187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  };
1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determine whether the given type \p T has already been
191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// transformed.
192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses can provide an alternative implementation of this routine
1941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// to short-circuit evaluation when it is known that a given type will
195577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// not change. For example, template instantiation need not traverse
196577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// non-dependent types.
197577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  bool AlreadyTransformed(QualType T) {
198577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T.isNull();
199577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
200577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether the given call argument should be dropped, e.g.,
2026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// because it is a default argument.
2036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
2046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Subclasses can provide an alternative implementation of this routine to
2056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// determine which kinds of call arguments get dropped. By default,
2066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// CXXDefaultArgument nodes are dropped (prior to transformation).
2076eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool DropCallArgument(Expr *E) {
2086eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return E->isDefaultArgument();
2096eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
2104a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Determine whether we should expand a pack expansion with the
2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// given set of parameter packs into separate arguments by repeatedly
2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// transforming the pattern.
2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
215b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor  /// By default, the transformer never tries to expand pack expansions.
2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// Subclasses can override this routine to provide different behavior.
2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param EllipsisLoc The location of the ellipsis that identifies the
2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pack expansion.
2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param PatternRange The source range that covers the entire pattern of
2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// the pack expansion.
2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// \param Unexpanded The set of unexpanded parameter packs within the
2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// pattern.
2268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param ShouldExpand Will be set to \c true if the transformer should
2288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// expand the corresponding pack expansions into separate arguments. When
2298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// set, \c NumExpansions must also be set.
2308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
231d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \param RetainExpansion Whether the caller should add an unexpanded
232d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// pack expansion after all of the expanded arguments. This is used
233d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when extending explicitly-specified template argument packs per
234d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// C++0x [temp.arg.explicit]p9.
235d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
2368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \param NumExpansions The number of separate arguments that will be in
237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// the expanded form of the corresponding pack expansion. This is both an
238cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// input and an output parameter, which can be set by the caller if the
239cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// number of expansions is known a priori (e.g., due to a prior substitution)
240cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// and will be set by the callee when the number of expansions is known.
241cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// The callee must set this value when \c ShouldExpand is \c true; it may
242cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// set this value in other cases.
2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
2444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// \returns true if an error occurred (e.g., because the parameter packs
2454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// are to be instantiated with arguments of different lengths), false
2464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// must be set.
2488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
2498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               SourceRange PatternRange,
250a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie                             llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
2518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                               bool &ShouldExpand,
252d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                               bool &RetainExpansion,
253cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                               llvm::Optional<unsigned> &NumExpansions) {
2548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    ShouldExpand = false;
2558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return false;
2568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
2574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Forget" about the partially-substituted pack template argument,
259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// when performing an instantiation that must preserve the parameter pack
260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  TemplateArgument ForgetPartiallySubstitutedPack() {
264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor    return TemplateArgument();
265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  }
2664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// \brief "Remember" the partially-substituted pack template argument
268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// after performing an instantiation that must preserve the parameter pack
269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// use.
270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  ///
271d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  /// This routine is meant to be overridden by the template instantiator.
272d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
2734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// \brief Note to the derived class when a function parameter pack is
27512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  /// being expanded.
27612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor  void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
2774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
278577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transforms the given type into another type.
279577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by creating a
281a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// TypeSourceInfo for it and delegating to the appropriate
282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// function.  This is expensive, but we don't mind, because
283a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// this method is deprecated anyway;  all users should be
284a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// switched to storing TypeSourceInfos.
285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \returns the transformed type.
28743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(QualType T);
2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transforms the given type-with-location into a new
290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type-with-location.
291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ///
292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// By default, this routine transforms a type by delegating to the
293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// appropriate TransformXXXType to build a new type.  Subclasses
294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// may override this function (to take over all type
295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// transformations) or some set of the TransformXXXType functions
296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// to alter the transformation.
29743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *TransformType(TypeSourceInfo *DI);
298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Transform the given type-with-location into a new
300a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// type, collecting location information in the given builder
301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// as necessary.
302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
30343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
3041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
305657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given statement.
306577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
3071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this routine transforms a statement by delegating to the
30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// appropriate TransformXXXStmt function to transform a specific kind of
30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// statement or the TransformExpr() function to transform an expression.
31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to transform statements using some
31143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// other mechanism.
31243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
31343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \returns the transformed statement.
31460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformStmt(Stmt *S);
3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
316657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  /// \brief Transform the given expression.
317657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor  ///
318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine transforms an expression by delegating to the
319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// appropriate TransformXXXExpr function to build a new expression.
320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this function to transform expressions using some
321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// other mechanism.
322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \returns the transformed expression.
32460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformExpr(Expr *E);
3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Transform the given list of expressions.
327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
3284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// This routine transforms a list of expressions by invoking
3294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// \c TransformExpr() for each subexpression. However, it also provides
330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// support for variadic templates by expanding any pack expansions (if the
331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// derived class permits such expansion) along the way. When pack expansions
332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// are present, the number of outputs may not equal the number of inputs.
333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Inputs The set of expressions to be transformed.
335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param NumInputs The number of expressions in \c Inputs.
337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param IsCall If \c true, then this transform is being performed on
3394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// function-call arguments, and any arguments that should be dropped, will
340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// be.
341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param Outputs The transformed input expressions will be added to this
343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// vector.
344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// due to transformation.
347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  ///
348aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \returns true if an error occurred, false otherwise.
349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
350686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                      SmallVectorImpl<Expr *> &Outputs,
351aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                      bool *ArgChanged = 0);
3524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given declaration, which is referenced from a type
354577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// or expression.
355577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
356dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// By default, acts as the identity function on declarations, unless the
357dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// transformer has had to transform the declaration itself. Subclasses
358dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  /// may override this function to provide alternate behavior.
3594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  Decl *TransformDecl(SourceLocation Loc, Decl *D) {
360dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    llvm::DenseMap<Decl *, Decl *>::iterator Known
361dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor      = TransformedLocalDecls.find(D);
362dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    if (Known != TransformedLocalDecls.end())
363dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor      return Known->second;
3644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return D;
366dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  }
36743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
3684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// \brief Transform the attributes associated with the given declaration and
369dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// place them on the new declaration.
370dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  ///
371dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// By default, this operation does nothing. Subclasses may override this
372dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// behavior to transform attributes.
373dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  void transformAttrs(Decl *Old, Decl *New) { }
3744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
375dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Note that a local declaration has been transformed by this
376dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// transformer.
377dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  ///
3784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// Local declarations are typically transformed via a call to
379dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// TransformDefinition. However, in some cases (e.g., lambda expressions),
380dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// the transformer itself has to transform the declarations. This routine
381dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// can be overridden by a subclass that keeps track of such mappings.
382dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  void transformedLocalDecl(Decl *Old, Decl *New) {
383dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    TransformedLocalDecls[Old] = New;
384dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  }
3854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
38643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Transform the definition of the given declaration.
38743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, invokes TransformDecl() to transform the declaration.
38943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
3904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
3914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return getDerived().TransformDecl(Loc, D);
3927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  }
3931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3946cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// \brief Transform the given declaration, which was the first part of a
3956cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// nested-name-specifier in a member access expression.
3966cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
3974a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// This specific declaration transformation only applies to the first
3986cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// identifier in a nested-name-specifier of a member access expression, e.g.,
3996cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// the \c T in \c x->T::member
4006cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  ///
4016cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// By default, invokes TransformDecl() to transform the declaration.
4026cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  /// Subclasses may override this function to provide alternate behavior.
4034a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
4044a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
4056cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  }
4064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
407c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// \brief Transform the given nested-name-specifier with source-location
408c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// information.
409c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  ///
410c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// By default, transforms all of the types and declarations within the
411c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// nested-name-specifier. Subclasses may override this function to provide
412c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  /// alternate behavior.
413c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
414c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                    NestedNameSpecifierLoc NNS,
415c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                          QualType ObjectType = QualType(),
416c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                          NamedDecl *FirstQualifierInScope = 0);
417c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
41881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// \brief Transform the given declaration name.
41981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  ///
42081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// By default, transforms the types of conversion function, constructor,
42181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// and destructor names and then (if needed) rebuilds the declaration name.
42281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// Identifiers and selectors are returned unmodified. Sublcasses may
42381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  /// override this function to provide alternate behavior.
4242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo
42543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
4261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
427577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template name.
4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
429fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param SS The nested-name-specifier that qualifies the template
430fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// name. This nested-name-specifier must already have been transformed.
431fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
432fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param Name The template name to transform.
433fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
434fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param NameLoc The source location of the template name.
435fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
4364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// \param ObjectType If we're translating a template name within a member
437fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// access expression, this is the type of the object whose member template
438fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// is being referenced.
439fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
440fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// \param FirstQualifierInScope If the first part of a nested-name-specifier
441fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// also refers to a name within the current (lexical) scope, this is the
442fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// declaration it refers to.
443fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  ///
444fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// By default, transforms the template name by transforming the declarations
445fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// and nested-name-specifiers that occur within the template name.
446fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  /// Subclasses may override this function to provide alternate behavior.
447fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName TransformTemplateName(CXXScopeSpec &SS,
448fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     TemplateName Name,
449e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                     SourceLocation NameLoc,
450fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     QualType ObjectType = QualType(),
451fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                     NamedDecl *FirstQualifierInScope = 0);
452fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
453577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Transform the given template argument.
454577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, this operation transforms the type, expression, or
4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// declaration stored within the template argument and constructs a
457670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// new template argument from the transformed result. Subclasses may
458670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  /// override this function to provide alternate behavior.
459833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  ///
460833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// Returns true if there was an error.
461833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
462833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &Output);
463833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
464fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \brief Transform the given set of template arguments.
465fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
4664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// By default, this operation transforms all of the template arguments
467fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
468fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// the transformed arguments to the output list.
469fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
4707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// Note that this overload of \c TransformTemplateArguments() is merely
4717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// a convenience function. Subclasses that wish to override this behavior
4727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// should override the iterator-based member template version.
4737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
474fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Inputs The set of template arguments to be transformed.
475fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
476fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param NumInputs The number of template arguments in \p Inputs.
477fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
478fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// \param Outputs The set of transformed template arguments output by this
479fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// routine.
480fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  ///
481fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  /// Returns true if an error occurred.
482fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
483fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                  unsigned NumInputs,
4847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs) {
4857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
4867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
4877f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
4887f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \brief Transform the given set of template arguments.
4897f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// By default, this operation transforms all of the template arguments
4917f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// in the input set using \c TransformTemplateArgument(), and appends
4924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// the transformed arguments to the output list.
4937f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param First An iterator to the first template argument.
4957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
4967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \param Last An iterator one step past the last template argument.
4977f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
4987f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// \param Outputs The set of transformed template arguments output by this
4997f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// routine.
5007f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  ///
5017f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  /// Returns true if an error occurred.
5027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename InputIterator>
5037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  bool TransformTemplateArguments(InputIterator First,
5047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  InputIterator Last,
5057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                  TemplateArgumentListInfo &Outputs);
5067f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
507833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
508833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  void InventTemplateArgumentLoc(const TemplateArgument &Arg,
509833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                 TemplateArgumentLoc &ArgLoc);
510833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
511a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// \brief Fakes up a TypeSourceInfo for a type.
512a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *InventTypeSourceInfo(QualType T) {
513a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return SemaRef.Context.getTrivialTypeSourceInfo(T,
514833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                       getDerived().getBaseLocation());
515833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
5161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
517a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT)                                   \
51943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
522cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
523cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor                                      FunctionProtoTypeLoc TL,
524cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor                                      CXXRecordDecl *ThisContext,
525cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor                                      unsigned ThisTypeQuals);
526cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor
52728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult
52828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  TransformSEHHandler(Stmt *Handler);
52928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
5304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType
53143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformTemplateSpecializationType(TypeLocBuilder &TLB,
53243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateSpecializationTypeLoc TL,
53343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      TemplateName Template);
53443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
5354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType
53643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
53743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentTemplateSpecializationTypeLoc TL,
538087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                               TemplateName Template,
539087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                               CXXScopeSpec &SS);
540a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
5414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType
542a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
54394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                               DependentTemplateSpecializationTypeLoc TL,
54494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                         NestedNameSpecifierLoc QualifierLoc);
54594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
54621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms the parameters of a function type into the
54721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// given vectors.
54821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
54921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// The result vectors should be kept in sync; null entries in the
55021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// variables vector are acceptable.
55121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  ///
55221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// Return true on error.
553a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  bool TransformFunctionTypeParams(SourceLocation Loc,
554a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   ParmVarDecl **Params, unsigned NumParams,
555a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                   const QualType *ParamTypes,
556686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                   SmallVectorImpl<QualType> &PTypes,
557686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                   SmallVectorImpl<ParmVarDecl*> *PVars);
55821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
55921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// \brief Transforms a single function-type parameter.  Return null
56021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  /// on error.
561fb44de956f27875def889482b5393475060392afJohn McCall  ///
562fb44de956f27875def889482b5393475060392afJohn McCall  /// \param indexAdjustment - A number to add to the parameter's
563fb44de956f27875def889482b5393475060392afJohn McCall  ///   scope index;  can be negative
5646a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
565fb44de956f27875def889482b5393475060392afJohn McCall                                          int indexAdjustment,
566d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                        llvm::Optional<unsigned> NumExpansions,
567d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                          bool ExpectParameterPack);
56821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
56943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
570833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
57160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
57260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
5731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
574612409ece080e814f79e06772c690d603f45fbd6Richard Smith  /// \brief Transform the captures and body of a lambda expression.
575612409ece080e814f79e06772c690d603f45fbd6Richard Smith  ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
576612409ece080e814f79e06772c690d603f45fbd6Richard Smith
57743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                        \
57860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Transform##Node(Node *S);
579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                        \
58060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Transform##Node(Node *E);
5817381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
5824bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
5831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new pointer type given its pointee type.
585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the pointer type.
587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
58885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new block pointer type given its pointee type.
591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis when building the block pointer
593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
59485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
59685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \brief Build a new reference type given the type it references.
597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
59885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// By default, performs semantic analysis when building the
59985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// reference type. Subclasses may override this routine to provide
60085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// different behavior.
601577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
60285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// \param LValue whether the type was written with an lvalue sigil
60385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  /// or an rvalue sigil.
60485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildReferenceType(QualType ReferentType,
60585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                bool LValue,
60685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                SourceLocation Sigil);
6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new member pointer type given the pointee type and the
609577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// class type it refers into.
610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
611577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the member pointer
612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// type. Subclasses may override this routine to provide different behavior.
61385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
61485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceLocation Sigil);
6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new array type given the element type, size
617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, size of the array (if known), size expression, and index type
618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// qualifiers.
619577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Also by default, all of the other Rebuild*Array
623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildArrayType(QualType ElementType,
624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            ArrayType::ArraySizeModifier SizeMod,
625577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            const llvm::APInt *Size,
626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            Expr *SizeExpr,
627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            unsigned IndexTypeQuals,
628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                            SourceRange BracketsRange);
6291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new constant array type given the element type, size
631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, (known) size of the array, and index type qualifiers.
632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildConstantArrayType(QualType ElementType,
636577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    const llvm::APInt &Size,
63885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    unsigned IndexTypeQuals,
63985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    SourceRange BracketsRange);
640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
641577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new incomplete array type given the element type, size
642577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// modifier, and index type qualifiers.
643577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildIncompleteArrayType(QualType ElementType,
647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                      ArrayType::ArraySizeModifier SizeMod,
64885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      unsigned IndexTypeQuals,
64985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                      SourceRange BracketsRange);
650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new variable-length array type given the element type,
652577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildVariableArrayType(QualType ElementType,
657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    ArrayType::ArraySizeModifier SizeMod,
6589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SizeExpr,
659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned IndexTypeQuals,
660577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    SourceRange BracketsRange);
661577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new dependent-sized array type given the element type,
663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// size modifier, size expression, and index type qualifiers.
664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the array type.
666577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedArrayType(QualType ElementType,
668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
6699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *SizeExpr,
670577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          unsigned IndexTypeQuals,
671577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          SourceRange BracketsRange);
672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
673577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new vector type given the element type and
674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
676577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
677577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
67882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
679e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                             VectorType::VectorKind VecKind);
6801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new extended vector type given the element type and
682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// number of elements.
683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                SourceLocation AttributeLoc);
6881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new potentially dependently-sized extended vector type
690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// given the element type and number of elements.
691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the vector type.
693577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType RebuildDependentSizedExtVectorType(QualType ElementType,
6959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *SizeExpr,
696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                              SourceLocation AttributeLoc);
6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
698577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new function type.
699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
700577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the function type.
701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildFunctionProtoType(QualType T,
7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    QualType *ParamTypes,
704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                    unsigned NumParamTypes,
705eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith                                    bool Variadic, bool HasTrailingReturn,
706eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith                                    unsigned Quals,
707c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                    RefQualifierKind RefQualifier,
708fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                    const FunctionType::ExtInfo &Info);
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  /// \brief Build a new unprototyped function type.
711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType RebuildFunctionNoProtoType(QualType ResultType);
712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
713ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// \brief Rebuild an unresolved typename type, given the decl that
714ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  /// the UnresolvedUsingTypenameDecl was transformed to.
715ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType RebuildUnresolvedUsingType(Decl *D);
716ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
717577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typedef type.
718162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Typedef);
720577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
721577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
722577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new class/struct/union type.
723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildRecordType(RecordDecl *Record) {
724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Record);
725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new Enum type.
728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildEnumType(EnumDecl *Enum) {
729577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.Context.getTypeDeclType(Enum);
730577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
7317da2431c23ef1ee8acb114e39692246e1801afc2John McCall
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(expr) type.
733577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
734577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typeof type.
735577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
7362a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
737577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new typeof(type) type.
739577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, builds a new TypeOfType with the given underlying type.
741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTypeOfType(QualType Underlying);
742577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
743ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// \brief Build a new unary transform type.
744ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType RebuildUnaryTransformType(QualType BaseType,
745ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                     UnaryTransformType::UTTKind UKind,
746ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                     SourceLocation Loc);
747ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++0x decltype type.
749577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
750577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the decltype type.
751577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
7522a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75434b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Build a new C++0x auto type.
75534b41d939a1328f484511c6002ba2456db879a29Richard Smith  ///
75634b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// By default, builds a new AutoType with the given deduced type.
75734b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType RebuildAutoType(QualType Deduced) {
75834b41d939a1328f484511c6002ba2456db879a29Richard Smith    return SemaRef.Context.getAutoType(Deduced);
75934b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
76034b41d939a1328f484511c6002ba2456db879a29Richard Smith
761577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new template specialization type.
762577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
763577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the template
764577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// specialization type. Subclasses may override this routine to provide
765577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
766577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType RebuildTemplateSpecializationType(TemplateName Template,
767833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateLoc,
76867714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                             TemplateArgumentListInfo &Args);
7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
770075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// \brief Build a new parenthesized type.
771075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ///
772075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// By default, builds a new ParenType type from the inner type.
773075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
774075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType RebuildParenType(QualType InnerType) {
775075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return SemaRef.Context.getParenType(InnerType);
776075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
777075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
778577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new qualified name type.
779577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
780465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// By default, builds a new ElaboratedType type from the keyword,
781465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// the nested-name-specifier and the named type.
782465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// Subclasses may override this routine to provide different behavior.
78321e413fe6305a198564d436ac515497716c47844John McCall  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
78421e413fe6305a198564d436ac515497716c47844John McCall                                 ElaboratedTypeKeyword Keyword,
7859e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                 NestedNameSpecifierLoc QualifierLoc,
7869e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                 QualType Named) {
7874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return SemaRef.Context.getElaboratedType(Keyword,
7884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                         QualifierLoc.getNestedNameSpecifier(),
7899e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                             Named);
7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
791577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
792577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to a template-id.
793577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
794e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// By default, builds a new DependentNameType type from the
795e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// nested-name-specifier and the given type. Subclasses may override
796e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// this routine to provide different behavior.
79733500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType RebuildDependentTemplateSpecializationType(
79894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          ElaboratedTypeKeyword Keyword,
79994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
80094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          const IdentifierInfo *Name,
80194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                          SourceLocation NameLoc,
80267714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                          TemplateArgumentListInfo &Args) {
80394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Rebuild the template name.
80494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // TODO: avoid TemplateName abstraction
805fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    CXXScopeSpec SS;
806fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    SS.Adopt(QualifierLoc);
8074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    TemplateName InstName
808fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
8094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
81094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (InstName.isNull())
81194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return QualType();
8124a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
81394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // If it's still dependent, make a dependent specialization.
81494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (InstName.getAsDependentTemplateName())
8154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
8164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                          QualifierLoc.getNestedNameSpecifier(),
8174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                                                    Name,
81894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                                    Args);
8194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
82094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Otherwise, make an elaborated type wrapping a non-dependent
82194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // specialization.
82294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualType T =
82394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
82494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (T.isNull()) return QualType();
8254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
82694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
82794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      return T;
8284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return SemaRef.Context.getElaboratedType(Keyword,
8304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                       QualifierLoc.getNestedNameSpecifier(),
83194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                             T);
83294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  }
83394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
834577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// \brief Build a new typename type that refers to an identifier.
835577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  ///
836577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// By default, performs semantic analysis when building the typename type
837e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  /// (or elaborated type). Subclasses may override this routine to provide
838577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  /// different behavior.
839e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
840e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation KeywordLoc,
8412494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                    NestedNameSpecifierLoc QualifierLoc,
8422494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                    const IdentifierInfo *Id,
843e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara                                    SourceLocation IdLoc) {
8444033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    CXXScopeSpec SS;
8452494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    SS.Adopt(QualifierLoc);
846e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara
8472494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
8484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      // If the name is still dependent, just build a new dependent name type.
8494033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      if (!SemaRef.computeDeclContext(SS))
8504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        return SemaRef.Context.getDependentNameType(Keyword,
8514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                          QualifierLoc.getNestedNameSpecifier(),
8522494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                                    Id);
8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    if (Keyword == ETK_None || Keyword == ETK_Typename)
8562494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor      return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
857e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor                                       *Id, IdLoc);
858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
859465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
860465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
861e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    // We had a dependent elaborated-type-specifier that has been transformed
8624033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // into a non-dependent elaborated-type-specifier. Find the tag we're
8634033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // referring to.
864e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
8654033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    DeclContext *DC = SemaRef.computeDeclContext(SS, false);
8664033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!DC)
8674033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
8684033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8695613876991c80a684595fe8de1f039296a0657ffJohn McCall    if (SemaRef.RequireCompleteDeclContext(SS, DC))
8705613876991c80a684595fe8de1f039296a0657ffJohn McCall      return QualType();
8715613876991c80a684595fe8de1f039296a0657ffJohn McCall
8724033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    TagDecl *Tag = 0;
8734033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    SemaRef.LookupQualifiedName(Result, DC);
8744033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    switch (Result.getResultKind()) {
8754033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFound:
8764033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::NotFoundInCurrentInstantiation:
8774033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
8784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8794033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Found:
8804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        Tag = Result.getAsSingle<TagDecl>();
8814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        break;
8824a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8834033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundOverloaded:
8844033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::FoundUnresolvedValue:
8854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        llvm_unreachable("Tag lookup cannot find non-tags");
8864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      case LookupResult::Ambiguous:
8884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        // Let the LookupResult structure handle ambiguities.
8894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor        return QualType();
8904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
8914033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
8924033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    if (!Tag) {
893446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // Check where the name exists but isn't a tag type and use that to emit
894446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      // better diagnostics.
895446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      SemaRef.LookupQualifiedName(Result, DC);
897446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      switch (Result.getResultKind()) {
898446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::Found:
899446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundOverloaded:
900446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        case LookupResult::FoundUnresolvedValue: {
9013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith          NamedDecl *SomeDecl = Result.getRepresentativeDecl();
902446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          unsigned Kind = 0;
903446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
904162e1c1b487352434552147967c3dd296ebee2f7Richard Smith          else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905162e1c1b487352434552147967c3dd296ebee2f7Richard Smith          else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
906446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
908446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
9093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        }
910446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky        default:
911446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          // FIXME: Would be nice to highlight just the source range.
912446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
913446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky            << Kind << Id << DC;
914446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky          break;
915446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky      }
9164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
9174033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
918465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
919bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu    if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
920bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu                                              IdLoc, *Id)) {
921e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
9224033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
9234033642464e8ba0982f88f34cffad808d247b393Douglas Gregor      return QualType();
9244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    }
9254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
9264033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    // Build the elaborated-type-specifier type.
9274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    QualType T = SemaRef.Context.getTypeDeclType(Tag);
9284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return SemaRef.Context.getElaboratedType(Keyword,
9294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                         QualifierLoc.getNestedNameSpecifier(),
9302494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                             T);
931dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor  }
9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9332fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// \brief Build a new pack expansion type.
9342fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  ///
9352fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// By default, builds a new PackExpansionType type from the given pattern.
9362fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
9374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType RebuildPackExpansionType(QualType Pattern,
9382fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                    SourceRange PatternRange,
939cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    SourceLocation EllipsisLoc,
940cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                    llvm::Optional<unsigned> NumExpansions) {
941cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
942cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                        NumExpansions);
9432fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
9442fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor
945b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  /// \brief Build a new atomic type given its value type.
946b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  ///
947b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  /// By default, performs semantic analysis when building the atomic type.
948b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  /// Subclasses may override this routine to provide different behavior.
949b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
950b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
951d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier, a flag
952d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// indicating whether the "template" keyword was provided, and the template
953d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// that the template name refers to.
954d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
955d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, builds the new template name directly. Subclasses may override
956d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// this routine to provide different behavior.
957fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
958d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   bool TemplateKW,
959d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                   TemplateDecl *Template);
960d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
961d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// \brief Build a new template name given a nested name specifier and the
962d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// name that is referred to as a template.
963d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  ///
964d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
965d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
966d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// template name. Subclasses may override this routine to provide different
967d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor  /// behavior.
968fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   const IdentifierInfo &Name,
970fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   SourceLocation NameLoc,
97143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   QualType ObjectType,
97243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                   NamedDecl *FirstQualifierInScope);
9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
974ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// \brief Build a new template name given a nested name specifier and the
975ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// overloaded operator name that is referred to as a template.
976ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  ///
977ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// By default, performs semantic analysis to determine whether the name can
978ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
979ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// template name. Subclasses may override this routine to provide different
980ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  /// behavior.
981fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName RebuildTemplateName(CXXScopeSpec &SS,
982ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   OverloadedOperatorKind Operator,
983fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                   SourceLocation NameLoc,
984ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                   QualType ObjectType);
9851aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
9861aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// \brief Build a new template name given a template template parameter pack
9874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// and the
9881aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  ///
9891aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// By default, performs semantic analysis to determine whether the name can
9901aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// be resolved to a specific template, then builds the appropriate kind of
9911aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// template name. Subclasses may override this routine to provide different
9921aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  /// behavior.
9931aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
9941aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                   const TemplateArgument &ArgPack) {
9951aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor    return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
9961aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor  }
9971aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor
99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new compound statement.
99943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
100043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
100260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
100343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       MultiStmtArg Statements,
100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       SourceLocation RBraceLoc,
100543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       bool IsStmtExpr) {
10069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                       IsStmtExpr);
100843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
101043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new case statement.
101143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
101243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
101343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
101460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
10159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *LHS,
101643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EllipsisLoc,
10179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Expr *RHS,
101843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation ColonLoc) {
10199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
102043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   ColonLoc);
102143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to a new case statement.
102443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
102543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
102643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
102760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
10289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    getSema().ActOnCaseStmtBody(S, Body);
10299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return S;
103043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new default statement.
103343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
103443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
103543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
103660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      SourceLocation ColonLoc,
10389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      Stmt *SubStmt) {
10399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
104043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      /*CurScope=*/0);
104143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
104343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new label statement.
104443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
104543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
104643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
104757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
104857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                              SourceLocation ColonLoc, Stmt *SubStmt) {
104957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
105043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1052534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  /// \brief Build a new label statement.
1053534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  ///
1054534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  /// By default, performs semantic analysis to build the new statement.
1055534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  /// Subclasses may override this routine to provide different behavior.
10564990890fc9428f98bef90ba349203a648c592778Alexander Kornienko  StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
10574990890fc9428f98bef90ba349203a648c592778Alexander Kornienko                                   ArrayRef<const Attr*> Attrs,
1058534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith                                   Stmt *SubStmt) {
1059534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1060534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  }
1061534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
106243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new "if" statement.
106343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
106443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
106543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
106660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
10674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                           VarDecl *CondVar, Stmt *Then,
106857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                           SourceLocation ElseLoc, Stmt *Else) {
106944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis    return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
107043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Start building a new switch statement.
107343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
107443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
107543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
107660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
107757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                    Expr *Cond, VarDecl *CondVar) {
10784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
1079d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                            CondVar);
108043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Attach the body to the switch statement.
108343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
108443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
108543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
108660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
108757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                   Stmt *Switch, Stmt *Body) {
10889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
109043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
109143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new while statement.
109243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
109343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
109443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
109557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
109657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                              VarDecl *CondVar, Stmt *Body) {
10979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
109843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
110043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new do-while statement.
110143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
110243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
110343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
110460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
1105ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                           SourceLocation WhileLoc, SourceLocation LParenLoc,
1106ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                           Expr *Cond, SourceLocation RParenLoc) {
11079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
11089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 Cond, RParenLoc);
110943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
111043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
111143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new for statement.
111243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
111343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
111443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1115ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
11164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                            Stmt *Init, Sema::FullExprArg Cond,
1117ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            VarDecl *CondVar, Sema::FullExprArg Inc,
1118ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                            SourceLocation RParenLoc, Stmt *Body) {
11194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1120ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                  CondVar, Inc, RParenLoc, Body);
112143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
112343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new goto statement.
112443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
112543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
112643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1127ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1128ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                             LabelDecl *Label) {
112957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
113043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
113143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
113243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new indirect goto statement.
113343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
113443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
113543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
113660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
1137ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                     SourceLocation StarLoc,
1138ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                     Expr *Target) {
11399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
114043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
114243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new return statement.
114343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
114443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
114543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1146ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
11479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnReturnStmt(ReturnLoc, Result);
114843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
11491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
115043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new declaration statement.
115143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
115243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
115343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
115460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                   SourceLocation StartLoc,
115643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                   SourceLocation EndLoc) {
1157406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith    Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1158406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith    return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
115943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1161703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// \brief Build a new inline asm statement.
1162703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  ///
1163703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// By default, performs semantic analysis to build the new statement.
1164703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  /// Subclasses may override this routine to provide different behavior.
1165df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1166df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                               bool IsVolatile, unsigned NumOutputs,
1167df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                               unsigned NumInputs, IdentifierInfo **Names,
1168df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                               MultiExprArg Constraints, MultiExprArg Exprs,
1169df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                               Expr *AsmString, MultiExprArg Clobbers,
1170df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                               SourceLocation RParenLoc) {
1171df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier    return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1172df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                                     NumInputs, Names, Constraints, Exprs,
1173df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                                     AsmString, Clobbers, RParenLoc);
1174703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
11754dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
11768cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  /// \brief Build a new MS style inline asm statement.
11778cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  ///
11788cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  /// By default, performs semantic analysis to build the new statement.
11798cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  /// Subclasses may override this routine to provide different behavior.
1180df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1181df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                              ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
11827bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier    return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
11838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier  }
11848cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier
1185699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett  /// \brief Build a new Objective-C \@try statement.
11864dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
11874dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
11884dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
118960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
11909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *TryBody,
11918f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor                                        MultiStmtArg CatchStmts,
11929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Stmt *Finally) {
11933fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer    return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
11949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Finally);
11954dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
11964dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
1197be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// \brief Rebuild an Objective-C exception declaration.
1198be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1199be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new declaration.
1200be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1201be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1202be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                    TypeSourceInfo *TInfo, QualType T) {
1203ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara    return getSema().BuildObjCExceptionDecl(TInfo, T,
1204ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getInnerLocStart(),
1205ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getLocation(),
1206ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getIdentifier());
1207be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
12084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
1209699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett  /// \brief Build a new Objective-C \@catch statement.
1210be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  ///
1211be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1212be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
121360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
1214be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          SourceLocation RParenLoc,
1215be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                          VarDecl *Var,
12169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Stmt *Body) {
1217be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
12189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Var, Body);
1219be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
12204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
1221699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett  /// \brief Build a new Objective-C \@finally statement.
12224dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  ///
12234dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
12244dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
122560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
12269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Stmt *Body) {
12279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
12284dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
12294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
1230699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett  /// \brief Build a new Objective-C \@throw statement.
1231d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  ///
1232d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
1233d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
123460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
12359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Expr *Operand) {
12369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1237d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
12384a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
1239699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett  /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
124007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  ///
124107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  /// By default, performs semantic analysis to build the new statement.
124207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  /// Subclasses may override this routine to provide different behavior.
124307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
124407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall                                              Expr *object) {
124507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
124607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  }
124707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall
1248699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett  /// \brief Build a new Objective-C \@synchronized statement.
12498fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  ///
12508fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
12518fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
125260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
125307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall                                           Expr *Object, Stmt *Body) {
125407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
12558fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  }
1256c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor
1257699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett  /// \brief Build a new Objective-C \@autoreleasepool statement.
1258f85e193739c953358c865005855253af4f68a497John McCall  ///
1259f85e193739c953358c865005855253af4f68a497John McCall  /// By default, performs semantic analysis to build the new statement.
1260f85e193739c953358c865005855253af4f68a497John McCall  /// Subclasses may override this routine to provide different behavior.
1261f85e193739c953358c865005855253af4f68a497John McCall  StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1262f85e193739c953358c865005855253af4f68a497John McCall                                            Stmt *Body) {
1263f85e193739c953358c865005855253af4f68a497John McCall    return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1264f85e193739c953358c865005855253af4f68a497John McCall  }
1265990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall
1266c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// \brief Build a new Objective-C fast enumeration statement.
1267c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  ///
1268c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
1269c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
127060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
1271f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Element,
1272f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Expr *Collection,
1273f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          SourceLocation RParenLoc,
1274f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                          Stmt *Body) {
1275bc20bbb0bf90446a469848c658ca376832f43dc8Sam Panzer    StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
1276a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian                                                Element,
12779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                Collection,
1278a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian                                                RParenLoc);
1279a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian    if (ForEachStmt.isInvalid())
1280a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian      return StmtError();
1281a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian
1282a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian    return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
1283c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  }
12844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
128543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ exception declaration.
128643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
128743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new decaration.
128843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
1289ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1290a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall                                TypeSourceInfo *Declarator,
1291ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                SourceLocation StartLoc,
1292ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                SourceLocation IdLoc,
1293ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                IdentifierInfo *Id) {
1294efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1295efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor                                                       StartLoc, IdLoc, Id);
1296efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    if (Var)
1297efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor      getSema().CurContext->addDecl(Var);
1298efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor    return Var;
129943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
130043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
130143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ catch statement.
130243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
130343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
130443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
130560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1306f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 VarDecl *ExceptionDecl,
1307f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                 Stmt *Handler) {
13089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
13099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                      Handler));
131043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
131243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// \brief Build a new C++ try statement.
131343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  ///
131443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// By default, performs semantic analysis to build the new statement.
131543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
131660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1317f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               Stmt *TryBlock,
1318f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                               MultiStmtArg Handlers) {
13193fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer    return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
132043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1322ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// \brief Build a new C++0x range-based for statement.
1323ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ///
1324ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// By default, performs semantic analysis to build the new statement.
1325ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// Subclasses may override this routine to provide different behavior.
1326ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1327ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    SourceLocation ColonLoc,
1328ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Stmt *Range, Stmt *BeginEnd,
1329ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Expr *Cond, Expr *Inc,
1330ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    Stmt *LoopVar,
1331ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                    SourceLocation RParenLoc) {
1332ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1333e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer                                          Cond, Inc, LoopVar, RParenLoc, false);
1334ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
1335ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
1336ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// \brief Build a new C++0x range-based for statement.
1337ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  ///
1338ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// By default, performs semantic analysis to build the new statement.
1339ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
13404a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1341ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                          bool IsIfExists,
1342ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
1343ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                          DeclarationNameInfo NameInfo,
1344ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                          Stmt *Nested) {
1345ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1346ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                                QualifierLoc, NameInfo, Nested);
1347ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  }
1348ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
1349ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// \brief Attach body to a C++0x range-based for statement.
1350ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ///
1351ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// By default, performs semantic analysis to finish the new statement.
1352ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// Subclasses may override this routine to provide different behavior.
1353ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1354ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return getSema().FinishCXXForRangeStmt(ForRange, Body);
1355ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
13564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
135728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHTryStmt(bool IsCXXTry,
135828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               SourceLocation TryLoc,
135928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *TryBlock,
136028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                               Stmt *Handler) {
136128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
136228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
136328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
136428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
136528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                  Expr *FilterExpr,
136628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                  Stmt *Block) {
136728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
136828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
136928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
137028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
137128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                   Stmt *Block) {
137228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getSema().ActOnSEHFinallyBlock(Loc,Block);
137328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
137428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression that references a declaration.
1376b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
137960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1380f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        LookupResult &R,
1381f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                        bool RequiresADL) {
1382f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1383f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1384f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1385f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1386f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Build a new expression that references a declaration.
1387f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  ///
1388f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// By default, performs semantic analysis to build the new expression.
1389f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Subclasses may override this routine to provide different behavior.
139040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
1391f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                ValueDecl *VD,
1392f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                const DeclarationNameInfo &NameInfo,
1393f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                TemplateArgumentListInfo *TemplateArgs) {
1394a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    CXXScopeSpec SS;
139540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    SS.Adopt(QualifierLoc);
1396dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
1397dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: loses template args.
13982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
13992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
1400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression in parentheses.
14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
140660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
1407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                    SourceLocation RParen) {
14089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
1409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1411a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Build a new pseudo-destructor expression.
14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1413a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1414a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
141560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
1416f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation OperatorLoc,
1417f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            bool isArrow,
1418f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            CXXScopeSpec &SS,
1419f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            TypeSourceInfo *ScopeType,
1420f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation CCLoc,
1421f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                            SourceLocation TildeLoc,
1422a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed);
14231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary operator expression.
14251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1426b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
142860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
14292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                        UnaryOperatorKind Opc,
14309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *SubExpr) {
14319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build a new builtin offsetof expression.
14358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
14368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
14378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
143860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
14398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       TypeSourceInfo *Type,
1440f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                       Sema::OffsetOfComponent *Components,
14418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       unsigned NumComponents,
14428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                       SourceLocation RParenLoc) {
14438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
14448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          NumComponents, RParenLoc);
14458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
14474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// \brief Build a new sizeof, alignof or vec_step expression with a
1448f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// type argument.
14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1451b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1452f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1453f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceLocation OpLoc,
1454f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         UnaryExprOrTypeTrait ExprKind,
1455f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceRange R) {
1456f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
1457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1459f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// \brief Build a new sizeof, alignof or vec step expression with an
1460f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  /// expression argument.
14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1464f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1465f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         UnaryExprOrTypeTrait ExprKind,
1466f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                         SourceRange R) {
146760d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1468e72c55b9a11be9f00fa3f66f7ad6b73b2814e963Chandler Carruth      = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
1469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1470f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
14711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14723fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer    return Result;
1473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new array subscript expression.
14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
147960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildArraySubscriptExpr(Expr *LHS,
1480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LBracketLoc,
14819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *RHS,
1482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RBracketLoc) {
14839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
14849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             LBracketLoc, RHS,
1485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             RBracketLoc);
1486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new call expression.
14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
149260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
1493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   MultiExprArg Args,
1494e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   SourceLocation RParenLoc,
1495e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                   Expr *ExecConfig = 0) {
14969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
14973fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                   Args, RParenLoc, ExecConfig);
1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1500b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member access expression.
15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
150460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
1505f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               bool isArrow,
150640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                               NestedNameSpecifierLoc QualifierLoc,
1507e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                               SourceLocation TemplateKWLoc,
1508f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               const DeclarationNameInfo &MemberNameInfo,
1509f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               ValueDecl *Member,
1510f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FoundDecl,
1511d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                        const TemplateArgumentListInfo *ExplicitTemplateArgs,
1512f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               NamedDecl *FirstQualifierInScope) {
15139138b4e96429cbaae00c52c15c960f72b6645088Richard Smith    ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
15149138b4e96429cbaae00c52c15c960f72b6645088Richard Smith                                                                      isArrow);
1515d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    if (!Member->getDeclName()) {
1516f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // We have a reference to an unnamed field.  This is always the
1517f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // base of an anonymous struct/union member access, i.e. the
1518f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      // field is always of record type.
151940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
1520f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      assert(Member->getType()->isRecordType() &&
1521f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             "unnamed member not of record type?");
15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15239138b4e96429cbaae00c52c15c960f72b6645088Richard Smith      BaseResult =
15249138b4e96429cbaae00c52c15c960f72b6645088Richard Smith        getSema().PerformObjectMemberConversion(BaseResult.take(),
1525429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                                QualifierLoc.getNestedNameSpecifier(),
1526429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                                FoundDecl, Member);
1527429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      if (BaseResult.isInvalid())
1528f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
1529429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley      Base = BaseResult.take();
1530f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      MemberExpr *ME =
15329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        new (getSema().Context) MemberExpr(Base, isArrow,
15332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           Member, MemberNameInfo,
1534f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           cast<FieldDecl>(Member)->getType(),
1535f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                           VK, OK_Ordinary);
1536d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson      return getSema().Owned(ME);
1537d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson    }
15381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
153983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    CXXScopeSpec SS;
154040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    SS.Adopt(QualifierLoc);
154183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
1542429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    Base = BaseResult.take();
15439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    QualType BaseType = Base->getType();
1544aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
15456bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // FIXME: this involves duplicating earlier analysis in a lot of
15466bb8017bb9e828d118e15e59d71c66bba323c364John McCall    // cases; we should avoid this when possible.
15472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
15486bb8017bb9e828d118e15e59d71c66bba323c364John McCall    R.addDecl(FoundDecl);
1549c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall    R.resolveKind();
1550c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
15519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
1552e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              SS, TemplateKWLoc,
1553e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              FirstQualifierInScope,
1554c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                              R, ExplicitTemplateArgs);
1555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new binary operator expression.
15581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
156160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
15622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                                         BinaryOperatorKind Opc,
15639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *LHS, Expr *RHS) {
15649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new conditional operator expression.
15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
157160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildConditionalOperator(Expr *Cond,
157256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        SourceLocation QuestionLoc,
157356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        Expr *LHS,
157456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        SourceLocation ColonLoc,
157556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                        Expr *RHS) {
15769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
15779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        LHS, RHS);
1578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C-style cast expression.
15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
158460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
15859d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                         TypeSourceInfo *TInfo,
1586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc,
15879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         Expr *SubExpr) {
1588b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall    return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
15899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubExpr);
1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
15911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new compound literal expression.
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
159660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
159742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall                                              TypeSourceInfo *TInfo,
1598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation RParenLoc,
15999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Init) {
160042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
16019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Init);
1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new extended vector element access expression.
16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
160860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildExtVectorElementExpr(Expr *Base,
1609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation OpLoc,
1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               SourceLocation AccessorLoc,
1611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               IdentifierInfo &Accessor) {
1612aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
1613129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    CXXScopeSpec SS;
16142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
16159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
1616129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              OpLoc, /*IsArrow*/ false,
1617e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              SS, SourceLocation(),
1618e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              /*FirstQualifierInScope*/ 0,
16192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                              NameInfo,
1620129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              /* TemplateArgs */ 0);
1621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new initializer list expression.
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
162760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildInitList(SourceLocation LBraceLoc,
1628c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             MultiExprArg Inits,
1629c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             SourceLocation RBraceLoc,
1630c8fc90a854b4ccba21c85884676a80334159dd94John McCall                             QualType ResultTy) {
163160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
16323fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer      = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
1633e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    if (Result.isInvalid() || ResultTy->isDependentType())
16343fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer      return Result;
16354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
1636e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // Patch in the result type we were given, which may have been computed
1637e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    // when the initial InitListExpr was built.
1638e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1639e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor    ILE->setType(ResultTy);
16403fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer    return Result;
1641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new designated initializer expression.
16441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
164760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildDesignatedInitExpr(Designation &Desig,
1648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             MultiExprArg ArrayExprs,
1649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation EqualOrColonLoc,
1650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             bool GNUSyntax,
16519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *Init) {
165260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result
1653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
16549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Init);
1655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Result.isInvalid())
1656f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
16571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16583fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer    return Result;
1659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new value-initialized expression.
16621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds the implicit value initialization without performing
1664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// any semantic analysis. Subclasses may override this routine to provide
1665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
166660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildImplicitValueInitExpr(QualType T) {
1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new \c va_arg expression.
16711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
167460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
16759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Expr *SubExpr, TypeSourceInfo *TInfo,
16762cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    SourceLocation RParenLoc) {
16772cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara    return getSema().BuildVAArgExpr(BuiltinLoc,
16789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    SubExpr, TInfo,
16792cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                    RParenLoc);
1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new expression list in parentheses.
16831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
168660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
16875b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  MultiExprArg SubExprs,
16885b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  SourceLocation RParenLoc) {
16893fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer    return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
1690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new address-of-label expression.
16931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
16941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// By default, performs semantic analysis, using the name of the label
1695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// rather than attempting to map the label statement itself.
1696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
169760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1698ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner                                  SourceLocation LabelLoc, LabelDecl *Label) {
169957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
1700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new GNU statement expression.
17031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
1704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
170660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
17079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Stmt *SubStmt,
1708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   SourceLocation RParenLoc) {
17099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
1710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new __builtin_choose_expr expression.
1713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
171660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
17179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Expr *Cond, Expr *LHS, Expr *RHS,
1718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                     SourceLocation RParenLoc) {
1719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.ActOnChooseExpr(BuiltinLoc,
17209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                   Cond, LHS, RHS,
1721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   RParenLoc);
1722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1724f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// \brief Build a new generic selection expression.
1725f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ///
1726f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// By default, performs semantic analysis to build the new expression.
1727f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// Subclasses may override this routine to provide different behavior.
1728f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1729f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         SourceLocation DefaultLoc,
1730f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         SourceLocation RParenLoc,
1731f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         Expr *ControllingExpr,
1732f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         TypeSourceInfo **Types,
1733f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         Expr **Exprs,
1734f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                         unsigned NumAssocs) {
1735f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1736f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                ControllingExpr, Types, Exprs,
1737f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                NumAssocs);
1738f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
1739f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
1740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new overloaded operator call expression.
1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1743b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// The semantic analysis provides the behavior of template instantiation,
1744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// copying with transformations that turn what looks like an overloaded
17451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// operator call into a use of a builtin operator, performing
1746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// argument-dependent lookup, etc. Subclasses may override this routine to
1747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
174860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              SourceLocation OpLoc,
17509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Callee,
17519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *First,
17529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Expr *Second);
17531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new C++ "named" cast expression, such as static_cast or
1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// reinterpret_cast.
1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, this routine dispatches to one of the more-specific routines
17581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
1759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
176060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           Stmt::StmtClass Class,
1762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
17639d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
17669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    switch (Class) {
1769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXStaticCastExprClass:
17709d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
17711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
17729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
1773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXDynamicCastExprClass:
17759d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
17761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                    RAngleLoc, LParenLoc,
17779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    SubExpr, RParenLoc);
17781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXReinterpretCastExprClass:
17809d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                        RAngleLoc, LParenLoc,
17829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                        SubExpr,
1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        RParenLoc);
17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::CXXConstCastExprClass:
17869d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall      return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
17871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                   RAngleLoc, LParenLoc,
17889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr, RParenLoc);
17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    default:
1791b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie      llvm_unreachable("Invalid C++ named cast");
1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
1793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ static_cast expression.
1796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
179960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LAngleLoc,
18019d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                            TypeSourceInfo *TInfo,
1802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RAngleLoc,
1803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation LParenLoc,
18049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Expr *SubExpr,
1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            SourceLocation RParenLoc) {
1806c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
18079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1808c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1809c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ dynamic_cast 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 RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LAngleLoc,
18189d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                             TypeSourceInfo *TInfo,
1819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RAngleLoc,
1820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation LParenLoc,
18219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Expr *SubExpr,
1822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             SourceLocation RParenLoc) {
1823c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
18249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1825c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1826c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ reinterpret_cast expression.
1830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
183360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LAngleLoc,
18359d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                                 TypeSourceInfo *TInfo,
1836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RAngleLoc,
1837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation LParenLoc,
18389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SubExpr,
1839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 SourceLocation RParenLoc) {
1840c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
18419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1842c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1843c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ const_cast expression.
1847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
185060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LAngleLoc,
18529d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                                           TypeSourceInfo *TInfo,
1853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RAngleLoc,
1854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation LParenLoc,
18559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Expr *SubExpr,
1856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           SourceLocation RParenLoc) {
1857c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
18589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       TInfo, SubExpr,
1859c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LAngleLoc, RAngleLoc),
1860c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall                                       SourceRange(LParenLoc, RParenLoc));
1861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ functional-style cast expression.
1864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1867ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1868ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation LParenLoc,
1869ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          Expr *Sub,
1870ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          SourceLocation RParenLoc) {
1871ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
1872f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall                                               MultiExprArg(&Sub, 1),
1873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(type) expression.
1877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1879b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
188060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
188157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
188257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        TypeSourceInfo *Operand,
1883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
18844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
188557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
18871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
188801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ typeid(expr) expression.
1890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
189360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
189457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                        SourceLocation TypeidLoc,
18959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand,
1896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        SourceLocation RParenLoc) {
18979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
189857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                    RParenLoc);
18991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
19001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
190101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(type) expression.
190201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
190301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
190401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
190501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
190601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
190701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        TypeSourceInfo *Operand,
190801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
19094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
191001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
191101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
191201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
191301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Build a new C++ __uuidof(expr) expression.
191401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ///
191501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// By default, performs semantic analysis to build the new expression.
191601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// Subclasses may override this routine to provide different behavior.
191701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
191801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation TypeidLoc,
191901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        Expr *Operand,
192001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                        SourceLocation RParenLoc) {
192101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
192201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                    RParenLoc);
192301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
192401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
1925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "this" expression.
1926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new "this" expression without performing any
19281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// semantic analysis. Subclasses may override this routine to provide
1929b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// different behavior.
193060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
1931ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                QualType ThisType,
1932ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                bool isImplicit) {
1933b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    getSema().CheckCXXThisCapture(ThisLoc);
1934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().Owned(
1935828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                      new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1936828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor                                                          isImplicit));
1937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ throw expression.
1940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1943bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1944bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor                                 bool IsThrownVariableInScope) {
1945bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor    return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
1946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ default-argument expression.
1949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, builds a new default-argument expression, which does not
1951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// require any semantic analysis. Subclasses may override this routine to
1952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// provide different behavior.
19534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1954036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                            ParmVarDecl *Param) {
1955036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1956036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                                     Param));
1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
1958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ zero-initialization expression.
1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
1963ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1964ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
1965ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
1966ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
19675354e77e60e82828c7c2361f5c688c2667ab59ccBenjamin Kramer                                               MultiExprArg(), RParenLoc);
1968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "new" expression.
1971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
1973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
197460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
19751bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               bool UseGlobal,
19761bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementLParen,
19771bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               MultiExprArg PlacementArgs,
19781bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceLocation PlacementRParen,
19791bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               SourceRange TypeIdParens,
19801bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               QualType AllocatedType,
19811bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               TypeSourceInfo *AllocatedTypeInfo,
19821bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                               Expr *ArraySize,
19832aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                               SourceRange DirectInitRange,
19842aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                               Expr *Initializer) {
19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getSema().BuildCXXNew(StartLoc, UseGlobal,
1986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementLParen,
19873fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                 PlacementArgs,
1988b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                 PlacementRParen,
19894bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                 TypeIdParens,
19901bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedType,
19911bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                 AllocatedTypeInfo,
19929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                 ArraySize,
19932aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                                 DirectInitRange,
19942aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                                 Initializer);
1995b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
19961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1997b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new C++ "delete" expression.
1998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
1999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
200160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
2002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsGlobalDelete,
2003b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        bool IsArrayForm,
20049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Expr *Operand) {
2005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
20069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    Operand);
2007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
20081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new unary type trait expression.
2010b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
201360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
20143d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation StartLoc,
20153d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   TypeSourceInfo *T,
20163d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor                                   SourceLocation RParenLoc) {
20173d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor    return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
2018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
20206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// \brief Build a new binary type trait expression.
20216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ///
20226ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// By default, performs semantic analysis to build the new expression.
20236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Subclasses may override this routine to provide different behavior.
20246ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
20256ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation StartLoc,
20266ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *LhsT,
20276ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    TypeSourceInfo *RhsT,
20286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                    SourceLocation RParenLoc) {
20296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
20306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
20316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Build a new type trait expression.
20334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  ///
20344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
20354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
20364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  ExprResult RebuildTypeTrait(TypeTrait Trait,
20374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                              SourceLocation StartLoc,
20384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                              ArrayRef<TypeSourceInfo *> Args,
20394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                              SourceLocation RParenLoc) {
20404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
20414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
204321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// \brief Build a new array type trait expression.
204421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ///
204521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// By default, performs semantic analysis to build the new expression.
204621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// Subclasses may override this routine to provide different behavior.
204721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
204821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   SourceLocation StartLoc,
204921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   TypeSourceInfo *TSInfo,
205021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   Expr *DimExpr,
205121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                   SourceLocation RParenLoc) {
205221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
205321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
205421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
2055552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// \brief Build a new expression trait expression.
2056552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ///
2057552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// By default, performs semantic analysis to build the new expression.
2058552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// Subclasses may override this routine to provide different behavior.
2059552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2060552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   SourceLocation StartLoc,
2061552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   Expr *Queried,
2062552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                                   SourceLocation RParenLoc) {
2063552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2064552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
2065552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
20661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build a new (previously unresolved) declaration reference
2067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// expression.
2068b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
207100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  ExprResult RebuildDependentScopeDeclRefExpr(
207200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
2073e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                          SourceLocation TemplateKWLoc,
20742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                       const DeclarationNameInfo &NameInfo,
2075f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
2076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
207700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    SS.Adopt(QualifierLoc);
2078f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
20799d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara    if (TemplateArgs || TemplateKWLoc.isValid())
2080e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
20819d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara                                                    NameInfo, TemplateArgs);
2082f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
20839d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara    return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
2084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2085b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2086b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new template-id expression.
2087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2089b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
209060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
2091e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                   SourceLocation TemplateKWLoc,
2092e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                   LookupResult &R,
2093e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                   bool RequiresADL,
20949d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara                              const TemplateArgumentListInfo *TemplateArgs) {
2095e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2096e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                         TemplateArgs);
2097b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
210360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXConstructExpr(QualType T,
21047cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                     SourceLocation Loc,
21057cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                     CXXConstructorDecl *Constructor,
21067cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                     bool IsElidable,
21077cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                     MultiExprArg Args,
21087cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                     bool HadMultipleCandidates,
21097cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                     bool RequiresZeroInit,
2110428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                             CXXConstructExpr::ConstructionKind ConstructKind,
21117cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                     SourceRange ParenRange) {
21124e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer    SmallVector<Expr*, 8> ConvertedArgs;
21133fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer    if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
21144411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                          ConvertedArgs))
2115f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
21164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
21174411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor    return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
21183fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                           ConvertedArgs,
21197cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                           HadMultipleCandidates,
2120428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           RequiresZeroInit, ConstructKind,
2121428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                           ParenRange);
2122b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2123b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
2128ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2129ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation LParenLoc,
2130ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           MultiExprArg Args,
2131ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                           SourceLocation RParenLoc) {
2132ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
2133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
21343fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                               Args,
2135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
2136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new object-construction expression.
2139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
2142ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2143ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation LParenLoc,
2144ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               MultiExprArg Args,
2145ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                               SourceLocation RParenLoc) {
2146ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return getSema().BuildCXXTypeConstructExpr(TSInfo,
2147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               LParenLoc,
21483fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                               Args,
2149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               RParenLoc);
2150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
21511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new member reference expression.
2153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
215660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
21577c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                QualType BaseType,
21587c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                bool IsArrow,
21597c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                SourceLocation OperatorLoc,
21607c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                          NestedNameSpecifierLoc QualifierLoc,
2161e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                SourceLocation TemplateKWLoc,
2162129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                            NamedDecl *FirstQualifierInScope,
21632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                   const DeclarationNameInfo &MemberNameInfo,
2164129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                              const TemplateArgumentListInfo *TemplateArgs) {
2165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    CXXScopeSpec SS;
21667c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    SS.Adopt(QualifierLoc);
21671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2169aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
2170e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                            SS, TemplateKWLoc,
2171e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                            FirstQualifierInScope,
21722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            MemberNameInfo,
21732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            TemplateArgs);
2174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
2175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2176129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Build a new member reference expression.
21773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  ///
21783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
21793b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
21809138b4e96429cbaae00c52c15c960f72b6645088Richard Smith  ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
21819138b4e96429cbaae00c52c15c960f72b6645088Richard Smith                                         SourceLocation OperatorLoc,
21829138b4e96429cbaae00c52c15c960f72b6645088Richard Smith                                         bool IsArrow,
21839138b4e96429cbaae00c52c15c960f72b6645088Richard Smith                                         NestedNameSpecifierLoc QualifierLoc,
2184e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                         SourceLocation TemplateKWLoc,
21859138b4e96429cbaae00c52c15c960f72b6645088Richard Smith                                         NamedDecl *FirstQualifierInScope,
21869138b4e96429cbaae00c52c15c960f72b6645088Richard Smith                                         LookupResult &R,
2187129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                const TemplateArgumentListInfo *TemplateArgs) {
21883b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    CXXScopeSpec SS;
21894c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    SS.Adopt(QualifierLoc);
21901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
2192aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                            OperatorLoc, IsArrow,
2193e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                            SS, TemplateKWLoc,
2194e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                            FirstQualifierInScope,
2195c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                            R, TemplateArgs);
21963b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21982e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// \brief Build a new noexcept expression.
21992e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ///
22002e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// By default, performs semantic analysis to build the new expression.
22012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  /// Subclasses may override this routine to provide different behavior.
22022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
22032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
22042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
22052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2206ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Build a new expression to compute the length of a parameter pack.
22074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
22084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                   SourceLocation PackLoc,
2209ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                                   SourceLocation RParenLoc,
2210089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor                                   llvm::Optional<unsigned> Length) {
2211089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor    if (Length)
22124a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
22134a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                                  OperatorLoc, Pack, PackLoc,
2214089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor                                                  RParenLoc, *Length);
22154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
22164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
22174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                                OperatorLoc, Pack, PackLoc,
2218089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor                                                RParenLoc);
2219ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2220ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2221eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  /// \brief Build a new Objective-C boxed expression.
2222eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  ///
2223eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  /// By default, performs semantic analysis to build the new expression.
2224eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  /// Subclasses may override this routine to provide different behavior.
2225eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2226eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard    return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2227eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  }
22284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2229ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  /// \brief Build a new Objective-C array literal.
2230ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ///
2231ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  /// By default, performs semantic analysis to build the new expression.
2232ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  /// Subclasses may override this routine to provide different behavior.
2233ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2234ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                     Expr **Elements, unsigned NumElements) {
22354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return getSema().BuildObjCArrayLiteral(Range,
2236ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                           MultiExprArg(Elements, NumElements));
2237ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
22384a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
22394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2240ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                         Expr *Base, Expr *Key,
2241ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                         ObjCMethodDecl *getterMethod,
2242ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                         ObjCMethodDecl *setterMethod) {
2243ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return  getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2244ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                   getterMethod, setterMethod);
2245ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
2246ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
2247ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  /// \brief Build a new Objective-C dictionary literal.
2248ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ///
2249ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  /// By default, performs semantic analysis to build the new expression.
2250ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  /// Subclasses may override this routine to provide different behavior.
2251ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2252ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                          ObjCDictionaryElement *Elements,
2253ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                          unsigned NumElements) {
2254ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2255ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
22564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2257699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett  /// \brief Build a new Objective-C \@encode expression.
2258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
226160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
226281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                         TypeSourceInfo *EncodeTypeInfo,
2263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                         SourceLocation RParenLoc) {
226481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
2265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                           RParenLoc));
22661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
2267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
226892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C class message.
226960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
227092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2271207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis                                          ArrayRef<SourceLocation> SelectorLocs,
227292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
22734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                          SourceLocation LBracLoc,
227492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
227592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
227692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return SemaRef.BuildClassMessage(ReceiverTypeInfo,
227792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     ReceiverTypeInfo->getType(),
227892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                     /*SuperLoc=*/SourceLocation(),
2279207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis                                     Sel, Method, LBracLoc, SelectorLocs,
22803fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                     RBracLoc, Args);
228192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
228292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
228392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  /// \brief Build a new Objective-C instance message.
228460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCMessageExpr(Expr *Receiver,
228592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          Selector Sel,
2286207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis                                          ArrayRef<SourceLocation> SelectorLocs,
228792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          ObjCMethodDecl *Method,
22884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                          SourceLocation LBracLoc,
228992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          MultiExprArg Args,
229092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                          SourceLocation RBracLoc) {
22919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildInstanceMessage(Receiver,
22929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Receiver->getType(),
229392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                        /*SuperLoc=*/SourceLocation(),
2294207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis                                        Sel, Method, LBracLoc, SelectorLocs,
22953fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                        RBracLoc, Args);
229692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
229792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
2298f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C ivar reference expression.
2299f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2300f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2301f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
230260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
2303f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          SourceLocation IvarLoc,
2304f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                          bool IsArrow, bool IsFreeIvar) {
2305f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    // FIXME: We lose track of the IsFreeIvar bit.
2306f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
2307429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2308f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2309f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
231060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2311f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IvarLoc,
2312d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0,
2313ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall                                                         false);
2314429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2315f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
23164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2317f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
23183fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer      return Result;
23194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2320429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2321e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              /*FIXME:*/IvarLoc, IsArrow,
2322e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              SS, SourceLocation(),
2323f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
23244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                              R,
2325f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2326f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
2327e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor
2328e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// \brief Build a new Objective-C property reference expression.
2329e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  ///
2330e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2331e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
23324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
23333c3b7f90a863af43fa63043d396553ecf205351cJohn McCall                                        ObjCPropertyDecl *Property,
23343c3b7f90a863af43fa63043d396553ecf205351cJohn McCall                                        SourceLocation PropertyLoc) {
2335e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    CXXScopeSpec SS;
2336429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2337e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2338e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                   Sema::LookupMemberName);
2339e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    bool IsArrow = false;
234060d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2341e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                                         /*FIME:*/PropertyLoc,
2342d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2343429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2344f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
23454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2346e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor    if (Result.get())
23473fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer      return Result;
23484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2349429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
23504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                              /*FIXME:*/PropertyLoc, IsArrow,
2351e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              SS, SourceLocation(),
2352e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*FirstQualifierInScope=*/0,
23534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                              R,
2354e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor                                              /*TemplateArgs=*/0);
2355e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  }
23564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
235712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// \brief Build a new Objective-C property reference expression.
23589cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  ///
23599cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
236012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  /// Subclasses may override this routine to provide different behavior.
236112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
236212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Getter,
236312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        ObjCMethodDecl *Setter,
236412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                        SourceLocation PropertyLoc) {
236512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // Since these expressions can only be value-dependent, we do not
236612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    // need to perform semantic analysis again.
236712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return Owned(
236812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall      new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
236912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  VK_LValue, OK_ObjCProperty,
237012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                  PropertyLoc, Base));
23719cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor  }
23729cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor
2373f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// \brief Build a new Objective-C "isa" expression.
2374f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  ///
2375f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// By default, performs semantic analysis to build the new expression.
2376f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  /// Subclasses may override this routine to provide different behavior.
237760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
2378f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                      bool IsArrow) {
2379f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    CXXScopeSpec SS;
2380429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult Base = getSema().Owned(BaseArg);
2381f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2382f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                   Sema::LookupMemberName);
238360d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
2384f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                                         /*FIME:*/IsaLoc,
2385d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall                                                         SS, 0, false);
2386429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    if (Result.isInvalid() || Base.isInvalid())
2387f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
23884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2389f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor    if (Result.get())
23903fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer      return Result;
23914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2392429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
2393e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              /*FIXME:*/IsaLoc, IsArrow,
2394e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                              SS, SourceLocation(),
2395f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*FirstQualifierInScope=*/0,
23964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                              R,
2397f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                              /*TemplateArgs=*/0);
2398f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  }
23994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// \brief Build a new shuffle vector expression.
2401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  ///
2402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// By default, performs semantic analysis to build the new expression.
2403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  /// Subclasses may override this routine to provide different behavior.
240460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
2405f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      MultiExprArg SubExprs,
2406f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                      SourceLocation RParenLoc) {
2407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Find the declaration for __builtin_shufflevector
24081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const IdentifierInfo &Name
2409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = SemaRef.Context.Idents.get("__builtin_shufflevector");
2410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
24131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Build a reference to the __builtin_shufflevector builtin
2415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
2416a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman    Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2417a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman                                                  SemaRef.Context.BuiltinFnTy,
2418a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman                                                  VK_RValue, BuiltinLoc);
2419a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman    QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2420a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman    Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2421a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman                                       CK_BuiltinFnToFnPtr).take();
24221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // Build the CallExpr
2424429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    ExprResult TheCall = SemaRef.Owned(
2425a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman      new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
24263b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                                     Builtin->getCallResultType(),
2427f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            Expr::getValueKindForType(Builtin->getResultType()),
2428429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley                                     RParenLoc));
24291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    // Type-check the __builtin_shufflevector expression.
2431429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley    return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
2432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
243343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
24348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// \brief Build a new template argument pack expansion.
24358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  ///
24368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
24374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// for a template argument. Subclasses may override this routine to provide
24388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  /// different behavior.
24398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2440cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           SourceLocation EllipsisLoc,
2441cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                       llvm::Optional<unsigned> NumExpansions) {
24428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    switch (Pattern.getArgument().getKind()) {
24437a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    case TemplateArgument::Expression: {
24447a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      ExprResult Result
244567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
244667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                       EllipsisLoc, NumExpansions);
24477a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      if (Result.isInvalid())
24487a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor        return TemplateArgumentLoc();
24494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
24507a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor      return TemplateArgumentLoc(Result.get(), Result.get());
24517a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor    }
24524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
24538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Template:
2454a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor      return TemplateArgumentLoc(TemplateArgument(
2455a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                          Pattern.getArgument().getAsTemplate(),
24562be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor                                                  NumExpansions),
2457b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                 Pattern.getTemplateQualifierLoc(),
2458a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 Pattern.getTemplateNameLoc(),
2459a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor                                 EllipsisLoc);
24604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
24618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Null:
24628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Integral:
24638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Declaration:
24648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Pack:
2465a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    case TemplateArgument::TemplateExpansion:
24668491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      llvm_unreachable("Pack expansion pattern has no parameter packs");
24674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
24688491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    case TemplateArgument::Type:
24694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      if (TypeSourceInfo *Expansion
24708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor            = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2471cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           EllipsisLoc,
2472cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           NumExpansions))
24738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
24748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                   Expansion);
24758491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      break;
24768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
24774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
24788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    return TemplateArgumentLoc();
24798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor  }
24804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2481dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// \brief Build a new expression pack expansion.
2482dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  ///
2483dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// By default, performs semantic analysis to build a new pack expansion
24844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// for an expression. Subclasses may override this routine to provide
2485dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  /// different behavior.
248667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
248767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                  llvm::Optional<unsigned> NumExpansions) {
248867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
2489dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor  }
2490dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman
2491dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  /// \brief Build a new atomic operation expression.
2492dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  ///
2493dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  /// By default, performs semantic analysis to build the new expression.
2494dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  /// Subclasses may override this routine to provide different behavior.
2495dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2496dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman                               MultiExprArg SubExprs,
2497dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman                               QualType RetTy,
2498dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman                               AtomicExpr::AtomicOp Op,
2499dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman                               SourceLocation RParenLoc) {
2500dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    // Just create the expression; there is not any interesting semantic
2501dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    // analysis here because we can't actually build an AtomicExpr until
2502dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    // we are sure it is semantically sound.
25033b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
2504dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman                                            RParenLoc);
2505dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  }
2506dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman
250743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate:
2508c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2509c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     QualType ObjectType,
2510c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     NamedDecl *FirstQualifierInScope,
2511c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                     CXXScopeSpec &SS);
2512b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor
2513b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2514b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             QualType ObjectType,
2515b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             NamedDecl *FirstQualifierInScope,
2516b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                             CXXScopeSpec &SS);
2517577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor};
2518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
251943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
252060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
252143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!S)
252243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    return SemaRef.Owned(S);
25231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
252443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  switch (S->getStmtClass()) {
252543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::NoStmtClass: break;
25261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
252743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform individual statement nodes
252843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)                                              \
252943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
253063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node)
253143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent)
25324bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
25331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
253443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform expressions by calling TransformExpr.
253543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent)
25367381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
253743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class:
25384bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
253943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    {
254060d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
254143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      if (E.isInvalid())
2542f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
25431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
254543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    }
25461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
25471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25483fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
254943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
25501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2552670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived>
255360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
2554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!E)
2555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    return SemaRef.Owned(E);
2556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
2557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  switch (E->getStmtClass()) {
2558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    case Stmt::NoStmtClass: break;
2559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break;
25607381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt)
2561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent)                                              \
2562454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall    case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
25634bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc"
25641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
25651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
2567657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor}
2568657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor
2569657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived>
25704a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosierbool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
25714a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                            unsigned NumInputs,
2572aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool IsCall,
2573686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                      SmallVectorImpl<Expr *> &Outputs,
2574aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                            bool *ArgChanged) {
2575aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  for (unsigned I = 0; I != NumInputs; ++I) {
2576aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    // If requested, drop call arguments that need to be dropped.
2577aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2578aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      if (ArgChanged)
2579aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor        *ArgChanged = true;
25804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2581aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      break;
2582aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    }
25834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2584dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2585dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      Expr *Pattern = Expansion->getPattern();
25864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2587686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2588dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2589dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
25904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2591dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
2592dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // be expanded.
2593dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      bool Expand = true;
2594d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
259567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> OrigNumExpansions
259667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor        = Expansion->getNumExpansions();
259767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
2598dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2599dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor                                               Pattern->getSourceRange(),
2600a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie                                               Unexpanded,
2601d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               Expand, RetainExpansion,
2602d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
2603dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        return true;
26044a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2605dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      if (!Expand) {
2606dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // The transform has determined that we should perform a simple
26074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        // transformation on the pack expansion, producing another pack
2608dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        // expansion.
2609dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2610dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2611dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (OutPattern.isInvalid())
2612dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
26134a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
26144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
261567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                Expansion->getEllipsisLoc(),
261667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                                           NumExpansions);
2617dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2618dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
26194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2620dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (ArgChanged)
2621dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          *ArgChanged = true;
2622dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2623dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        continue;
2624dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
2625c8fc90a854b4ccba21c85884676a80334159dd94John McCall
2626c8fc90a854b4ccba21c85884676a80334159dd94John McCall      // Record right away that the argument was changed.  This needs
2627c8fc90a854b4ccba21c85884676a80334159dd94John McCall      // to happen even if the array expands to nothing.
2628c8fc90a854b4ccba21c85884676a80334159dd94John McCall      if (ArgChanged) *ArgChanged = true;
26294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2630dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // The transform has determined that we should perform an elementwise
2631dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      // expansion of the pattern. Do so.
2632cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
2633dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2634dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        ExprResult Out = getDerived().TransformExpr(Pattern);
2635dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        if (Out.isInvalid())
2636dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor          return true;
2637dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor
263877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.get()->containsUnexpandedParameterPack()) {
263967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor          Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
264067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                     OrigNumExpansions);
264177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.isInvalid())
264277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
264377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
26444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2645dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor        Outputs.push_back(Out.get());
2646dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      }
26474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2648dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor      continue;
2649dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor    }
26504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2651aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2652aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.isInvalid())
2653aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return true;
26544a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2655aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    if (Result.get() != Inputs[I] && ArgChanged)
2656aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      *ArgChanged = true;
26574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
26584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Outputs.push_back(Result.get());
2659aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
26604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2661aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  return false;
2662aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor}
2663aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2664aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived>
2665c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc
2666c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2667c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                    NestedNameSpecifierLoc NNS,
2668c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                     QualType ObjectType,
2669c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                             NamedDecl *FirstQualifierInScope) {
2670686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
26714a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2672c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor       Qualifier = Qualifier.getPrefix())
2673c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Qualifiers.push_back(Qualifier);
2674c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2675c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  CXXScopeSpec SS;
2676c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  while (!Qualifiers.empty()) {
2677c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2678c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
26794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2680c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    switch (QNNS->getKind()) {
2681c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Identifier:
26824a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2683c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              *QNNS->getAsIdentifier(),
26844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                              Q.getLocalBeginLoc(),
2685c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              Q.getLocalEndLoc(),
26864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                              ObjectType, false, SS,
2687c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              FirstQualifierInScope, false))
2688c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        return NestedNameSpecifierLoc();
26894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2690c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
26914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2692c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Namespace: {
2693c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      NamespaceDecl *NS
2694c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        = cast_or_null<NamespaceDecl>(
2695c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                    getDerived().TransformDecl(
2696c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                          Q.getLocalBeginLoc(),
2697c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                       QNNS->getAsNamespace()));
2698c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2699c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2700c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
27014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2702c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::NamespaceAlias: {
2703c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      NamespaceAliasDecl *Alias
2704c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        = cast_or_null<NamespaceAliasDecl>(
2705c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                      getDerived().TransformDecl(Q.getLocalBeginLoc(),
2706c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                 QNNS->getAsNamespaceAlias()));
27074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2708c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                Q.getLocalEndLoc());
2709c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
2710c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
27114a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2712c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::Global:
2713c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      // There is no meaningful transformation that one could perform on the
2714c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      // global scope.
2715c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2716c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      break;
27174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2718c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::TypeSpecWithTemplate:
2719c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    case NestedNameSpecifier::TypeSpec: {
2720c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2721c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                              FirstQualifierInScope, SS);
27224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2723c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (!TL)
2724c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        return NestedNameSpecifierLoc();
27254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2726c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
27274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier          (SemaRef.getLangOpts().CPlusPlus0x &&
2728c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor           TL.getType()->isEnumeralType())) {
27294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        assert(!TL.getType().hasLocalQualifiers() &&
2730c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor               "Can't get cv-qualifiers here");
273195aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith        if (TL.getType()->isEnumeralType())
273295aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith          SemaRef.Diag(TL.getBeginLoc(),
273395aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith                       diag::warn_cxx98_compat_enum_nested_name_spec);
2734c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2735c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                  Q.getLocalEndLoc());
2736c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor        break;
2737c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      }
273800c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      // If the nested-name-specifier is an invalid type def, don't emit an
273900c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      // error because a previous error should have already been emitted.
274000c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
274100c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
27424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
274300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu          << TL.getType() << SS.getRange();
274400c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu      }
2745c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      return NestedNameSpecifierLoc();
2746c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    }
27477c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    }
27484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
27497c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    // The qualifier-in-scope and object type only apply to the leftmost entity.
2750c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    FirstQualifierInScope = 0;
27517c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    ObjectType = QualType();
2752c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  }
27534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2754c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // Don't rebuild the nested-name-specifier if we don't have to.
27554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2756c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      !getDerived().AlwaysRebuild())
2757c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    return NNS;
27584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
27594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  // If we can re-use the source-location data from the original
2760c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // nested-name-specifier, do so.
2761c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (SS.location_size() == NNS.getDataLength() &&
2762c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2763c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2764c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2765c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // Allocate new nested-name-specifier location information.
2766c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  return SS.getWithLocInContext(SemaRef.Context);
2767c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor}
2768c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
2769c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived>
27702577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo
27712577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived>
277243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
27732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name = NameInfo.getName();
277481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  if (!Name)
27752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo();
277681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
277781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  switch (Name.getNameKind()) {
277881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::Identifier:
277981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCZeroArgSelector:
278081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCOneArgSelector:
278181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::ObjCMultiArgSelector:
278281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXOperatorName:
27833e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  case DeclarationName::CXXLiteralOperatorName:
278481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXUsingDirective:
27852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NameInfo;
27861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
278781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConstructorName:
278881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXDestructorName:
278981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  case DeclarationName::CXXConversionFunctionName: {
27902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *NewTInfo;
27912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CanQualType NewCanTy;
27922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
279343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewTInfo = getDerived().TransformType(OldTInfo);
279443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      if (!NewTInfo)
279543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall        return DeclarationNameInfo();
279643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
27972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
27982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    else {
27992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewTInfo = 0;
28002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
280143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      QualType NewT = getDerived().TransformType(Name.getCXXNameType());
28022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      if (NewT.isNull())
28032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        return DeclarationNameInfo();
28042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NewCanTy = SemaRef.Context.getCanonicalType(NewT);
28052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
28061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationName NewName
28082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
28092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                           NewCanTy);
28102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DeclarationNameInfo NewNameInfo(NameInfo);
28112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setName(NewName);
28122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NewNameInfo.setNamedTypeInfo(NewTInfo);
28132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return NewNameInfo;
281481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor  }
28151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
28161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2817b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  llvm_unreachable("Unknown name kind.");
281881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor}
281981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor
282081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived>
28211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
2822fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2823fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              TemplateName Name,
2824fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              SourceLocation NameLoc,
2825fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              QualType ObjectType,
2826fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              NamedDecl *FirstQualifierInScope) {
2827fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2828fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *Template = QTN->getTemplateDecl();
2829fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    assert(Template && "qualified template name must refer to a template");
28304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2831fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *TransTemplate
28324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2833fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                                              Template));
2834fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransTemplate)
2835fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
28364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2837fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2838fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        SS.getScopeRep() == QTN->getQualifier() &&
2839fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransTemplate == Template)
2840fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
28414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2842fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2843fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            TransTemplate);
2844fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
28454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2846fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2847fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (SS.getScopeRep()) {
2848fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      // These apply to the scope specifier, not the template.
2849fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      ObjectType = QualType();
2850fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      FirstQualifierInScope = 0;
28514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    }
28524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2853fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2854fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        SS.getScopeRep() == DTN->getQualifier() &&
2855fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        ObjectType.isNull())
2856fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
28574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2858fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (DTN->isIdentifier()) {
2859fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return getDerived().RebuildTemplateName(SS,
28604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                              *DTN->getIdentifier(),
2861fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              NameLoc,
2862fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              ObjectType,
2863fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                              FirstQualifierInScope);
2864fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    }
28654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2866fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2867fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            ObjectType);
2868fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
28694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2870fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2871fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateDecl *TransTemplate
28724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2873fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                                              Template));
2874fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransTemplate)
2875fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
28764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2877fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2878fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransTemplate == Template)
2879fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
28804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2881fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    return TemplateName(TransTemplate);
2882fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
28834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2884fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  if (SubstTemplateTemplateParmPackStorage *SubstPack
2885fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      = Name.getAsSubstTemplateTemplateParmPack()) {
2886fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    TemplateTemplateParmDecl *TransParam
2887fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    = cast_or_null<TemplateTemplateParmDecl>(
2888fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor            getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2889fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!TransParam)
2890fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return TemplateName();
28914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2892fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
2893fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor        TransParam == SubstPack->getParameterPack())
2894fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor      return Name;
28954a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
28964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return getDerived().RebuildTemplateName(TransParam,
2897fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SubstPack->getArgumentPack());
2898fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  }
28994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2900fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  // These should be getting filtered out before they reach the AST.
2901fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  llvm_unreachable("overloaded function decl survived to here");
2902fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor}
2903fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor
2904fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived>
2905833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc(
2906833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgument &Arg,
2907833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2908833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  SourceLocation Loc = getDerived().getBaseLocation();
2909670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  switch (Arg.getKind()) {
2910670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Null:
29119f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("null template argument in TreeTransform");
2912833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2913833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2914833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
2915833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg,
2916a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall               SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
29174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2918833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2919833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2920788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
2921b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor  case TemplateArgument::TemplateExpansion: {
2922b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    NestedNameSpecifierLocBuilder Builder;
2923b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    TemplateName Template = Arg.getAsTemplate();
2924b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2925b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2926b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2927b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
29284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2929b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (Arg.getKind() == TemplateArgument::Template)
29304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      Output = TemplateArgumentLoc(Arg,
2931b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Builder.getWithLocInContext(SemaRef.Context),
2932b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Loc);
2933b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    else
29344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      Output = TemplateArgumentLoc(Arg,
2935b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Builder.getWithLocInContext(SemaRef.Context),
2936b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor                                   Loc, Loc);
29374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
2938a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    break;
2939b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor  }
2940a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
2941833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
2942833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2943833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2944833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2945833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
2946670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Integral:
2947833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
2948828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
2949833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    break;
2950833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
2951833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
2952833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2953833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived>
2954833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument(
2955833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         const TemplateArgumentLoc &Input,
2956833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                         TemplateArgumentLoc &Output) {
2957833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgument &Arg = Input.getArgument();
2958833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
2959833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
2960833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
2961833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = Input;
2962833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
29631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2964670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Type: {
2965a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *DI = Input.getTypeSourceInfo();
2966833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (DI == NULL)
2967a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall      DI = InventTypeSourceInfo(Input.getArgument().getAsType());
2968833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2969833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    DI = getDerived().TransformType(DI);
2970833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!DI) return true;
2971833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2972833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2973833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2974670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
29751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2976670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Declaration: {
2977833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // FIXME: we should never have to transform one of these.
2978972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    DeclarationName Name;
2979972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor    if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2980972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor      Name = ND->getDeclName();
2981788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemporaryBase Rebase(*this, Input.getLocation(), Name);
29827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
2983833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!D) return true;
2984833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2985828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Expr *SourceExpr = Input.getSourceDeclExpression();
2986828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    if (SourceExpr) {
2987828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      EnterExpressionEvaluationContext Unevaluated(getSema(),
2988f6702a3927147655206ae729a84339c4fda4c651Richard Smith                                                   Sema::ConstantEvaluated);
298960d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult E = getDerived().TransformExpr(SourceExpr);
2990ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman      E = SemaRef.ActOnConstantExpression(E);
29919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      SourceExpr = (E.isInvalid() ? 0 : E.take());
2992828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    }
2993828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
2994828bff2079b6a91ecd7ed5b842c59527d7682789John McCall    Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
2995833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
2996670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
29971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2998788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template: {
2999b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3000b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    if (QualifierLoc) {
3001b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3002b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor      if (!QualifierLoc)
3003b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor        return true;
3004b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    }
30054a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
30061d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    CXXScopeSpec SS;
30071d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    SS.Adopt(QualifierLoc);
3008788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    TemplateName Template
30091d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor      = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
30101d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor                                           Input.getTemplateNameLoc());
3011788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    if (Template.isNull())
3012788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor      return true;
30134a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3014b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor    Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
3015788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor                                 Input.getTemplateNameLoc());
3016788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return false;
3017788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  }
3018a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
3019a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor  case TemplateArgument::TemplateExpansion:
3020a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor    llvm_unreachable("Caller should expand pack expansions");
3021a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor
3022670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Expression: {
3023f6702a3927147655206ae729a84339c4fda4c651Richard Smith    // Template argument expressions are constant expressions.
30241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EnterExpressionEvaluationContext Unevaluated(getSema(),
3025f6702a3927147655206ae729a84339c4fda4c651Richard Smith                                                 Sema::ConstantEvaluated);
30261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3027833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    Expr *InputExpr = Input.getSourceExpression();
3028833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3029833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3030223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner    ExprResult E = getDerived().TransformExpr(InputExpr);
3031ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman    E = SemaRef.ActOnConstantExpression(E);
3032833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (E.isInvalid()) return true;
30339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
3034833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
3035670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
30361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3037670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  case TemplateArgument::Pack: {
3038686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<TemplateArgument, 4> TransformedArgs;
3039670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    TransformedArgs.reserve(Arg.pack_size());
30401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
3041670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor                                      AEnd = Arg.pack_end();
3042670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor         A != AEnd; ++A) {
30431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3044833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // FIXME: preserve source information here when we start
3045833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      // caring about parameter packs.
3046833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3047828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc InputArg;
3048828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TemplateArgumentLoc OutputArg;
3049828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      getDerived().InventTemplateArgumentLoc(*A, InputArg);
3050828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
3051833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall        return true;
3052833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3053828bff2079b6a91ecd7ed5b842c59527d7682789John McCall      TransformedArgs.push_back(OutputArg.getArgument());
3054670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor    }
3055910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor
3056910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    TemplateArgument *TransformedArgsPtr
3057910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor      = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3058910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor    std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3059910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor              TransformedArgsPtr);
30604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
30614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                                  TransformedArgs.size()),
3062910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor                                 Input.getLocInfo());
3063833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
3064670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
3065670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  }
30661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3067670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // Work around bogus GCC warning
3068833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return true;
3069670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor}
3070670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
30717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information
30727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator.
30737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator>
30747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator {
30757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TreeTransform<Derived> &Self;
30767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  InputIterator Iter;
30774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
30787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic:
30797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc value_type;
30807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLoc reference;
30817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef typename std::iterator_traits<InputIterator>::difference_type
30827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    difference_type;
30837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef std::input_iterator_tag iterator_category;
30844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
30857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class pointer {
30867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Arg;
30874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
30887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
30897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
30904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
30917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    const TemplateArgumentLoc *operator->() const { return &Arg; }
30927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
30934a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
30947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator() { }
30954a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
30967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
30977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                             InputIterator Iter)
30987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    : Self(Self), Iter(Iter) { }
30994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator &operator++() {
31017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++Iter;
31027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return *this;
3103fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  }
31044a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  TemplateArgumentLocInventIterator operator++(int) {
31067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocInventIterator Old(*this);
31077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ++(*this);
31087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Old;
31097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
31104a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  reference operator*() const {
31127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc Result;
31137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    Self.InventTemplateArgumentLoc(*Iter, Result);
31147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return Result;
31157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
31164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  pointer operator->() const { return pointer(**this); }
31184a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator==(const TemplateArgumentLocInventIterator &X,
31207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
31217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter == Y.Iter;
31227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
3123fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor
31247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  friend bool operator!=(const TemplateArgumentLocInventIterator &X,
31257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                         const TemplateArgumentLocInventIterator &Y) {
31267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    return X.Iter != Y.Iter;
31277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  }
31287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor};
31294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31307f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived>
31317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator>
31327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
31337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                        InputIterator Last,
31347f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor                                            TemplateArgumentListInfo &Outputs) {
31357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  for (; First != Last; ++First) {
31367f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    TemplateArgumentLoc Out;
31377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc In = *First;
31384a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().getKind() == TemplateArgument::Pack) {
31408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Unpack argument packs, which we translate them into separate
31418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // arguments.
31427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // FIXME: We could do much better if we could guarantee that the
31437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // TemplateArgumentLocInfo for the pack expansion would be usable for
31447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      // all of the template arguments in the argument pack.
31454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      typedef TemplateArgumentLocInventIterator<Derived,
31467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                TemplateArgument::pack_iterator>
31477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        PackLocIterator;
31484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      if (TransformTemplateArguments(PackLocIterator(*this,
31497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                 In.getArgument().pack_begin()),
31507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     PackLocIterator(*this,
31517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                                   In.getArgument().pack_end()),
31527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                     Outputs))
31537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return true;
31544a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
31568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
31574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (In.getArgument().isPackExpansion()) {
31598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // We have a pack expansion, for which we will be substituting into
31608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // the pattern.
31618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      SourceLocation Ellipsis;
3162cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> OrigNumExpansions;
31638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      TemplateArgumentLoc Pattern
31644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3165cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                     getSema().Context);
31664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3167686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      SmallVector<UnexpandedParameterPack, 2> Unexpanded;
31688491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
31698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
31704a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // Determine whether the set of unexpanded parameter packs can and should
31728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // be expanded.
31738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      bool Expand = true;
3174d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
3175cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
31768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (getDerived().TryExpandParameterPacks(Ellipsis,
31778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                               Pattern.getSourceRange(),
3178a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie                                               Unexpanded,
31794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                               Expand,
3180d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
3181d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions))
31828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        return true;
31834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      if (!Expand) {
31858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // The transform has determined that we should perform a simple
31864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        // transformation on the pack expansion, producing another pack
31878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        // expansion.
31888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        TemplateArgumentLoc OutPattern;
31898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
31908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
31918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
31924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3193cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3194cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                NumExpansions);
31958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (Out.getArgument().isNull())
31968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
31974a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
31988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
31998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        continue;
32008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
32014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // The transform has determined that we should perform an elementwise
32038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      // expansion of the pattern. Do so.
3204cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      for (unsigned I = 0; I != *NumExpansions; ++I) {
32058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
32068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
32078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
32088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor          return true;
32094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
321077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        if (Out.getArgument().containsUnexpandedParameterPack()) {
3211cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3212cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                  OrigNumExpansions);
321377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor          if (Out.getArgument().isNull())
321477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor            return true;
321577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor        }
32164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        Outputs.addArgument(Out);
32188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      }
32194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32203cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
32213cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
32223cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
32233cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
32244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32253cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (getDerived().TransformTemplateArgument(Pattern, Out))
32263cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
32274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3228cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3229cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                OrigNumExpansions);
32303cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (Out.getArgument().isNull())
32313cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
32324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32333cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        Outputs.addArgument(Out);
32343cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
32354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor      continue;
32378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    }
32384a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    // The simple case:
32408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor    if (getDerived().TransformTemplateArgument(In, Out))
32417f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor      return true;
32424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32437f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    Outputs.addArgument(Out);
32447f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  }
32454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
32467f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor  return false;
32477f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
32487f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor}
32497f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor
3250577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
3251577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation
3252577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
3253577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3254577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
325543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) {
3256577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (getDerived().AlreadyTransformed(T))
3257577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return T;
32581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3259a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Temporary workaround.  All of these transformations should
3260a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // eventually turn into transformations on TypeLocs.
3261c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor  TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3262c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor                                                getDerived().getBaseLocation());
32634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
326443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeSourceInfo *NewDI = getDerived().TransformType(DI);
32651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3266a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (!NewDI)
3267a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
32681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3269a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return NewDI->getType();
3270577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
32711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3272577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
327343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
3274f6702a3927147655206ae729a84339c4fda4c651Richard Smith  // Refine the base location to the type's location.
3275f6702a3927147655206ae729a84339c4fda4c651Richard Smith  TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3276f6702a3927147655206ae729a84339c4fda4c651Richard Smith                       getDerived().getBaseEntity());
3277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlreadyTransformed(DI->getType()))
3278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return DI;
32791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLocBuilder TLB;
32811bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
3282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeLoc TL = DI->getTypeLoc();
3283a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TLB.reserve(TL.getFullDataSize());
32841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
328543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, TL);
3286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return 0;
32881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3289a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3290577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
32911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
329443fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
3295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  switch (T.getTypeLocClass()) {
3296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT)
3297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \
3298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  case TypeLoc::CLASS: \
329943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
3300a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def"
3301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
33039f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin  llvm_unreachable("unhandled type loc!");
3304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
33051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3306a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types
3307a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers
3308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function
3309a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but
3310a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients.
33111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
33121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3313a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
331443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               QualifiedTypeLoc T) {
3315a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers Quals = T.getType().getLocalQualifiers();
3316a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
331743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
3318a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
3319577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
33201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3321a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Silently suppress qualifiers if the result type can't be qualified.
3322a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: this is the right thing for template instantiation, but
3323a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // probably not for other clients.
3324a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result->isFunctionType() || Result->isReferenceType())
3325a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return Result;
33261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3327f85e193739c953358c865005855253af4f68a497John McCall  // Suppress Objective-C lifetime qualifiers if they don't make sense for the
3328e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  // resulting type.
3329e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  if (Quals.hasObjCLifetime()) {
3330e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3331e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      Quals.removeObjCLifetime();
33324020caec546d221170072d2388b57d151cb26111Douglas Gregor    else if (Result.getObjCLifetime()) {
33334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      // Objective-C ARC:
3334e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      //   A lifetime qualifier applied to a substituted template parameter
3335e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      //   overrides the lifetime qualifier from the template argument.
33364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      if (const SubstTemplateTypeParmType *SubstTypeParam
3337e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3338e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        QualType Replacement = SubstTypeParam->getReplacementType();
3339e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Qualifiers Qs = Replacement.getQualifiers();
3340e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Qs.removeObjCLifetime();
33414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        Replacement
3342e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor          = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3343e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                             Qs);
3344e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Result = SemaRef.Context.getSubstTemplateTypeParmType(
33454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                        SubstTypeParam->getReplacedParameter(),
3346e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor                                                              Replacement);
3347e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        TLB.TypeWasModifiedSafely(Result);
3348e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      } else {
33494020caec546d221170072d2388b57d151cb26111Douglas Gregor        // Otherwise, complain about the addition of a qualifier to an
33504020caec546d221170072d2388b57d151cb26111Douglas Gregor        // already-qualified type.
33514020caec546d221170072d2388b57d151cb26111Douglas Gregor        SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
3352b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis        SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
33534020caec546d221170072d2388b57d151cb26111Douglas Gregor          << Result << R;
33544a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3355e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor        Quals.removeObjCLifetime();
3356e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor      }
3357e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor    }
3358e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor  }
33592865474261a608c7873b87ba4af110d17907896dJohn McCall  if (!Quals.empty()) {
33602865474261a608c7873b87ba4af110d17907896dJohn McCall    Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
33612865474261a608c7873b87ba4af110d17907896dJohn McCall    TLB.push<QualifiedTypeLoc>(Result);
33622865474261a608c7873b87ba4af110d17907896dJohn McCall    // No location information to preserve.
33632865474261a608c7873b87ba4af110d17907896dJohn McCall  }
3364a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3365a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3366a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3367a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
336843fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
3369b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc
3370b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
337143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   QualType ObjectType,
337243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   NamedDecl *UnqualLookup,
3373b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                   CXXScopeSpec &SS) {
3374b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  QualType T = TL.getType();
337543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (getDerived().AlreadyTransformed(T))
3376b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TL;
33774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
337843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TypeLocBuilder TLB;
337943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType Result;
33804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
338143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (isa<TemplateSpecializationType>(T)) {
3382b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateSpecializationTypeLoc SpecTL
3383b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = cast<TemplateSpecializationTypeLoc>(TL);
33844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
338543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    TemplateName Template =
3386b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      getDerived().TransformTemplateName(SS,
3387b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getTypePtr()->getTemplateName(),
3388b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         SpecTL.getTemplateNameLoc(),
338943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         ObjectType, UnqualLookup);
33904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    if (Template.isNull())
3391b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return TypeLoc();
33924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
33934a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3394b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                              Template);
339543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else if (isa<DependentTemplateSpecializationType>(T)) {
3396b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
3397b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      = cast<DependentTemplateSpecializationTypeLoc>(TL);
33984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3399b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateName Template
34004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      = getDerived().RebuildTemplateName(SS,
34014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                         *SpecTL.getTypePtr()->getIdentifier(),
340255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara                                         SpecTL.getTemplateNameLoc(),
3403b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                         ObjectType, UnqualLookup);
3404a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    if (Template.isNull())
3405b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return TypeLoc();
34064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
34074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3408b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                                       SpecTL,
3409087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                     Template,
3410087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       SS);
341143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  } else {
341243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    // Nothing special needs to be done for these.
3413b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    Result = getDerived().TransformType(TLB, TL);
341443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
34154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
34164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (Result.isNull())
3417b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TypeLoc();
34184a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3419b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
342043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
342143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
3422c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived>
3423b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo *
3424b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3425c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   QualType ObjectType,
3426c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   NamedDecl *UnqualLookup,
3427c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                   CXXScopeSpec &SS) {
3428c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  // FIXME: Painfully copy-paste from the above!
34294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3430b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  QualType T = TSInfo->getType();
3431c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (getDerived().AlreadyTransformed(T))
3432b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return TSInfo;
34334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3434c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  TypeLocBuilder TLB;
3435c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  QualType Result;
34364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3437b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  TypeLoc TL = TSInfo->getTypeLoc();
3438c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  if (isa<TemplateSpecializationType>(T)) {
3439c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    TemplateSpecializationTypeLoc SpecTL
3440c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      = cast<TemplateSpecializationTypeLoc>(TL);
34414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3442b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    TemplateName Template
3443b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    = getDerived().TransformTemplateName(SS,
3444fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getTypePtr()->getTemplateName(),
3445fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                         SpecTL.getTemplateNameLoc(),
3446c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                         ObjectType, UnqualLookup);
34474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    if (Template.isNull())
3448b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return 0;
34494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
34504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3451c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor                                                              Template);
3452c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  } else if (isa<DependentTemplateSpecializationType>(T)) {
3453c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
3454c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor      = cast<DependentTemplateSpecializationTypeLoc>(TL);
34554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3456a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    TemplateName Template
34574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      = getDerived().RebuildTemplateName(SS,
34584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                         *SpecTL.getTypePtr()->getIdentifier(),
345955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara                                         SpecTL.getTemplateNameLoc(),
34607c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                         ObjectType, UnqualLookup);
3461a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    if (Template.isNull())
3462b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor      return 0;
34634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
34644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3465a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                                       SpecTL,
3466087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       Template,
3467087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                                                       SS);
3468c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  } else {
3469c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    // Nothing special needs to be done for these.
3470c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor    Result = getDerived().TransformType(TLB, TL);
3471c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor  }
34724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
34734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (Result.isNull())
3474b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor    return 0;
34754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3476b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor  return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3477c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor}
3478c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor
3479a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline
3480a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3481a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TyLoc NewT = TLB.push<TyLoc>(T.getType());
3482a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewT.setNameLoc(T.getNameLoc());
3483a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return T.getType();
3484a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
3485a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3486a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3487a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
348843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      BuiltinTypeLoc T) {
3489ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3490ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  NewT.setBuiltinLoc(T.getBuiltinLoc());
3491ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  if (T.needsExtraLocalData())
3492ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor    NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3493ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor  return T.getType();
3494577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3495577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
34961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3497a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
349843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      ComplexTypeLoc T) {
3499a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: recurse?
3500a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, T);
3501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
35021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3503a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3504a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
350543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      PointerTypeLoc TL) {
35064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType PointeeType
35074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    = getDerived().TransformType(TLB, TL.getPointeeLoc());
350892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (PointeeType.isNull())
350992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return QualType();
351092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
351192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  QualType Result = TL.getType();
3512c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (PointeeType->getAs<ObjCObjectType>()) {
351392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // A dependent pointer type 'T *' has is being transformed such
351492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // that an Objective-C class type is being replaced for 'T'. The
351592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // resulting pointer type is an ObjCObjectPointerType, not a
351692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // PointerType.
3517c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
35184a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3519c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3520c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NewT.setStarLoc(TL.getStarLoc());
352192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return Result;
352292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
352343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
352492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (getDerived().AlwaysRebuild() ||
352592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      PointeeType != TL.getPointeeLoc().getType()) {
352692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
352792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (Result.isNull())
352892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      return QualType();
352992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
35304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3531f85e193739c953358c865005855253af4f68a497John McCall  // Objective-C ARC can add lifetime qualifiers to the type that we're
3532f85e193739c953358c865005855253af4f68a497John McCall  // pointing to.
3533f85e193739c953358c865005855253af4f68a497John McCall  TLB.TypeWasModifiedSafely(Result->getPointeeType());
35344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
353592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
353692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
35374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  return Result;
3538577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3539577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
35401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
35411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3542a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
354343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                  BlockPointerTypeLoc TL) {
3544db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  QualType PointeeType
35454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    = getDerived().TransformType(TLB, TL.getPointeeLoc());
35464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (PointeeType.isNull())
35474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return QualType();
35484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
35494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType Result = TL.getType();
35504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().AlwaysRebuild() ||
35514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      PointeeType != TL.getPointeeLoc().getType()) {
35524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Result = getDerived().RebuildBlockPointerType(PointeeType,
3553db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor                                                  TL.getSigilLoc());
3554db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor    if (Result.isNull())
3555db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor      return QualType();
3556db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  }
3557db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor
355839968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor  BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
3559db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  NewT.setSigilLoc(TL.getSigilLoc());
3560db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor  return Result;
3561a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
35621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
356385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type.  Note that somewhat paradoxically we
356485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value
356585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type;  we only care if the type was *written* as an l-value type
356685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type.
356785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived>
356885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType
356985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
357043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ReferenceTypeLoc TL) {
357185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  const ReferenceType *T = TL.getTypePtr();
357285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
357385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // Note that this works with the pointee-as-written.
357485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
357585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (PointeeType.isNull())
357685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    return QualType();
357785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
357885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  QualType Result = TL.getType();
357985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (getDerived().AlwaysRebuild() ||
358085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      PointeeType != T->getPointeeTypeAsWritten()) {
358185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    Result = getDerived().RebuildReferenceType(PointeeType,
358285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               T->isSpelledAsLValue(),
358385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                               TL.getSigilLoc());
358485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    if (Result.isNull())
358585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall      return QualType();
358685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  }
358785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3588f85e193739c953358c865005855253af4f68a497John McCall  // Objective-C ARC can add lifetime qualifiers to the type that we're
3589f85e193739c953358c865005855253af4f68a497John McCall  // referring to.
3590f85e193739c953358c865005855253af4f68a497John McCall  TLB.TypeWasModifiedSafely(
3591f85e193739c953358c865005855253af4f68a497John McCall                     Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3592f85e193739c953358c865005855253af4f68a497John McCall
359385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  // r-value references can be rebuilt as l-value references.
359485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  ReferenceTypeLoc NewTL;
359585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  if (isa<LValueReferenceType>(Result))
359685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
359785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  else
359885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall    NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
359985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
360085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
360185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall  return Result;
360285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall}
360385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall
3604a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3605a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3606a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
360743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 LValueReferenceTypeLoc TL) {
360843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3609a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
36101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3611a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
3612a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3613a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
361443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 RValueReferenceTypeLoc TL) {
361543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return TransformReferenceType(TLB, TL);
3616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
36171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
36191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3620a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
362143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   MemberPointerTypeLoc TL) {
3622a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (PointeeType.isNull())
3624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3626b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3627b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  TypeSourceInfo* NewClsTInfo = 0;
3628b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  if (OldClsTInfo) {
3629b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3630b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (!NewClsTInfo)
3631b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return QualType();
3632b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
3633b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara
3634b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  const MemberPointerType *T = TL.getTypePtr();
3635b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  QualType OldClsType = QualType(T->getClass(), 0);
3636b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  QualType NewClsType;
3637b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  if (NewClsTInfo)
3638b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsType = NewClsTInfo->getType();
3639b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  else {
3640b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    NewClsType = getDerived().TransformType(OldClsType);
3641b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    if (NewClsType.isNull())
3642b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      return QualType();
3643b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  }
36441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3645a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3646a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3647a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      PointeeType != T->getPointeeType() ||
3648b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara      NewClsType != OldClsType) {
3649b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara    Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
365085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getStarLoc());
3651a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3652a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3653a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3655a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3656a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSigilLoc(TL.getSigilLoc());
3657b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara  NewTL.setClassTInfo(NewClsTInfo);
3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3659a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3660577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3661577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
36621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
36631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
3664a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
366543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ConstantArrayTypeLoc TL) {
3666f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ConstantArrayType *T = TL.getTypePtr();
3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
36701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3671a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildConstantArrayType(ElementType,
3675a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
3676a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSize(),
367785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             T->getIndexTypeCVRQualifiers(),
367885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3679a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3680a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3681a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3682457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman
3683457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman  // We might have either a ConstantArrayType or a VariableArrayType now:
3684457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman  // a ConstantArrayType is allowed to have an element type which is a
3685457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman  // VariableArrayType if the type is dependent.  Fortunately, all array
3686457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman  // types have the same location layout.
3687457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
36901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3691a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  Expr *Size = TL.getSizeExpr();
3692a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Size) {
3693f6702a3927147655206ae729a84339c4fda4c651Richard Smith    EnterExpressionEvaluationContext Unevaluated(SemaRef,
3694f6702a3927147655206ae729a84339c4fda4c651Richard Smith                                                 Sema::ConstantEvaluated);
3695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3696ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman    Size = SemaRef.ActOnConstantExpression(Size).take();
3697a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3698a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
3699a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3700a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
37021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType(
3705a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                              TypeLocBuilder &TLB,
370643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                              IncompleteArrayTypeLoc TL) {
3707f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const IncompleteArrayType *T = TL.getTypePtr();
3708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3709577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3710577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
37111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3714a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3715a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildIncompleteArrayType(ElementType,
3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                     T->getSizeModifier(),
371785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                           T->getIndexTypeCVRQualifiers(),
371885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                     TL.getBracketsRange());
3719a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3720a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3721a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
37224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3723a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3724a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3725a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(0);
3727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3728a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3729577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
37301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3731577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
3732a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3733a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
373443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   VariableArrayTypeLoc TL) {
3735f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VariableArrayType *T = TL.getTypePtr();
3736a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3737577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3738577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
37391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
374060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SizeResult
3741a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    = getDerived().TransformExpr(T->getSizeExpr());
3742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (SizeResult.isInvalid())
3743577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
37441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Size = SizeResult.take();
3746a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3748a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3749a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
3750a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Size != T->getSizeExpr()) {
3751a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildVariableArrayType(ElementType,
3752a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->getSizeModifier(),
37539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Size,
3754a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                             T->getIndexTypeCVRQualifiers(),
375585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   TL.getBracketsRange());
3756a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3757a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3758577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
37594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3760a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3761a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3762a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
3763a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setSizeExpr(Size);
37641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3765a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3766577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
37671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3769a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
3770a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
377143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                             DependentSizedArrayTypeLoc TL) {
3772f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedArrayType *T = TL.getTypePtr();
3773a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3774577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3775577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
37761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3777f6702a3927147655206ae729a84339c4fda4c651Richard Smith  // Array bounds are constant expressions.
3778f6702a3927147655206ae729a84339c4fda4c651Richard Smith  EnterExpressionEvaluationContext Unevaluated(SemaRef,
3779f6702a3927147655206ae729a84339c4fda4c651Richard Smith                                               Sema::ConstantEvaluated);
37801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // Prefer the expression from the TypeLoc;  the other may have been uniqued.
37823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *origSize = TL.getSizeExpr();
37833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!origSize) origSize = T->getSizeExpr();
37843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
37853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExprResult sizeResult
37863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    = getDerived().TransformExpr(origSize);
3787ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman  sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
37883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (sizeResult.isInvalid())
3789577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
37901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Expr *size = sizeResult.get();
3792a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3793a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3794a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3795a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType() ||
37963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      size != origSize) {
3797a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3798a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                         T->getSizeModifier(),
37993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                                                         size,
3800a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                T->getIndexTypeCVRQualifiers(),
380185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                        TL.getBracketsRange());
3802a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3804577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
38051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3806a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // We might have any sort of array type now, but fortunately they
3807a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // all have the same location layout.
3808a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3809a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setLBracketLoc(TL.getLBracketLoc());
3810a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setRBracketLoc(TL.getRBracketLoc());
38113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  NewTL.setSizeExpr(size);
3812a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3813a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3814577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3817577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
3818a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                      TypeLocBuilder &TLB,
381943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                      DependentSizedExtVectorTypeLoc TL) {
3820f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentSizedExtVectorType *T = TL.getTypePtr();
3821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3822a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // FIXME: ext vector locs should be nested
3823577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3824577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3825577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
38261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3827f6702a3927147655206ae729a84339c4fda4c651Richard Smith  // Vector sizes are constant expressions.
3828f6702a3927147655206ae729a84339c4fda4c651Richard Smith  EnterExpressionEvaluationContext Unevaluated(SemaRef,
3829f6702a3927147655206ae729a84339c4fda4c651Richard Smith                                               Sema::ConstantEvaluated);
3830670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor
383160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
3832ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman  Size = SemaRef.ActOnConstantExpression(Size);
3833577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (Size.isInvalid())
3834577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
38351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3836a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3837a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3838eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      ElementType != T->getElementType() ||
3839eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall      Size.get() != T->getSizeExpr()) {
3840a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
38419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                             Size.take(),
3842577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                         T->getAttributeLoc());
3843a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3844a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3845a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3846a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3847a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  // Result might be dependent or not.
3848a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (isa<DependentSizedExtVectorType>(Result)) {
3849a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    DependentSizedExtVectorTypeLoc NewTL
3850a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3851a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3852a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  } else {
3853a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3854a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setNameLoc(TL.getNameLoc());
3855a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
3856a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
3857a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3858577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3861a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
386243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     VectorTypeLoc TL) {
3863f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3864577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3865577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3866577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
3867577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
3868a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3869a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3870a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
387182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
3872e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                            T->getVectorKind());
3873a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3874a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3875a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
38764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3877a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3878a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
38791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3880a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3881577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
38821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
3884a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
388543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        ExtVectorTypeLoc TL) {
3886f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const VectorType *T = TL.getTypePtr();
3887577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType ElementType = getDerived().TransformType(T->getElementType());
3888577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (ElementType.isNull())
3889577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
38901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3891a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
3892a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
3893a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ElementType != T->getElementType()) {
3894a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildExtVectorType(ElementType,
3895a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               T->getNumElements(),
3896a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                               /*FIXME*/ SourceLocation());
3897a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
3898a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
3899a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
39004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
3901a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3902a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
39031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3904a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
3905577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
3906577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
39071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
390821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl *
39096a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3910fb44de956f27875def889482b5393475060392afJohn McCall                                                   int indexAdjustment,
3911d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                         llvm::Optional<unsigned> NumExpansions,
3912d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                   bool ExpectParameterPack) {
391321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
39146a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  TypeSourceInfo *NewDI = 0;
39154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
39166a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
39174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    // If we're substituting into a pack expansion type and we know the
3918d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor    // length we want to expand to, just substitute for the pattern.
39196a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc OldTL = OldDI->getTypeLoc();
39206a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
39214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
39226a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLocBuilder TLB;
39236a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TypeLoc NewTL = OldDI->getTypeLoc();
39246a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    TLB.reserve(NewTL.getFullDataSize());
39254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
39264a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    QualType Result = getDerived().TransformType(TLB,
39276a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                               OldExpansionTL.getPatternLoc());
39286a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
39296a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
39304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
39314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Result = RebuildPackExpansionType(Result,
39324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                OldExpansionTL.getPatternLoc().getSourceRange(),
39336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      OldExpansionTL.getEllipsisLoc(),
39346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor                                      NumExpansions);
39356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    if (Result.isNull())
39366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      return 0;
39374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
39386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    PackExpansionTypeLoc NewExpansionTL
39396a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      = TLB.push<PackExpansionTypeLoc>(Result);
39406a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
39416a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
39426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor  } else
39436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor    NewDI = getDerived().TransformType(OldDI);
394421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall  if (!NewDI)
394521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return 0;
394621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
3947fb44de956f27875def889482b5393475060392afJohn McCall  if (NewDI == OldDI && indexAdjustment == 0)
394821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall    return OldParm;
3949fb44de956f27875def889482b5393475060392afJohn McCall
3950fb44de956f27875def889482b5393475060392afJohn McCall  ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3951fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getDeclContext(),
3952fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getInnerLocStart(),
3953fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getLocation(),
3954fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getIdentifier(),
3955fb44de956f27875def889482b5393475060392afJohn McCall                                             NewDI->getType(),
3956fb44de956f27875def889482b5393475060392afJohn McCall                                             NewDI,
3957fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getStorageClass(),
3958fb44de956f27875def889482b5393475060392afJohn McCall                                             OldParm->getStorageClassAsWritten(),
3959fb44de956f27875def889482b5393475060392afJohn McCall                                             /* DefArg */ NULL);
3960fb44de956f27875def889482b5393475060392afJohn McCall  newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3961fb44de956f27875def889482b5393475060392afJohn McCall                        OldParm->getFunctionScopeIndex() + indexAdjustment);
3962fb44de956f27875def889482b5393475060392afJohn McCall  return newParm;
396321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall}
396421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
396521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
396621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>::
3967a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  TransformFunctionTypeParams(SourceLocation Loc,
3968a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              ParmVarDecl **Params, unsigned NumParams,
3969a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                              const QualType *ParamTypes,
3970686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                              SmallVectorImpl<QualType> &OutParamTypes,
3971686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                              SmallVectorImpl<ParmVarDecl*> *PVars) {
3972fb44de956f27875def889482b5393475060392afJohn McCall  int indexAdjustment = 0;
3973fb44de956f27875def889482b5393475060392afJohn McCall
3974a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor  for (unsigned i = 0; i != NumParams; ++i) {
3975a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (ParmVarDecl *OldParm = Params[i]) {
3976fb44de956f27875def889482b5393475060392afJohn McCall      assert(OldParm->getFunctionScopeIndex() == i);
3977fb44de956f27875def889482b5393475060392afJohn McCall
39786a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor      llvm::Optional<unsigned> NumExpansions;
3979406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      ParmVarDecl *NewParm = 0;
3980603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (OldParm->isParameterPack()) {
3981603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We have a function parameter pack that may need to be expanded.
3982686775deca8b8685eb90801495880e3abdd844c2Chris Lattner        SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3983603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
3984603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Find the parameter packs that could be expanded.
3985c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3986c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3987c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        TypeLoc Pattern = ExpansionTL.getPatternLoc();
3988c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
3989406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3990406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor
3991603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // Determine whether we should expand the parameter packs.
3992603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        bool ShouldExpand = false;
3993d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor        bool RetainExpansion = false;
39946a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        llvm::Optional<unsigned> OrigNumExpansions
39956a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor          = ExpansionTL.getTypePtr()->getNumExpansions();
39966a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor        NumExpansions = OrigNumExpansions;
3997c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor        if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3998c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor                                                 Pattern.getSourceRange(),
39994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                                 Unexpanded,
40004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                                 ShouldExpand,
4001d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 RetainExpansion,
4002d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                                 NumExpansions)) {
4003603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          return true;
4004603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
40054a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4006603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        if (ShouldExpand) {
4007603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // Expand the function parameter pack into multiple, separate
4008603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // parameters.
400912c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor          getDerived().ExpandingFunctionParameterPack(OldParm);
4010cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor          for (unsigned I = 0; I != *NumExpansions; ++I) {
4011603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
40124a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier            ParmVarDecl *NewParm
40136a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
4014fb44de956f27875def889482b5393475060392afJohn McCall                                                        indexAdjustment++,
4015d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                        OrigNumExpansions,
4016d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                /*ExpectParameterPack=*/false);
4017603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            if (!NewParm)
4018603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor              return true;
40194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4020a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            OutParamTypes.push_back(NewParm->getType());
4021a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            if (PVars)
4022a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor              PVars->push_back(NewParm);
4023603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          }
4024d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
4025d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // If we're supposed to retain a pack expansion, do so by temporarily
4026d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          // forgetting the partially-substituted parameter pack.
4027d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          if (RetainExpansion) {
4028d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            ForgetPartiallySubstitutedPackRAII Forget(getDerived());
40294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier            ParmVarDecl *NewParm
40306a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor              = getDerived().TransformFunctionTypeParam(OldParm,
4031fb44de956f27875def889482b5393475060392afJohn McCall                                                        indexAdjustment++,
4032d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                        OrigNumExpansions,
4033d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                /*ExpectParameterPack=*/false);
4034d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (!NewParm)
4035d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              return true;
40364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4037d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            OutParamTypes.push_back(NewParm->getType());
4038d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor            if (PVars)
4039d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor              PVars->push_back(NewParm);
4040d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor          }
4041d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
4042fb44de956f27875def889482b5393475060392afJohn McCall          // The next parameter should have the same adjustment as the
4043fb44de956f27875def889482b5393475060392afJohn McCall          // last thing we pushed, but we post-incremented indexAdjustment
4044fb44de956f27875def889482b5393475060392afJohn McCall          // on every push.  Also, if we push nothing, the adjustment should
4045fb44de956f27875def889482b5393475060392afJohn McCall          // go down by one.
4046fb44de956f27875def889482b5393475060392afJohn McCall          indexAdjustment--;
4047fb44de956f27875def889482b5393475060392afJohn McCall
4048603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          // We're done with the pack expansion.
4049603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          continue;
4050603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
40514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
40524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        // We'll substitute the parameter now without expanding the pack
4053603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // expansion.
4054406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4055406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4056fb44de956f27875def889482b5393475060392afJohn McCall                                                          indexAdjustment,
4057d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                          NumExpansions,
4058d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                  /*ExpectParameterPack=*/true);
4059406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      } else {
4060406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor        NewParm = getDerived().TransformFunctionTypeParam(OldParm,
4061fb44de956f27875def889482b5393475060392afJohn McCall                                                          indexAdjustment,
4062d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                          llvm::Optional<unsigned>(),
4063d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor                                                /*ExpectParameterPack=*/false);
4064603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
4065406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor
406621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall      if (!NewParm)
406721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
40684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4069a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      OutParamTypes.push_back(NewParm->getType());
4070a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (PVars)
4071a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor        PVars->push_back(NewParm);
4072603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      continue;
4073603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    }
4074a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4075a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // Deal with the possibility that we don't have a parameter
4076a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    // declaration for this parameter.
4077a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    QualType OldType = ParamTypes[i];
4078603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    bool IsPackExpansion = false;
4079cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    llvm::Optional<unsigned> NumExpansions;
4080406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor    QualType NewType;
40814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    if (const PackExpansionType *Expansion
4082603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor                                       = dyn_cast<PackExpansionType>(OldType)) {
4083603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // We have a function parameter pack that may need to be expanded.
4084603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      QualType Pattern = Expansion->getPattern();
4085686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4086603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
40874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4088603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // Determine whether we should expand the parameter packs.
4089603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      bool ShouldExpand = false;
4090d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor      bool RetainExpansion = false;
4091a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
40924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                               Unexpanded,
40934a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                               ShouldExpand,
4094d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               RetainExpansion,
4095d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                               NumExpansions)) {
409621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall        return true;
4097603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
40984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4099603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      if (ShouldExpand) {
41004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        // Expand the function parameter pack into multiple, separate
4101603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // parameters.
4102cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor        for (unsigned I = 0; I != *NumExpansions; ++I) {
4103603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4104603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          QualType NewType = getDerived().TransformType(Pattern);
4105603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor          if (NewType.isNull())
4106603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor            return true;
4107603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor
4108a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          OutParamTypes.push_back(NewType);
4109a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor          if (PVars)
4110a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor            PVars->push_back(0);
4111603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        }
41124a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4113603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        // We're done with the pack expansion.
4114603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor        continue;
4115603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      }
41164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
41173cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // If we're supposed to retain a pack expansion, do so by temporarily
41183cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      // forgetting the partially-substituted parameter pack.
41193cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      if (RetainExpansion) {
41203cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        ForgetPartiallySubstitutedPackRAII Forget(getDerived());
41213cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        QualType NewType = getDerived().TransformType(Pattern);
41223cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (NewType.isNull())
41233cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          return true;
41244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
41253cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        OutParamTypes.push_back(NewType);
41263cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor        if (PVars)
41273cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor          PVars->push_back(0);
41283cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor      }
4129d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor
41304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      // We'll substitute the parameter now without expanding the pack
4131603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      // expansion.
4132603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      OldType = Expansion->getPattern();
4133603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      IsPackExpansion = true;
4134406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4135406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      NewType = getDerived().TransformType(OldType);
4136406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor    } else {
4137406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor      NewType = getDerived().TransformType(OldType);
4138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    }
41394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4140603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (NewType.isNull())
4141603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor      return true;
41421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4143603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor    if (IsPackExpansion)
4144cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NewType = getSema().Context.getPackExpansionType(NewType,
4145cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                       NumExpansions);
41464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4147a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    OutParamTypes.push_back(NewType);
4148a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor    if (PVars)
4149a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor      PVars->push_back(0);
4150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
41511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4152fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG
4153fb44de956f27875def889482b5393475060392afJohn McCall  if (PVars) {
4154fb44de956f27875def889482b5393475060392afJohn McCall    for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4155fb44de956f27875def889482b5393475060392afJohn McCall      if (ParmVarDecl *parm = (*PVars)[i])
4156fb44de956f27875def889482b5393475060392afJohn McCall        assert(parm->getFunctionScopeIndex() == i);
4157603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor  }
4158fb44de956f27875def889482b5393475060392afJohn McCall#endif
4159fb44de956f27875def889482b5393475060392afJohn McCall
4160fb44de956f27875def889482b5393475060392afJohn McCall  return false;
4161fb44de956f27875def889482b5393475060392afJohn McCall}
416221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall
416321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived>
416421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType
416521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
416643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   FunctionProtoTypeLoc TL) {
4167cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor  return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4168cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor}
4169cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor
4170cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregortemplate<typename Derived>
4171cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas GregorQualType
4172cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas GregorTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4173cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor                                                   FunctionProtoTypeLoc TL,
4174cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor                                                   CXXRecordDecl *ThisContext,
4175cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor                                                   unsigned ThisTypeQuals) {
41767e010a04fef171049291d8cb3047f118566da090Douglas Gregor  // Transform the parameters and return type.
41777e010a04fef171049291d8cb3047f118566da090Douglas Gregor  //
4178e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith  // We are required to instantiate the params and return type in source order.
4179dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // When the function has a trailing return type, we instantiate the
4180dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // parameters before the return type,  since the return type can then refer
4181dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  // to the parameters themselves (via decltype, sizeof, etc.).
4182dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  //
4183686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<QualType, 4> ParamTypes;
4184686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<ParmVarDecl*, 4> ParamDecls;
4185f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionProtoType *T = TL.getTypePtr();
41867e010a04fef171049291d8cb3047f118566da090Douglas Gregor
4187dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  QualType ResultType;
4188dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
41899fbf327cfdd27ddb5d845042c95f2299ac95b143Richard Smith  if (T->hasTrailingReturn()) {
41904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4191a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
4192a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
41934a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                             TL.getTypePtr()->arg_type_begin(),
4194a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
4195dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4196dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4197cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor    {
4198cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor      // C++11 [expr.prim.general]p3:
41994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      //   If a declaration declares a member function or member function
42004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      //   template of a class X, the expression this is a prvalue of type
4201cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor      //   "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
42024a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      //   and the end of the function-definition, member-declarator, or
4203cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor      //   declarator.
4204cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor      Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
42054a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4206cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor      ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4207cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor      if (ResultType.isNull())
4208cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor        return QualType();
4209cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor    }
4210dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
4211dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  else {
4212dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4213dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor    if (ResultType.isNull())
4214dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4215dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
42164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4217a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getParmArray(),
4218a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 TL.getNumArgs(),
42194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                             TL.getTypePtr()->arg_type_begin(),
4220a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor                                                 ParamTypes, &ParamDecls))
4221dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor      return QualType();
4222dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor  }
4223dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor
4224e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith  // FIXME: Need to transform the exception-specification too.
4225e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith
4226a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4228a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType() ||
4229bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor      T->getNumArgs() != ParamTypes.size() ||
4230a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4231a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionProtoType(ResultType,
4232a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.data(),
4233a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   ParamTypes.size(),
4234a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                   T->isVariadic(),
4235eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith                                                   T->hasTrailingReturn(),
4236fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getTypeQuals(),
4237c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                   T->getRefQualifier(),
4238fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                   T->getExtInfo());
4239a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4240a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4241a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
42421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4243a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4244796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4245796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4246a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4247a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    NewTL.setArg(i, ParamDecls[i]);
4248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4249a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4250577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
42511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4252577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4253577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType(
4254a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                 TypeLocBuilder &TLB,
425543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 FunctionNoProtoTypeLoc TL) {
4256f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const FunctionNoProtoType *T = TL.getTypePtr();
4257a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4258a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (ResultType.isNull())
4259a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4260a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4261a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4262a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4263a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      ResultType != T->getResultType())
4264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4265a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4266a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4267796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4268796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara  NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
4269a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4270a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4271577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
42721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4273ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType
4274ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
427543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                 UnresolvedUsingTypeLoc TL) {
4276f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const UnresolvedUsingType *T = TL.getTypePtr();
42777c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor  Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
4278ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (!D)
4279ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return QualType();
4280ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4281ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType Result = TL.getType();
4282ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4283ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Result = getDerived().RebuildUnresolvedUsingType(D);
4284ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    if (Result.isNull())
4285ed97649e9574b9d854fa4d6109c9333ae0993554John McCall      return QualType();
4286ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
4287ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4288ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // We might get an arbitrary type spec type back.  We should at
4289ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  // least always get a type spec type, though.
4290ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4291ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  NewTL.setNameLoc(TL.getNameLoc());
4292ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4293ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return Result;
4294ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
4295ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
4296577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
429843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypedefTypeLoc TL) {
4299f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const TypedefType *T = TL.getTypePtr();
4300162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *Typedef
4301162e1c1b487352434552147967c3dd296ebee2f7Richard Smith    = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4302162e1c1b487352434552147967c3dd296ebee2f7Richard Smith                                                               T->getDecl()));
4303577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Typedef)
4304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
43051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4306a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4307a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Typedef != T->getDecl()) {
4309a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildTypedefType(Typedef);
4310a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4311a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4312a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4313a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4314a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4315a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
43161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4317a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4318577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4320577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4321a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
432243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TypeOfExprTypeLoc TL) {
4323670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // typeof expressions are not potentially evaluated contexts
4324f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
43251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
432660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
4327577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
4328577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
4329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
433072b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
433172b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  if (E.isInvalid())
433272b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman    return QualType();
433372b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman
4334a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4335a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4336cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall      E.get() != TL.getUnderlyingExpr()) {
43372a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
4338a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4339a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4340577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4341a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
43421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
4344cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
4345cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
4346cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
4347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4348a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4349577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4352a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
435343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     TypeOfTypeLoc TL) {
4354cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4355cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4356cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (!New_Under_TI)
4357577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
43581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4359a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4360cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4361cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall    Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
4362a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4363a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4364a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
43651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4366a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
4367cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setTypeofLoc(TL.getTypeofLoc());
4368cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setLParenLoc(TL.getLParenLoc());
4369cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setRParenLoc(TL.getRParenLoc());
4370cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall  NewTL.setUnderlyingTInfo(New_Under_TI);
4371a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4372a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4373577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
43741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4376a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
437743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                       DecltypeTypeLoc TL) {
4378f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DecltypeType *T = TL.getTypePtr();
4379a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4380670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor  // decltype expressions are not potentially evaluated contexts
438176f3f69db1416425070177243e9f390122c553e0Richard Smith  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
438276f3f69db1416425070177243e9f390122c553e0Richard Smith                                               /*IsDecltype=*/ true);
43831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
438460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
4385577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (E.isInvalid())
4386577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
43871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
438876f3f69db1416425070177243e9f390122c553e0Richard Smith  E = getSema().ActOnDecltypeExpression(E.take());
438976f3f69db1416425070177243e9f390122c553e0Richard Smith  if (E.isInvalid())
439076f3f69db1416425070177243e9f390122c553e0Richard Smith    return QualType();
439176f3f69db1416425070177243e9f390122c553e0Richard Smith
4392a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4393a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4394a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      E.get() != T->getUnderlyingExpr()) {
43952a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
4396a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4397a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4398577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  }
4399a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  else E.take();
4400a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4401a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4402a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
44031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4404a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4405577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4407577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4408ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType(
4409ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                            TypeLocBuilder &TLB,
4410ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                     UnaryTransformTypeLoc TL) {
4411ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType Result = TL.getType();
4412ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  if (Result->isDependentType()) {
4413ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    const UnaryTransformType *T = TL.getTypePtr();
4414ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    QualType NewBase =
4415ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4416ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    Result = getDerived().RebuildUnaryTransformType(NewBase,
4417ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    T->getUTTKind(),
4418ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                                    TL.getKWLoc());
4419ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    if (Result.isNull())
4420ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt      return QualType();
4421ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
4422ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
4423ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4424ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setKWLoc(TL.getKWLoc());
4425ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setParensRange(TL.getParensRange());
4426ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4427ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  return Result;
4428ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
4429ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
4430ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived>
443134b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
443234b41d939a1328f484511c6002ba2456db879a29Richard Smith                                                   AutoTypeLoc TL) {
443334b41d939a1328f484511c6002ba2456db879a29Richard Smith  const AutoType *T = TL.getTypePtr();
443434b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType OldDeduced = T->getDeducedType();
443534b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType NewDeduced;
443634b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (!OldDeduced.isNull()) {
443734b41d939a1328f484511c6002ba2456db879a29Richard Smith    NewDeduced = getDerived().TransformType(OldDeduced);
443834b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (NewDeduced.isNull())
443934b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
444034b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
444134b41d939a1328f484511c6002ba2456db879a29Richard Smith
444234b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType Result = TL.getType();
444334b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
444434b41d939a1328f484511c6002ba2456db879a29Richard Smith    Result = getDerived().RebuildAutoType(NewDeduced);
444534b41d939a1328f484511c6002ba2456db879a29Richard Smith    if (Result.isNull())
444634b41d939a1328f484511c6002ba2456db879a29Richard Smith      return QualType();
444734b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
444834b41d939a1328f484511c6002ba2456db879a29Richard Smith
444934b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
445034b41d939a1328f484511c6002ba2456db879a29Richard Smith  NewTL.setNameLoc(TL.getNameLoc());
445134b41d939a1328f484511c6002ba2456db879a29Richard Smith
445234b41d939a1328f484511c6002ba2456db879a29Richard Smith  return Result;
445334b41d939a1328f484511c6002ba2456db879a29Richard Smith}
445434b41d939a1328f484511c6002ba2456db879a29Richard Smith
445534b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived>
4456a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
445743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                     RecordTypeLoc TL) {
4458f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const RecordType *T = TL.getTypePtr();
4459577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  RecordDecl *Record
44607c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
44617c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                          T->getDecl()));
4462577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Record)
4463577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
44641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4465a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4466a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4467a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Record != T->getDecl()) {
4468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildRecordType(Record);
4469a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
44721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4473a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4474a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
4475a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4476a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4477577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
44781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4480a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
448143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   EnumTypeLoc TL) {
4482f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const EnumType *T = TL.getTypePtr();
4483577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  EnumDecl *Enum
44847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
44857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                        T->getDecl()));
4486577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (!Enum)
4487577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
44881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
4491a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      Enum != T->getDecl()) {
4492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    Result = getDerived().RebuildEnumType(Enum);
4493a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4494a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4496a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4497a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4498a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  NewTL.setNameLoc(TL.getNameLoc());
44991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4500a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4501577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
45027da2431c23ef1ee8acb114e39692246e1801afc2John McCall
45033cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived>
45043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType(
45053cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                         TypeLocBuilder &TLB,
450643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         InjectedClassNameTypeLoc TL) {
45073cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
45083cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall                                       TL.getTypePtr()->getDecl());
45093cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  if (!D) return QualType();
45103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
45113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
45123cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
45133cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  return T;
45143cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall}
45153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
4516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
4517577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType(
4518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                                TypeLocBuilder &TLB,
451943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                TemplateTypeParmTypeLoc TL) {
4520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return TransformTypeSpecType(TLB, TL);
4521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
4522577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
45231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
452449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
4525a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall                                         TypeLocBuilder &TLB,
452643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                         SubstTemplateTypeParmTypeLoc TL) {
45270b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  const SubstTemplateTypeParmType *T = TL.getTypePtr();
45284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
45290b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Substitute into the replacement type, which itself might involve something
45300b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // that needs to be transformed. This only tends to occur with default
45310b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // template arguments of template template parameters.
45320b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
45330b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  QualType Replacement = getDerived().TransformType(T->getReplacementType());
45340b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  if (Replacement.isNull())
45350b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    return QualType();
45364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
45370b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Always canonicalize the replacement type.
45380b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  Replacement = SemaRef.Context.getCanonicalType(Replacement);
45390b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  QualType Result
45404a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
45410b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor                                                   Replacement);
45424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
45430b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  // Propagate type-source information.
45440b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  SubstTemplateTypeParmTypeLoc NewTL
45450b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor    = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
45460b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  NewTL.setNameLoc(TL.getNameLoc());
45470b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor  return Result;
45480b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor
454949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall}
455049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
455149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived>
4552c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4553c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          TypeLocBuilder &TLB,
4554c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                          SubstTemplateTypeParmPackTypeLoc TL) {
4555c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  return TransformTypeSpecType(TLB, TL);
4556c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor}
4557c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
4558c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived>
4559833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
456043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                        TypeLocBuilder &TLB,
456143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                           TemplateSpecializationTypeLoc TL) {
456243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  const TemplateSpecializationType *T = TL.getTypePtr();
4563828bff2079b6a91ecd7ed5b842c59527d7682789John McCall
45641d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  // The nested-name-specifier never matters in a TemplateSpecializationType,
45651d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  // because we can't have a dependent nested-name-specifier anyway.
45661d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor  CXXScopeSpec SS;
456743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  TemplateName Template
45681d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor    = getDerived().TransformTemplateName(SS, T->getTemplateName(),
45691d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor                                         TL.getTemplateNameLoc());
457043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (Template.isNull())
457143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4572833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
457343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4574dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor}
457543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
4576b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived>
4577b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4578b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman                                                     AtomicTypeLoc TL) {
4579b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4580b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  if (ValueType.isNull())
4581b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return QualType();
4582b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4583b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType Result = TL.getType();
4584b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  if (getDerived().AlwaysRebuild() ||
4585b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman      ValueType != TL.getValueLoc().getType()) {
4586b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4587b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    if (Result.isNull())
4588b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman      return QualType();
4589b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
4590b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4591b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4592b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  NewTL.setKWLoc(TL.getKWLoc());
4593b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  NewTL.setLParenLoc(TL.getLParenLoc());
4594b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  NewTL.setRParenLoc(TL.getRParenLoc());
4595b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4596b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  return Result;
4597b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}
4598b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
45997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace {
46004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  /// \brief Simple iterator that traverses the template arguments in a
46017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// container that provides a \c getArgLoc() member function.
46027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  ///
46037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// This iterator is intended to be used with the iterator form of
46047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  /// \c TreeTransform<Derived>::TransformTemplateArguments().
46057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  template<typename ArgLocContainer>
46067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  class TemplateArgumentLocContainerIterator {
46077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgLocContainer *Container;
46087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    unsigned Index;
46094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  public:
46117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc value_type;
46127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef TemplateArgumentLoc reference;
46137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef int difference_type;
46147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    typedef std::input_iterator_tag iterator_category;
46154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    class pointer {
46177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLoc Arg;
46184a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    public:
46207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
46214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      const TemplateArgumentLoc *operator->() const {
46237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor        return &Arg;
46247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      }
46257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    };
46264a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator() {}
46294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
46317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                 unsigned Index)
46327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      : Container(&Container), Index(Index) { }
46334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator &operator++() {
46357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++Index;
46367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return *this;
46377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
46384a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLocContainerIterator operator++(int) {
46407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      TemplateArgumentLocContainerIterator Old(*this);
46417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      ++(*this);
46427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Old;
46437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
46444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    TemplateArgumentLoc operator*() const {
46467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return Container->getArgLoc(Index);
46477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
46484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    pointer operator->() const {
46507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return pointer(Container->getArgLoc(Index));
46517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
46524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator==(const TemplateArgumentLocContainerIterator &X,
4654f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
46557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return X.Container == Y.Container && X.Index == Y.Index;
46567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
46574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
4659f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor                           const TemplateArgumentLocContainerIterator &Y) {
46607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor      return !(X == Y);
46617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    }
46627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  };
46637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}
46644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
46654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
466643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived>
4667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4668833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                        TypeLocBuilder &TLB,
4669833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                           TemplateSpecializationTypeLoc TL,
467043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      TemplateName Template) {
4671d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo NewTemplateArgs;
4672d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4673d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
46747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor  typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
46757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor    ArgIterator;
46764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
46777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
46787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor                                              NewTemplateArgs))
46797f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor    return QualType();
46801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4681833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  // FIXME: maybe don't rebuild if all the template arguments are the same.
4682833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
4683833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  QualType Result =
4684833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    getDerived().RebuildTemplateSpecializationType(Template,
4685833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                   TL.getTemplateNameLoc(),
4686d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                                   NewTemplateArgs);
46871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4688833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  if (!Result.isNull()) {
46893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // Specializations of template template parameters are represented as
46903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // TemplateSpecializationTypes, and substitution of type alias templates
46913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // within a dependent context can transform them into
46923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    // DependentTemplateSpecializationTypes.
46933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    if (isa<DependentTemplateSpecializationType>(Result)) {
46943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      DependentTemplateSpecializationTypeLoc NewTL
46953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
469655d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara      NewTL.setElaboratedKeywordLoc(SourceLocation());
46973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setQualifierLoc(NestedNameSpecifierLoc());
469866581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara      NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
469955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara      NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
47003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setLAngleLoc(TL.getLAngleLoc());
47013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      NewTL.setRAngleLoc(TL.getRAngleLoc());
47023e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
47033e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith        NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
47043e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      return Result;
47053e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    }
47063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
4707833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TemplateSpecializationTypeLoc NewTL
4708833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      = TLB.push<TemplateSpecializationTypeLoc>(Result);
470955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara    NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
4710833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4711833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setLAngleLoc(TL.getLAngleLoc());
4712833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    NewTL.setRAngleLoc(TL.getRAngleLoc());
4713833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4714833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4715833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  }
47161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4717833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return Result;
4718577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
47191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4720a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived>
4721a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4722a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                     TypeLocBuilder &TLB,
4723a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                     DependentTemplateSpecializationTypeLoc TL,
4724087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                     TemplateName Template,
4725087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor                                     CXXScopeSpec &SS) {
4726a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  TemplateArgumentListInfo NewTemplateArgs;
4727a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4728a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4729a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  typedef TemplateArgumentLocContainerIterator<
4730a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor            DependentTemplateSpecializationTypeLoc> ArgIterator;
47314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4732a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
4733a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                              NewTemplateArgs))
4734a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    return QualType();
47354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4736a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  // FIXME: maybe don't rebuild if all the template arguments are the same.
47374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4738a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4739a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    QualType Result
4740a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = getSema().Context.getDependentTemplateSpecializationType(
4741a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                TL.getTypePtr()->getKeyword(),
4742a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                         DTN->getQualifier(),
4743a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                         DTN->getIdentifier(),
4744a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                               NewTemplateArgs);
47454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4746a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    DependentTemplateSpecializationTypeLoc NewTL
4747a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
474855d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara    NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
474994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
475066581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara    NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
475155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4752a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setLAngleLoc(TL.getLAngleLoc());
4753a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setRAngleLoc(TL.getRAngleLoc());
4754a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4755a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4756a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    return Result;
4757a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
47584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
47594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType Result
4760a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    = getDerived().RebuildTemplateSpecializationType(Template,
476155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara                                                     TL.getTemplateNameLoc(),
4762a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor                                                     NewTemplateArgs);
47634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4764a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  if (!Result.isNull()) {
4765a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    /// FIXME: Wrap this in an elaborated-type-specifier?
4766a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    TemplateSpecializationTypeLoc NewTL
4767a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(Result);
476866581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara    NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
476955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara    NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4770a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setLAngleLoc(TL.getLAngleLoc());
4771a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    NewTL.setRAngleLoc(TL.getRAngleLoc());
4772a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4773a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4774a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
47754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
4776a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  return Result;
4777a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor}
4778a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor
47791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
4780a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
4781465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
478243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ElaboratedTypeLoc TL) {
4783f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const ElaboratedType *T = TL.getTypePtr();
4784465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
47859e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
4786465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // NOTE: the qualifier in an ElaboratedType is optional.
47879e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  if (TL.getQualifierLoc()) {
47884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    QualifierLoc
47899e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
47909e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    if (!QualifierLoc)
4791465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      return QualType();
4792465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
47931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
479443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
479543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  if (NamedT.isNull())
479643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    return QualType();
4797a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar
47983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  // C++0x [dcl.type.elab]p2:
47993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   If the identifier resolves to a typedef-name or the simple-template-id
48003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   resolves to an alias template specialization, the
48013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  //   elaborated-type-specifier is ill-formed.
48021804174e1591bf59118f317775b48edd0382c3f0Richard Smith  if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
48031804174e1591bf59118f317775b48edd0382c3f0Richard Smith    if (const TemplateSpecializationType *TST =
48041804174e1591bf59118f317775b48edd0382c3f0Richard Smith          NamedT->getAs<TemplateSpecializationType>()) {
48051804174e1591bf59118f317775b48edd0382c3f0Richard Smith      TemplateName Template = TST->getTemplateName();
48061804174e1591bf59118f317775b48edd0382c3f0Richard Smith      if (TypeAliasTemplateDecl *TAT =
48071804174e1591bf59118f317775b48edd0382c3f0Richard Smith          dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
48081804174e1591bf59118f317775b48edd0382c3f0Richard Smith        SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
48091804174e1591bf59118f317775b48edd0382c3f0Richard Smith                     diag::err_tag_reference_non_tag) << 4;
48101804174e1591bf59118f317775b48edd0382c3f0Richard Smith        SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
48111804174e1591bf59118f317775b48edd0382c3f0Richard Smith      }
48123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    }
48133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  }
48143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
4815a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  QualType Result = TL.getType();
4816a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (getDerived().AlwaysRebuild() ||
48179e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor      QualifierLoc != TL.getQualifierLoc() ||
4818e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara      NamedT != T->getNamedType()) {
481938a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara    Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
48204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                                T->getKeyword(),
48219e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor                                                QualifierLoc, NamedT);
4822a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    if (Result.isNull())
4823a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall      return QualType();
4824a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  }
4825577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
4826465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
482738a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara  NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
48289e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor  NewTL.setQualifierLoc(QualifierLoc);
4829a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4830577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
48311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
48339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType(
48349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                TypeLocBuilder &TLB,
48359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                                AttributedTypeLoc TL) {
48369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  const AttributedType *oldType = TL.getTypePtr();
48379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
48389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (modifiedType.isNull())
48399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return QualType();
48409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
48419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType result = TL.getType();
48429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
48439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // FIXME: dependent operand expressions?
48449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (getDerived().AlwaysRebuild() ||
48459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      modifiedType != oldType->getModifiedType()) {
48469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // TODO: this is really lame; we should really be rebuilding the
48479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // equivalent type from first principles.
48489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    QualType equivalentType
48499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      = getDerived().TransformType(oldType->getEquivalentType());
48509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    if (equivalentType.isNull())
48519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      return QualType();
48529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
48539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               modifiedType,
48549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                                               equivalentType);
48559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
48569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
48579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
48589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  newTL.setAttrNameLoc(TL.getAttrNameLoc());
48599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrOperand())
48609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
48619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  if (TL.hasAttrExprOperand())
48629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrExprOperand(TL.getAttrExprOperand());
48639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  else if (TL.hasAttrEnumOperand())
48649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
48659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
48669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  return result;
48679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall}
48689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
48699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived>
4870075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType
4871075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4872075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara                                           ParenTypeLoc TL) {
4873075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4874075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (Inner.isNull())
4875075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType();
4876075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4877075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Result = TL.getType();
4878075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  if (getDerived().AlwaysRebuild() ||
4879075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      Inner != TL.getInnerLoc().getType()) {
4880075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Result = getDerived().RebuildParenType(Inner);
4881075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    if (Result.isNull())
4882075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara      return QualType();
4883075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
4884075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4885075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4886075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setLParenLoc(TL.getLParenLoc());
4887075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  NewTL.setRParenLoc(TL.getRParenLoc());
4888075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  return Result;
4889075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara}
4890075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
4891075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived>
48924714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
489343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                      DependentNameTypeLoc TL) {
4894f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const DependentNameType *T = TL.getTypePtr();
4895833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
48962494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  NestedNameSpecifierLoc QualifierLoc
48972494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
48982494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor  if (!QualifierLoc)
4899577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return QualType();
49001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
490133500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType Result
49022494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    = getDerived().RebuildDependentNameType(T->getKeyword(),
490338a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara                                            TL.getElaboratedKeywordLoc(),
49042494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            QualifierLoc,
49052494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor                                            T->getIdentifier(),
490633500955d731c73717af52088b7fc0e7a85681e7John McCall                                            TL.getNameLoc());
4907a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  if (Result.isNull())
4908a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall    return QualType();
4909a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
4910e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4911e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    QualType NamedT = ElabT->getNamedType();
491233500955d731c73717af52088b7fc0e7a85681e7John McCall    TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
491333500955d731c73717af52088b7fc0e7a85681e7John McCall
4914e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
491538a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara    NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
49169e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
491733500955d731c73717af52088b7fc0e7a85681e7John McCall  } else {
4918e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
491938a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara    NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
49202494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
4921e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara    NewTL.setNameLoc(TL.getNameLoc());
4922e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara  }
4923a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return Result;
4924577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
49251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4926577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
492733500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>::
492833500955d731c73717af52088b7fc0e7a85681e7John McCall          TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
492943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                 DependentTemplateSpecializationTypeLoc TL) {
493094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
493194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (TL.getQualifierLoc()) {
493294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualifierLoc
493394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
493494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    if (!QualifierLoc)
4935a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor      return QualType();
4936a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor  }
49374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
493843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return getDerived()
493994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor           .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
494043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall}
494143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
494243fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived>
494343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::
494494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
494594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                   DependentTemplateSpecializationTypeLoc TL,
494694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                       NestedNameSpecifierLoc QualifierLoc) {
494794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  const DependentTemplateSpecializationType *T = TL.getTypePtr();
49484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
494994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  TemplateArgumentListInfo NewTemplateArgs;
495094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
495194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
49524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
495394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  typedef TemplateArgumentLocContainerIterator<
495494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  DependentTemplateSpecializationTypeLoc> ArgIterator;
495594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
495694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                              ArgIterator(TL, TL.getNumArgs()),
495794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                              NewTemplateArgs))
495894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return QualType();
49594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
496094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  QualType Result
496194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
496294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                              QualifierLoc,
496394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            T->getIdentifier(),
496455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara                                                       TL.getTemplateNameLoc(),
496594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor                                                            NewTemplateArgs);
496694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (Result.isNull())
496794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    return QualType();
49684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
496994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
497094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    QualType NamedT = ElabT->getNamedType();
49714a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
497294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Copy information relevant to the template specialization.
497394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    TemplateSpecializationTypeLoc NamedTL
49740a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
497566581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara    NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
497655d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara    NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
497794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NamedTL.setLAngleLoc(TL.getLAngleLoc());
497894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NamedTL.setRAngleLoc(TL.getRAngleLoc());
4979944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
49800a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
49814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
498294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    // Copy information relevant to the elaborated type.
498394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
498438a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara    NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
498594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor    NewTL.setQualifierLoc(QualifierLoc);
49860a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor  } else if (isa<DependentTemplateSpecializationType>(Result)) {
49870a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    DependentTemplateSpecializationTypeLoc SpecTL
49880a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
498955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara    SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
49900a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setQualifierLoc(QualifierLoc);
499166581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara    SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
499255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara    SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
49930a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setLAngleLoc(TL.getLAngleLoc());
49940a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setRAngleLoc(TL.getRAngleLoc());
4995944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
49960a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
499794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  } else {
49980a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    TemplateSpecializationTypeLoc SpecTL
49990a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      = TLB.push<TemplateSpecializationTypeLoc>(Result);
500066581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara    SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
500155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara    SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
50020a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setLAngleLoc(TL.getLAngleLoc());
50030a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor    SpecTL.setRAngleLoc(TL.getRAngleLoc());
5004944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor    for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
50050a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor      SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
500694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  }
500794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor  return Result;
500894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor}
500994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor
501094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived>
50117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
50127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor                                                      PackExpansionTypeLoc TL) {
50134a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType Pattern
50144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    = getDerived().TransformType(TLB, TL.getPatternLoc());
50152fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (Pattern.isNull())
50162fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    return QualType();
50174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
50184a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  QualType Result = TL.getType();
50192fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  if (getDerived().AlwaysRebuild() ||
50202fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      Pattern != TL.getPatternLoc().getType()) {
50214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Result = getDerived().RebuildPackExpansionType(Pattern,
50222fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor                                           TL.getPatternLoc().getSourceRange(),
5023cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                                   TL.getEllipsisLoc(),
5024cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                                           TL.getTypePtr()->getNumExpansions());
50252fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor    if (Result.isNull())
50262fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor      return QualType();
50272fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  }
50284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
50292fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
50302fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  NewT.setEllipsisLoc(TL.getEllipsisLoc());
50312fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor  return Result;
50327536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor}
50337536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
50347536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived>
5035a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
5036a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
503743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                   ObjCInterfaceTypeLoc TL) {
5038ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCInterfaceType is never dependent.
5039c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
5040c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return TL.getType();
5041c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
5042c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
5043c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived>
5044c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType
5045c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
504643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                                ObjCObjectTypeLoc TL) {
5047c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // ObjCObjectType is never dependent.
5048c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
5049ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
5050577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
50511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
5053a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType
5054a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
505543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                               ObjCObjectPointerTypeLoc TL) {
5056ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  // ObjCObjectPointerType is never dependent.
5057c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  TLB.pushFullCopy(TL);
5058ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor  return TL.getType();
505924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis}
506024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis
5061577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
506243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation
506343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
506443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
506560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
50673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
506843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
506943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
507043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
507160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
507243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
507343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().TransformCompoundStmt(S, false);
507443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
507543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
507643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
507760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
50781eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
507943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                              bool IsStmtExpr) {
5080625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  Sema::CompoundScopeRAII CompoundScope(getSema());
5081625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko
50827114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  bool SubStmtInvalid = false;
508343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool SubStmtChanged = false;
50844e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Stmt*, 8> Statements;
508543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
508643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       B != BEnd; ++B) {
508760d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Result = getDerived().TransformStmt(*B);
50887114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    if (Result.isInvalid()) {
50897114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Immediately fail if this was a DeclStmt, since it's very
50907114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // likely that this will cause problems for future statements.
50917114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      if (isa<DeclStmt>(*B))
50927114cbab7eb6e8b714eb22f014327daf2c741c08John McCall        return StmtError();
50937114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
50947114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      // Otherwise, just keep processing substatements and fail later.
50957114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      SubStmtInvalid = true;
50967114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      continue;
50977114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
50981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
509943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    SubStmtChanged = SubStmtChanged || Result.get() != *B;
510043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Statements.push_back(Result.takeAs<Stmt>());
510143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
51021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51037114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  if (SubStmtInvalid)
51047114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    return StmtError();
51057114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
510643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
510743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !SubStmtChanged)
51083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
510943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
511043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
51113fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                          Statements,
511243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          S->getRBracLoc(),
511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          IsStmtExpr);
511443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
511760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
51181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
511960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS, RHS;
5120264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  {
51216b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman    EnterExpressionEvaluationContext Unevaluated(SemaRef,
51226b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman                                                 Sema::ConstantEvaluated);
51231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5124264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the left-hand case value.
5125264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    LHS = getDerived().TransformExpr(S->getLHS());
5126ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman    LHS = SemaRef.ActOnConstantExpression(LHS);
5127264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (LHS.isInvalid())
5128f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
51291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5130264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    // Transform the right-hand case value (for the GNU case-range extension).
5131264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    RHS = getDerived().TransformExpr(S->getRHS());
5132ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman    RHS = SemaRef.ActOnConstantExpression(RHS);
5133264c1f8ec895952466eab59b84b8b06801e721faEli Friedman    if (RHS.isInvalid())
5134f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5135264c1f8ec895952466eab59b84b8b06801e721faEli Friedman  }
51361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
513743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Build the case statement.
513843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Case statements are always rebuilt so that they will attached to their
513943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transformed switch statement.
514060d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
51419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       LHS.get(),
514243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getEllipsisLoc(),
51439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       RHS.get(),
514443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                                       S->getColonLoc());
514543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Case.isInvalid())
5146f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
514843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the case
514960d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
515043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
5151f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
515343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Attach the body to the case statement
51549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
515543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
515643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
515743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
515860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
51591eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
516043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the statement following the default case
516160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
516243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
5163f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
516543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Default statements are always rebuilt
516643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
51679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                         SubStmt.get());
516843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
517043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
517160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
51721eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
517360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
517443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (SubStmt.isInvalid())
5175f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
51761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
517757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
517857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getDecl());
517957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
518057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
5181534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
5182534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
518343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // FIXME: Pass the real colon location in.
5184ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  return getDerived().RebuildLabelStmt(S->getIdentLoc(),
518557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       cast<LabelDecl>(LD), SourceLocation(),
518657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                       SubStmt.get());
518743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
51881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
518943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
519060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
5191534986f2b21e6050bf00163cd6423fd92155a6edRichard SmithTreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5192534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5193534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  if (SubStmt.isInvalid())
5194534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return StmtError();
5195534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
5196534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  // TODO: transform attributes
5197534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5198534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith    return S;
5199534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
5200534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5201534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith                                            S->getAttrs(),
5202534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith                                            SubStmt.get());
5203534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith}
5204534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith
5205534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithtemplate<typename Derived>
5206534986f2b21e6050bf00163cd6423fd92155a6edRichard SmithStmtResult
52071eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
520843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
520960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
52108cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  VarDecl *ConditionVar = 0;
52118cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor  if (S->getConditionVariable()) {
52124a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    ConditionVar
52138cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor      = cast_or_null<VarDecl>(
5214aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5215aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5216aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
52178cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    if (!ConditionVar)
5218f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
521999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
52208cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
52214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
522299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5223f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
52244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5225eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor    // Convert the condition to a boolean value.
5226afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
52274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
52288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5229afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5230f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
52314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
52329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
5233afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
523499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
52354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
52369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
52379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5238f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
52394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
524043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "then" branch.
524160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Then = getDerived().TransformStmt(S->getThen());
524243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Then.isInvalid())
5243f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
52441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
524543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the "else" branch.
524660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Else = getDerived().TransformStmt(S->getElse());
524743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Else.isInvalid())
5248f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
52491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
525043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
52519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
525299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
525343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Then.get() == S->getThen() &&
525443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Else.get() == S->getElse())
52553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
52561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5257eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
525844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis                                    Then.get(),
52599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    S->getElseLoc(), Else.get());
526043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
526143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
526243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
526360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
52641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
526543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition.
526660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
5267d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  VarDecl *ConditionVar = 0;
5268d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor  if (S->getConditionVariable()) {
52694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    ConditionVar
5270d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor      = cast_or_null<VarDecl>(
5271aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5272aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5273aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
5274d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    if (!ConditionVar)
5275f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
527699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
5277d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
52784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
527999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5280f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
528199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
52821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
528343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Rebuild the switch statement.
528460d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Switch
52859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
5286586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor                                          ConditionVar);
528743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Switch.isInvalid())
5288f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
52891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
529043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body of the switch statement.
529160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
529243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5293f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
52941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
529543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Complete the switch statement.
52969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
52979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            Body.get());
529843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
52991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
530043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
530160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
53021eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
530343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
530460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
53055656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  VarDecl *ConditionVar = 0;
53065656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor  if (S->getConditionVariable()) {
53074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    ConditionVar
53085656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      = cast_or_null<VarDecl>(
5309aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5310aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5311aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
53125656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    if (!ConditionVar)
5313f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
531499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
53155656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
53164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
531799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5318f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5319afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
5320afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
5321afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
53224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
53238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5324afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5325f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
53269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE;
5327afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
532899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
53291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
53319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5332f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5333eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
533443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
533560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
533643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5337f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
53381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
533943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
53409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
534199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      ConditionVar == S->getConditionVariable() &&
534243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
53439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return Owned(S);
53441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5345eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
53469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       ConditionVar, Body.get());
534743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
53481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
534943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
535060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
535143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
535243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
535360d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
535443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5355f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
53561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5357eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  // Transform the condition
535860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(S->getCond());
5359eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor  if (Cond.isInvalid())
5360f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
53614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
536243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
536343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Cond.get() == S->getCond() &&
536443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
53653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
53661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
53689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                    /*FIXME:*/S->getWhileLoc(), Cond.get(),
536943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                    S->getRParenLoc());
537043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
53711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
537243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
537360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
53741eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) {
537543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the initialization statement
537660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Init = getDerived().TransformStmt(S->getInit());
537743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Init.isInvalid())
5378f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
53791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
538043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the condition
538160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond;
538299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  VarDecl *ConditionVar = 0;
538399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  if (S->getConditionVariable()) {
53844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    ConditionVar
538599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor      = cast_or_null<VarDecl>(
5386aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                   getDerived().TransformDefinition(
5387aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                      S->getConditionVariable()->getLocation(),
5388aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                    S->getConditionVariable()));
538999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (!ConditionVar)
5390f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
539199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  } else {
539299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    Cond = getDerived().TransformExpr(S->getCond());
53934a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
539499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    if (Cond.isInvalid())
5395f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5396afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
5397afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    if (S->getCond()) {
5398afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      // Convert the condition to a boolean value.
53994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
54008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor                                                         Cond.get());
5401afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor      if (CondE.isInvalid())
5402f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5403afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor
54049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Cond = CondE.get();
5405afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor    }
540699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor  }
54071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
54099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
5410f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5411eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
541243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the increment
541360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Inc = getDerived().TransformExpr(S->getInc());
541443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Inc.isInvalid())
5415f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
54161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
54189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (S->getInc() && !FullInc.get())
5419f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5420eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor
542143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the body
542260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
542343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Body.isInvalid())
5424f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
54251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
542643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
542743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Init.get() == S->getInit() &&
54289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      FullCond.get() == S->getCond() &&
542943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Inc.get() == S->getInc() &&
543043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Body.get() == S->getBody())
54313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
54321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
543343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
54349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     Init.get(), FullCond, ConditionVar,
54359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                     FullInc, S->getRParenLoc(), Body.get());
543643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
543743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
543843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
543960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
544157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
544257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        S->getLabel());
544357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
544457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return StmtError();
54454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
544643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Goto statements must always be rebuilt, to resolve the label.
54471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
544857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                      cast<LabelDecl>(LD));
544943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
545043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
545143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
545260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
545460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Target = getDerived().TransformExpr(S->getTarget());
545543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Target.isInvalid())
5456f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
5457d29975fd08713eb9d1777e60536addaa62df8995Eli Friedman  Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
54581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
545943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
546043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Target.get() == S->getTarget())
54613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
546243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
546343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
54649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              Target.get());
546543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
546643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
546743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
546860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54691eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
54703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
547143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
547343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
547460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54751eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
54763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(S);
547743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
547943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
548060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54811eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
548260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result = getDerived().TransformExpr(S->getRetValue());
548343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (Result.isInvalid())
5484f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
548543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
54861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: We always rebuild the return statement because there is no way
548743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // to tell whether the return type of the function has changed.
54889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
548943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
54901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
549143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
549260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
54931eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
549443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool DeclChanged = false;
5495686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Decl *, 4> Decls;
549643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
549743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor       D != DEnd; ++D) {
5498aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor    Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5499aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor                                                         *D);
550043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (!Transformed)
5501f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
55021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
550343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Transformed != *D)
550443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      DeclChanged = true;
55051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
550643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Decls.push_back(Transformed);
550743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
55081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
550943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() && !DeclChanged)
55103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
55111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
55121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
551343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                      S->getStartLoc(), S->getEndLoc());
551443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
55151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
551643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
551760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
5518df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad RosierTreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
55194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
55204e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Constraints;
55214e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Exprs;
5522686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<IdentifierInfo *, 4> Names;
5523a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson
552460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult AsmString;
55254e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Clobbers;
5526703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5527703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  bool ExprsChanged = false;
55284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5529703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the outputs.
5530703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
5531ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getOutputIdentifier(I));
55324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5533703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
55343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getOutputConstraintLiteral(I));
55354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5536703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the output expr.
5537703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *OutputExpr = S->getOutputExpr(I);
553860d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(OutputExpr);
5539703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
5540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
55414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5542703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != OutputExpr;
55434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
55449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
5545703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
55464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5547703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the inputs.
5548703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
5549ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson    Names.push_back(S->getInputIdentifier(I));
55504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5551703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // No need to transform the constraint literal.
55523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    Constraints.push_back(S->getInputConstraintLiteral(I));
55534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5554703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    // Transform the input expr.
5555703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    Expr *InputExpr = S->getInputExpr(I);
555660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Result = getDerived().TransformExpr(InputExpr);
5557703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    if (Result.isInvalid())
5558f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
55594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5560703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson    ExprsChanged |= Result.get() != InputExpr;
55614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
55629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Exprs.push_back(Result.get());
5563703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  }
55644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5565703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  if (!getDerived().AlwaysRebuild() && !ExprsChanged)
55663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
5567703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5568703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // Go through the clobbers.
5569703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
55705c7f59445ae68109c7ffee731aca2ce32db587c7Chad Rosier    Clobbers.push_back(S->getClobberStringLiteral(I));
5571703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson
5572703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  // No need to transform the asm string literal.
5573703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson  AsmString = SemaRef.Owned(S->getAsmString());
5574df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier  return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5575df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                                        S->isVolatile(), S->getNumOutputs(),
5576df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                                        S->getNumInputs(), Names.data(),
5577df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                                        Constraints, Exprs, AsmString.get(),
5578df5faf5e7ae6823d0af0b801c4ac26d47f2cee97Chad Rosier                                        Clobbers, S->getRParenLoc());
557943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
558043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
55818cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosiertemplate<typename Derived>
55828cd64b4c5553fa6284d248336cb7c82dc960a394Chad RosierStmtResult
55838cd64b4c5553fa6284d248336cb7c82dc960a394Chad RosierTreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
558479efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier  ArrayRef<Token> AsmToks =
558579efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier    llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
558662f22b87801882646418bae85111e565f7a53ddbChad Rosier
55877bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier  return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
55887bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier                                       AsmToks, S->getEndLoc());
55898cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier}
559043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
559143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
559260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
55931eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
55944dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body of the @try.
559560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
55964dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (TryBody.isInvalid())
5597f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
55984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
55998f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  // Transform the @catch statements (if present).
56008f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  bool AnyCatchChanged = false;
56014e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Stmt*, 8> CatchStmts;
56028f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor  for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
560360d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
56044dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Catch.isInvalid())
5605f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
56068f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    if (Catch.get() != S->getCatchStmt(I))
56078f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      AnyCatchChanged = true;
56088f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor    CatchStmts.push_back(Catch.release());
56094dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
56104a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
56114dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the @finally statement (if present).
561260d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Finally;
56134dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (S->getFinallyStmt()) {
56144dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    Finally = getDerived().TransformStmt(S->getFinallyStmt());
56154dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor    if (Finally.isInvalid())
5616f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
56174dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  }
56184dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
56194dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
56204dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
56214dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      TryBody.get() == S->getTryBody() &&
56228f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor      !AnyCatchChanged &&
56234dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Finally.get() == S->getFinallyStmt())
56243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
56254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
56264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
56279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
56283fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                           CatchStmts, Finally.get());
562943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
56301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
563143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
563260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
56331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
5634be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  // Transform the @catch parameter, if there is one.
5635be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  VarDecl *Var = 0;
5636be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (VarDecl *FromVar = S->getCatchParamDecl()) {
5637be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    TypeSourceInfo *TSInfo = 0;
5638be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (FromVar->getTypeSourceInfo()) {
5639be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5640be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (!TSInfo)
5641f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return StmtError();
5642be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
56434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5644be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    QualType T;
5645be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (TSInfo)
5646be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = TSInfo->getType();
5647be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    else {
5648be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      T = getDerived().TransformType(FromVar->getType());
5649be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor      if (T.isNull())
56504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        return StmtError();
5651be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    }
56524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5653be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5654be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor    if (!Var)
5655f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5656be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  }
56574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
565860d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
5659be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor  if (Body.isInvalid())
5660f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
56614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
56624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
5663be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor                                             S->getRParenLoc(),
56649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                             Var, Body.get());
566543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
56661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
566743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
566860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
56691eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
56704dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Transform the body.
567160d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
56724dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (Body.isInvalid())
5673f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
56744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
56754dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // If nothing changed, just retain this statement.
56764dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
56774dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor      Body.get() == S->getFinallyBody())
56783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
56794dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor
56804dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  // Build a new statement.
56814dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor  return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
56829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                               Body.get());
568343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
56841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
568543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
568660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
56871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
568860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand;
5689d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (S->getThrowExpr()) {
5690d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    Operand = getDerived().TransformExpr(S->getThrowExpr());
5691d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor    if (Operand.isInvalid())
5692f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
5693d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  }
56944a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5695d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5696d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor      Operand.get() == S->getThrowExpr())
56973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return getSema().Owned(S);
56984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
56999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
570043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
57011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
570243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
570360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
570443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
57051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCAtSynchronizedStmt *S) {
57068fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the object we are locking.
570760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
57088fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Object.isInvalid())
5709f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
571007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  Object =
571107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
571207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall                                                  Object.get());
571307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall  if (Object.isInvalid())
571407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall    return StmtError();
57154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
57168fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Transform the body.
571760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
57188fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (Body.isInvalid())
5719f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
57204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
57218fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // If nothing change, just retain the current statement.
57228fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
57238fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Object.get() == S->getSynchExpr() &&
57248fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor      Body.get() == S->getSynchBody())
57253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
57268fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor
57278fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  // Build a new statement.
57288fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor  return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
57299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                    Object.get(), Body.get());
573043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
573143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
573243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
573360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
5734f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5735f85e193739c953358c865005855253af4f68a497John McCall                                              ObjCAutoreleasePoolStmt *S) {
5736f85e193739c953358c865005855253af4f68a497John McCall  // Transform the body.
5737f85e193739c953358c865005855253af4f68a497John McCall  StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5738f85e193739c953358c865005855253af4f68a497John McCall  if (Body.isInvalid())
5739f85e193739c953358c865005855253af4f68a497John McCall    return StmtError();
57404a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5741f85e193739c953358c865005855253af4f68a497John McCall  // If nothing changed, just retain this statement.
5742f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
5743f85e193739c953358c865005855253af4f68a497John McCall      Body.get() == S->getSubStmt())
5744f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(S);
5745f85e193739c953358c865005855253af4f68a497John McCall
5746f85e193739c953358c865005855253af4f68a497John McCall  // Build a new statement.
5747f85e193739c953358c865005855253af4f68a497John McCall  return getDerived().RebuildObjCAutoreleasePoolStmt(
5748f85e193739c953358c865005855253af4f68a497John McCall                        S->getAtLoc(), Body.get());
5749f85e193739c953358c865005855253af4f68a497John McCall}
5750f85e193739c953358c865005855253af4f68a497John McCall
5751f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
5752f85e193739c953358c865005855253af4f68a497John McCallStmtResult
575343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt(
57541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                  ObjCForCollectionStmt *S) {
5755c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the element statement.
575660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Element = getDerived().TransformStmt(S->getElement());
5757c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Element.isInvalid())
5758f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
57594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5760c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the collection expression.
576160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Collection = getDerived().TransformExpr(S->getCollection());
5762c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Collection.isInvalid())
5763f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
57644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5765c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Transform the body.
576660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Body = getDerived().TransformStmt(S->getBody());
5767c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (Body.isInvalid())
5768f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
57694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5770c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // If nothing changed, just retain this statement.
5771c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
5772c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Element.get() == S->getElement() &&
5773c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Collection.get() == S->getCollection() &&
5774c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor      Body.get() == S->getBody())
57753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
57764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5777c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  // Build a new statement.
5778c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor  return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
57799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Element.get(),
57809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Collection.get(),
5781c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor                                                   S->getRParenLoc(),
57829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Body.get());
578343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
578443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
578543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
578643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
578760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
578843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
578943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the exception declaration, if any.
579043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  VarDecl *Var = 0;
579143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (S->getExceptionDecl()) {
579243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    VarDecl *ExceptionDecl = S->getExceptionDecl();
579383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    TypeSourceInfo *T = getDerived().TransformType(
579483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor                                            ExceptionDecl->getTypeSourceInfo());
579583cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    if (!T)
5796f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
57971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
579883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor    Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
5799ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getInnerLocStart(),
5800ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getLocation(),
5801ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara                                            ExceptionDecl->getIdentifier());
5802ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor    if (!Var || Var->isInvalidDecl())
5803f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
580443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
58051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
580643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the actual exception handler.
580760d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
5808ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor  if (Handler.isInvalid())
5809f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
58101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
581143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
581243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !Var &&
581343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      Handler.get() == S->getHandlerBlock())
58143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
581543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
581643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
581743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor                                          Var,
58189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                          Handler.get());
581943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
58201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
582143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived>
582260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult
582343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
582443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the try block itself.
582560d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult TryBlock
582643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    = getDerived().TransformCompoundStmt(S->getTryBlock());
582743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (TryBlock.isInvalid())
5828f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return StmtError();
58291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
583043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // Transform the handlers.
583143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  bool HandlerChanged = false;
58324e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Stmt*, 8> Handlers;
583343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
583460d7b3a319d84d688752be3870615ac0f111fb16John McCall    StmtResult Handler
583543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      = getDerived().TransformCXXCatchStmt(S->getHandler(I));
583643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    if (Handler.isInvalid())
5837f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return StmtError();
58381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
583943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
584043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor    Handlers.push_back(Handler.takeAs<Stmt>());
584143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  }
58421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
584343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
584443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      TryBlock.get() == S->getTryBlock() &&
584543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor      !HandlerChanged)
58463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(S);
584743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor
58489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
58493fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                        Handlers);
585043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor}
58511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5852ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived>
5853ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult
5854ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5855ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5856ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Range.isInvalid())
5857ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5858ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5859ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5860ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (BeginEnd.isInvalid())
5861ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5862ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5863ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ExprResult Cond = getDerived().TransformExpr(S->getCond());
5864ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Cond.isInvalid())
5865ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5866c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman  if (Cond.get())
5867c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman    Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5868c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman  if (Cond.isInvalid())
5869c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman    return StmtError();
5870c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman  if (Cond.get())
5871c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman    Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
5872ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5873ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  ExprResult Inc = getDerived().TransformExpr(S->getInc());
5874ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Inc.isInvalid())
5875ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5876c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman  if (Inc.get())
5877c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman    Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
5878ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5879ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5880ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (LoopVar.isInvalid())
5881ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5882ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5883ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult NewStmt = S;
5884ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (getDerived().AlwaysRebuild() ||
5885ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Range.get() != S->getRangeStmt() ||
5886ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      BeginEnd.get() != S->getBeginEndStmt() ||
5887ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Cond.get() != S->getCond() ||
5888ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Inc.get() != S->getInc() ||
5889ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      LoopVar.get() != S->getLoopVarStmt())
5890ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5891ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getColonLoc(), Range.get(),
5892ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  BeginEnd.get(), Cond.get(),
5893ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  Inc.get(), LoopVar.get(),
5894ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getRParenLoc());
5895ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5896ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  StmtResult Body = getDerived().TransformStmt(S->getBody());
5897ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Body.isInvalid())
5898ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return StmtError();
5899ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5900ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // Body has changed but we didn't rebuild the for-range statement. Rebuild
5901ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // it now so we have a new statement to attach the body to.
5902ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (Body.get() != S->getBody() && NewStmt.get() == S)
5903ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5904ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getColonLoc(), Range.get(),
5905ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  BeginEnd.get(), Cond.get(),
5906ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  Inc.get(), LoopVar.get(),
5907ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                                  S->getRParenLoc());
5908ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5909ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  if (NewStmt.get() == S)
5910ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return SemaRef.Owned(S);
5911ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
5912ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5913ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith}
5914ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
591528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
591628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
5917ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorTreeTransform<Derived>::TransformMSDependentExistsStmt(
5918ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                                    MSDependentExistsStmt *S) {
5919ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  // Transform the nested-name-specifier, if any.
5920ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
5921ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  if (S->getQualifierLoc()) {
59224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    QualifierLoc
5923ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5924ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    if (!QualifierLoc)
5925ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor      return StmtError();
5926ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  }
5927ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
5928ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  // Transform the declaration name.
5929ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  DeclarationNameInfo NameInfo = S->getNameInfo();
5930ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  if (NameInfo.getName()) {
5931ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5932ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    if (!NameInfo.getName())
5933ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor      return StmtError();
5934ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  }
5935ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
5936ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  // Check whether anything changed.
5937ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
5938ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor      QualifierLoc == S->getQualifierLoc() &&
5939ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor      NameInfo.getName() == S->getNameInfo().getName())
5940ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    return S;
59414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5942ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  // Determine whether this name exists, if we can.
5943ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  CXXScopeSpec SS;
5944ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  SS.Adopt(QualifierLoc);
5945ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  bool Dependent = false;
5946ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5947ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  case Sema::IER_Exists:
5948ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    if (S->isIfExists())
5949ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor      break;
59504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5951ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    return new (getSema().Context) NullStmt(S->getKeywordLoc());
5952ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
5953ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  case Sema::IER_DoesNotExist:
5954ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    if (S->isIfNotExists())
5955ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor      break;
59564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5957ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    return new (getSema().Context) NullStmt(S->getKeywordLoc());
59584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5959ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  case Sema::IER_Dependent:
5960ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    Dependent = true;
5961ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    break;
59624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
596365019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor  case Sema::IER_Error:
596465019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor    return StmtError();
5965ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  }
59664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5967ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  // We need to continue with the instantiation, so do so now.
5968ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5969ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  if (SubStmt.isInvalid())
5970ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    return StmtError();
59714a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5972ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  // If we have resolved the name, just transform to the substatement.
5973ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  if (!Dependent)
5974ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    return SubStmt;
59754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
5976ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  // The name is still dependent, so build a dependent expression again.
5977ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5978ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                                   S->isIfExists(),
5979ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                                   QualifierLoc,
5980ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                                   NameInfo,
5981ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                                                   SubStmt.get());
5982ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor}
5983ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
5984ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregortemplate<typename Derived>
5985ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorStmtResult
598628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
598728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult TryBlock; //  = getDerived().TransformCompoundStmt(S->getTryBlock());
598828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(TryBlock.isInvalid()) return StmtError();
598928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
599028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
599128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(!getDerived().AlwaysRebuild() &&
599228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley     TryBlock.get() == S->getTryBlock() &&
599328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley     Handler.get() == S->getHandler())
599428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return SemaRef.Owned(S);
599528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
599628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
599728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        S->getTryLoc(),
599828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        TryBlock.take(),
599928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                        Handler.take());
600028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
600128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
600228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
600328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
600428bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
600528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
600628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(Block.isInvalid()) return StmtError();
600728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
600828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
600928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                            Block.take());
601028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
601128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
601228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
601328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
601428bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
601528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
601628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(FilterExpr.isInvalid()) return StmtError();
601728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
601828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  StmtResult Block; //  = getDerived().TransformCompoundStatement(S->getBlock());
601928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(Block.isInvalid()) return StmtError();
602028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
602128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
602228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                           FilterExpr.take(),
602328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley                                           Block.take());
602428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
602528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
602628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived>
602728bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult
602828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
602928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  if(isa<SEHFinallyStmt>(Handler))
603028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
603128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  else
603228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
603328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
603428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
603543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===//
6036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation
6037577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===//
60381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
603960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6040454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
60413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
60421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
60431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
604560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6046454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
604740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
604840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  if (E->getQualifierLoc()) {
604940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    QualifierLoc
605040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
605140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!QualifierLoc)
6052f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6053a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
6054dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
6055dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *ND
60567c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
60577c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getDecl()));
6058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!ND)
6059f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
60601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6061ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  DeclarationNameInfo NameInfo = E->getNameInfo();
6062ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  if (NameInfo.getName()) {
6063ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6064ec8045d3f0375302eadaa63deb373bacaf25a569John McCall    if (!NameInfo.getName())
6065f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6066ec8045d3f0375302eadaa63deb373bacaf25a569John McCall  }
60672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
60682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!getDerived().AlwaysRebuild() &&
606940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      QualifierLoc == E->getQualifierLoc() &&
6070a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ND == E->getDecl() &&
60712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      NameInfo.getName() == E->getDecl()->getDeclName() &&
6072096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
60731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6074dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // Mark it referenced in the new context regardless.
6075dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    // FIXME: this is a bit instantiation-specific.
60765f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman    SemaRef.MarkDeclRefReferenced(E);
6077a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
60783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
6079a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
6080dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
6081dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
6082096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
6083dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TemplateArgs = &TransArgs;
6084dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
6085dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
6086fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6087fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
6088fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
6089fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
6090dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
6091dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
60924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
609340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                                         TemplateArgs);
6094577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
60951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6096b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
609760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6098454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
60993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6100577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
61011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
610360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6104454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
61053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6106b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
610960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6110454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
61113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
611560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6116454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
61173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6118b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
612160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6122454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
61233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
612760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
61289fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithTreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
61299fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  return SemaRef.MaybeBindToTemporary(E);
61309fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith}
61319fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
61329fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithtemplate<typename Derived>
61339fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithExprResult
6134f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6135f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  ExprResult ControllingExpr =
6136f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    getDerived().TransformExpr(E->getControllingExpr());
6137f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  if (ControllingExpr.isInvalid())
6138f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return ExprError();
6139f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
6140686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Expr *, 4> AssocExprs;
6141686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<TypeSourceInfo *, 4> AssocTypes;
6142f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6143f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6144f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (TS) {
6145f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6146f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      if (!AssocType)
6147f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne        return ExprError();
6148f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      AssocTypes.push_back(AssocType);
6149f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    } else {
6150f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      AssocTypes.push_back(0);
6151f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    }
6152f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
6153f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6154f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (AssocExpr.isInvalid())
6155f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      return ExprError();
6156f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    AssocExprs.push_back(AssocExpr.release());
6157f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
6158f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
6159f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6160f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getDefaultLoc(),
6161f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getRParenLoc(),
6162f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  ControllingExpr.release(),
6163f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  AssocTypes.data(),
6164f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  AssocExprs.data(),
6165f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                                                  E->getNumAssocs());
6166f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}
6167f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
6168f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived>
6169f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult
6170454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
617160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6173f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
61763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
6179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       E->getRParen());
6180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
61821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
618360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6184454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
618560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6187f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
61881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
61903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
61911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6193b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getOpcode(),
61949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get());
6195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
61961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
619860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
61998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
62008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform the type.
62018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
62028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!Type)
6203f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
62044a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
62058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Transform all of the components into components similar to what the
62068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // parser uses.
62074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  // FIXME: It would be slightly more efficient in the non-dependent case to
62084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  // just map FieldDecls, rather than requiring the rebuilder to look for
62094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  // the fields again. However, __builtin_offsetof is rare enough in
62108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // template code that we don't care.
62118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool ExprChanged = false;
6212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall  typedef Sema::OffsetOfComponent Component;
62138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef OffsetOfExpr::OffsetOfNode Node;
6214686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Component, 4> Components;
62158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
62168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const Node &ON = E->getComponent(I);
62178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Component Comp;
621872be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor    Comp.isBrackets = true;
621906dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara    Comp.LocStart = ON.getSourceRange().getBegin();
622006dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara    Comp.LocEnd = ON.getSourceRange().getEnd();
62218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    switch (ON.getKind()) {
62228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Array: {
62238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
622460d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(FromIndex);
62258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (Index.isInvalid())
6226f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
62274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
62288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      ExprChanged = ExprChanged || Index.get() != FromIndex;
62298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = true;
62309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      Comp.U.E = Index.get();
62318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
62328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
62334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
62348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Field:
62358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    case Node::Identifier:
62368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.isBrackets = false;
62378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Comp.U.IdentInfo = ON.getFieldName();
623829d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor      if (!Comp.U.IdentInfo)
623929d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor        continue;
62404a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
62418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      break;
62424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
6243cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    case Node::Base:
6244cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      // Will be recomputed during the rebuild.
6245cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      continue;
62468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
62474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
62488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Components.push_back(Comp);
62498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
62504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
62518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // If nothing changed, retain the existing expression.
62528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
62538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Type == E->getTypeSourceInfo() &&
62548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      !ExprChanged)
62553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
62564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
62578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Build a new offsetof expression.
62588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
62598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          Components.data(), Components.size(),
62608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                          E->getRParenLoc());
62617cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}
62627cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
62637cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived>
62647cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult
62657cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
62667cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  assert(getDerived().AlreadyTransformed(E->getType()) &&
62677cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall         "opaque value expression requires transformation");
62687cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  return SemaRef.Owned(E);
62698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
62708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
62718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived>
627260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
62734b9c2d235fb9449e249d74f48ecfec601650de93John McCallTreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
627401e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall  // Rebuild the syntactic form.  The original syntactic form has
627501e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall  // opaque-value expressions in it, so strip those away and rebuild
627601e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall  // the result.  This is a really awful way of doing this, but the
627701e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall  // better solution (rebuilding the semantic expressions and
627801e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall  // rebinding OVEs as necessary) doesn't work; we'd need
627901e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall  // TreeTransform to not strip away implicit conversions.
628001e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall  Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
628101e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall  ExprResult result = getDerived().TransformExpr(newSyntacticForm);
62824b9c2d235fb9449e249d74f48ecfec601650de93John McCall  if (result.isInvalid()) return ExprError();
62834b9c2d235fb9449e249d74f48ecfec601650de93John McCall
62844b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // If that gives us a pseudo-object result back, the pseudo-object
62854b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // expression must have been an lvalue-to-rvalue conversion which we
62864b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // should reapply.
62874b9c2d235fb9449e249d74f48ecfec601650de93John McCall  if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
62884b9c2d235fb9449e249d74f48ecfec601650de93John McCall    result = SemaRef.checkPseudoObjectRValue(result.take());
62894b9c2d235fb9449e249d74f48ecfec601650de93John McCall
62904b9c2d235fb9449e249d74f48ecfec601650de93John McCall  return result;
62914b9c2d235fb9449e249d74f48ecfec601650de93John McCall}
62924b9c2d235fb9449e249d74f48ecfec601650de93John McCall
62934b9c2d235fb9449e249d74f48ecfec601650de93John McCalltemplate<typename Derived>
62944b9c2d235fb9449e249d74f48ecfec601650de93John McCallExprResult
6295f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6296f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                UnaryExprOrTypeTraitExpr *E) {
6297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isArgumentType()) {
6298a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *OldT = E->getArgumentTypeInfo();
62995557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor
6300a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *NewT = getDerived().TransformType(OldT);
63015ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!NewT)
6302f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
63031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63045ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    if (!getDerived().AlwaysRebuild() && OldT == NewT)
63053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
63061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6307f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6308f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                    E->getKind(),
6309f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                    E->getSourceRange());
6310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
63111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
631272b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  // C++0x [expr.sizeof]p1:
631372b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  //   The operand is either an expression, which is an unevaluated operand
631472b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  //   [...]
631572b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
63161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
631772b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
631872b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  if (SubExpr.isInvalid())
631972b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman    return ExprError();
63201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
632172b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
632272b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman    return SemaRef.Owned(E);
63231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6324f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6325f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getOperatorLoc(),
6326f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getKind(),
6327f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                                                  E->getSourceRange());
6328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
633160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6332454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
633360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6335f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
633760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6339f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
63453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
63461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildArraySubscriptExpr(LHS.get(),
6348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           /*FIXME:*/E->getLHS()->getLocStart(),
63499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                RHS.get(),
6350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getRBracketLoc());
6351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
635460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6355454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
6356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the callee.
635760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
6359f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform arguments.
6362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgChanged = false;
63634e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Args;
63644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6365aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
6366aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
63674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
6368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
6370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgChanged)
63711ad23d62007162df82b58bca31b4aa277a5f6586Dmitri Gribenko    return SemaRef.MaybeBindToTemporary(E);
63721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Wrong source location information for the '('.
63741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLParenLoc
6375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = ((Expr *)Callee.get())->getSourceRange().getBegin();
63769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
63773fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                      Args,
6378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
6379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
63801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
638260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6383454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
638460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
6386f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
63871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
638840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
638983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (E->hasQualifier()) {
639040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    QualifierLoc
639140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
63924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
639340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!QualifierLoc)
6394f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
639583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
6396e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
63971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6398f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *Member
63997c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
64007c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getMemberDecl()));
6401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Member)
6402f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
64031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64046bb8017bb9e828d118e15e59d71c66bba323c364John McCall  NamedDecl *FoundDecl = E->getFoundDecl();
64056bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (FoundDecl == E->getMemberDecl()) {
64066bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = Member;
64076bb8017bb9e828d118e15e59d71c66bba323c364John McCall  } else {
64086bb8017bb9e828d118e15e59d71c66bba323c364John McCall    FoundDecl = cast_or_null<NamedDecl>(
64096bb8017bb9e828d118e15e59d71c66bba323c364John McCall                   getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
64106bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!FoundDecl)
6411f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
64126bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
64136bb8017bb9e828d118e15e59d71c66bba323c364John McCall
6414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase() &&
641640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      QualifierLoc == E->getQualifierLoc() &&
64178a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor      Member == E->getMemberDecl() &&
64186bb8017bb9e828d118e15e59d71c66bba323c364John McCall      FoundDecl == E->getFoundDecl() &&
6419096832c5ed5b9106fa177ebc148489760c3bc496John McCall      !E->hasExplicitTemplateArgs()) {
64204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
64211f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // Mark it referenced in the new context regardless.
64221f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson    // FIXME: this is a bit instantiation-specific.
64235f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman    SemaRef.MarkMemberReferenced(E);
64245f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman
64253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64261f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson  }
6427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6428d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs;
6429096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (E->hasExplicitTemplateArgs()) {
6430d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setLAngleLoc(E->getLAngleLoc());
6431d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    TransArgs.setRAngleLoc(E->getRAngleLoc());
6432fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6433fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                E->getNumTemplateArgs(),
6434fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
6435fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
64368a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor  }
64374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
6438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bogus source location for the operator
6439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeOperatorLoc
6440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6442c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
6443c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
6444c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
6445c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
6446c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
6447c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
64489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
6449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isArrow(),
645040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                                        QualifierLoc,
6451e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                        TemplateKWLoc,
64522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                        E->getMemberNameInfo(),
64538a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor                                        Member,
64546bb8017bb9e828d118e15e59d71c66bba323c364John McCall                                        FoundDecl,
6455096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                        (E->hasExplicitTemplateArgs()
6456d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                           ? &TransArgs : 0),
6457c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                        FirstQualifierInScope);
6458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
646160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6462454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
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      LHS.get() == E->getLHS() &&
6473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
64743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
64751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6476b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
64779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            LHS.get(), RHS.get());
6478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6479b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
64801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
648160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator(
6483454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CompoundAssignOperator *E) {
6484454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformBinaryOperator(E);
6485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
64861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
648856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>::
648956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
649056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // Just rebuild the common and RHS expressions and see whether we
649156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // get any changes.
649256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
649356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
649456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (commonExpr.isInvalid())
649556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
649656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
649756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
649856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (rhs.isInvalid())
649956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return ExprError();
650056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
650156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (!getDerived().AlwaysRebuild() &&
650256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      commonExpr.get() == e->getCommon() &&
650356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      rhs.get() == e->getFalseExpr())
650456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return SemaRef.Owned(e);
650556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
650656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  return getDerived().RebuildConditionalOperator(commonExpr.take(),
650756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getQuestionLoc(),
650856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 0,
650956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 e->getColonLoc(),
651056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                                 rhs.get());
651156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}
651256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
651356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived>
651460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6515454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
651660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
6517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
6518f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
652060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6522f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
652460d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6526f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
6530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
65323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
65331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
65349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildConditionalOperator(Cond.get(),
653547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getQuestionLoc(),
65369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 LHS.get(),
653747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                                                 E->getColonLoc(),
65389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 RHS.get());
6539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
65411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
654260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6543454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
6544a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // Implicit casts are eliminated during transformation, since they
6545a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  // will be recomputed by semantic analysis after transformation.
65466eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return getDerived().TransformExpr(E->getSubExprAsWritten());
6547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
655060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6551454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
6552ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6553ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6554ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
65554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
655660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
65576eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6559f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6562ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
65643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
65651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
65669d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
6567ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                            Type,
6568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc(),
65699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                            SubExpr.get());
6570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
657360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6574454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
657542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *OldT = E->getTypeSourceInfo();
657642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *NewT = getDerived().TransformType(OldT);
657742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  if (!NewT)
6578f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
658060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInitializer());
6581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
6582f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
65831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
658542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      OldT == NewT &&
6586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInitializer())
658792be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor    return SemaRef.MaybeBindToTemporary(E);
6588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
65891d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // Note: the expression type doesn't necessarily match the
65901d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // type-as-written, but that's okay, because it should always be
65911d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  // derivable from the initializer.
65921d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
659342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
6594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                   /*FIXME:*/E->getInitializer()->getLocEnd(),
65959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Init.get());
6596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
65971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
659960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6600454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
660160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
6602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Base.isInvalid())
6603f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Base.get() == E->getBase())
66073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Bad source location
66101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeOperatorLoc
6611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
66129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
6613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessorLoc(),
6614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  E->getAccessor());
6615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
661860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6619454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
6620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool InitChanged = false;
66211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66224e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 4> Inits;
66234a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6624aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  Inits, &InitChanged))
6625aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
66264a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
6627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() && !InitChanged)
66283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66303fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer  return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
6631e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor                                      E->getRBraceLoc(), E->getType());
6632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
66331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
663560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6636454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
6637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Designation Desig;
66381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
663943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the initializer value
664060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Init = getDerived().TransformExpr(E->getInit());
6641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Init.isInvalid())
6642f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
66431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
664443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor  // transform the designators.
66454e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 4> ArrayExprs;
6646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ExprChanged = false;
6647b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             DEnd = E->designators_end();
6649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor       D != DEnd; ++D) {
6650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isFieldDesignator()) {
6651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Desig.AddDesignator(Designator::getField(D->getFieldName(),
6652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getDotLoc(),
6653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getFieldLoc()));
6654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
6655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
66561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (D->isArrayDesignator()) {
665860d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
6659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Index.isInvalid())
6660f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
66611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Desig.AddDesignator(Designator::getArray(Index.get(),
6663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               D->getLBracketLoc()));
66641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArrayExprs.push_back(Index.release());
6667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      continue;
6668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
66691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    assert(D->isArrayRangeDesignator() && "New kind of designator?");
667160d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Start
6672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Start.isInvalid())
6674f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
66751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
667660d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
6677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (End.isInvalid())
6678f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
66791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Desig.AddDesignator(Designator::getArrayRange(Start.get(),
6681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  End.get(),
6682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getLBracketLoc(),
6683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                  D->getEllipsisLoc()));
66841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      End.get() != E->getArrayRangeEnd(*D);
66871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(Start.release());
6689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    ArrayExprs.push_back(End.release());
6690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
66911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Init.get() == E->getInit() &&
6694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ExprChanged)
66953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
66961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66973fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer  return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
6698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                E->getEqualOrColonLoc(),
66999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                E->usesGNUSyntax(), Init.get());
6700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
670360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr(
6705454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     ImplicitValueInitExpr *E) {
67065557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
67074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
67085557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // FIXME: Will we ever have proper type location here? Will we actually
67095557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor  // need to transform the type?
6710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
6711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
6712f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType())
67163fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildImplicitValueInitExpr(T);
6719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
672260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6723454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
67249bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
67259bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor  if (!TInfo)
6726f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
672860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
6729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6730f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
67332cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      TInfo == E->getWrittenTypeInfo() &&
6734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
67353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
67361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
67382cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                                       TInfo, E->getRParenLoc());
6739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
674260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6743454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
6744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
67454e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 4> Inits;
6746aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6747aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
6748aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
67494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
6750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildParenListExpr(E->getLParenLoc(),
67513fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                           Inits,
6752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getRParenLoc());
6753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression.
6756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
6757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always
6758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to
6759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis.
6760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
676160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6762454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
676357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
676457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                        E->getLabel());
676557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner  if (!LD)
676657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner    return ExprError();
67674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
6768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
676957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner                                           cast<LabelDecl>(LD));
6770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
67734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad RosierExprResult
6774454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
67757f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall  SemaRef.ActOnStartStmtExpr();
677660d7b3a319d84d688752be3870615ac0f111fb16John McCall  StmtResult SubStmt
6777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
67787f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall  if (SubStmt.isInvalid()) {
67797f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall    SemaRef.ActOnStmtExprError();
6780f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
67817f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall  }
67821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
67847f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall      SubStmt.get() == E->getSubStmt()) {
67857f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall    // Calling this an 'error' is unintuitive, but it does the right thing.
67867f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall    SemaRef.ActOnStmtExprError();
678792be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor    return SemaRef.MaybeBindToTemporary(E);
67887f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall  }
67891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildStmtExpr(E->getLParenLoc(),
67919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                      SubStmt.get(),
6792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      E->getRParenLoc());
6793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
67941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
679660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6797454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
679860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Cond = getDerived().TransformExpr(E->getCond());
6799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Cond.isInvalid())
6800f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
680260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult LHS = getDerived().TransformExpr(E->getLHS());
6803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (LHS.isInvalid())
6804f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
680660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult RHS = getDerived().TransformExpr(E->getRHS());
6807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (RHS.isInvalid())
6808f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Cond.get() == E->getCond() &&
6812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      LHS.get() == E->getLHS() &&
6813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      RHS.get() == E->getRHS())
68143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
68151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
68179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        Cond.get(), LHS.get(), RHS.get(),
6818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->getRParenLoc());
6819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
68201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
682260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6823454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
68243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
6825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
6826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
6827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
682860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6829454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
6830668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  switch (E->getOperator()) {
6831668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_New:
6832668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Delete:
6833668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_New:
6834668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Array_Delete:
6835668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
68364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
6837668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Call: {
6838668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // This is a call to an object's operator().
6839668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6840668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6841668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the object itself.
684260d7b3a319d84d688752be3870615ac0f111fb16John McCall    ExprResult Object = getDerived().TransformExpr(E->getArg(0));
6843668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    if (Object.isInvalid())
6844f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6845668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6846668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // FIXME: Poor location information
6847668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    SourceLocation FakeLParenLoc
6848668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor      = SemaRef.PP.getLocForEndOfToken(
6849668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                              static_cast<Expr *>(Object.get())->getLocEnd());
6850668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6851668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Transform the call arguments.
68524e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer    SmallVector<Expr*, 8> Args;
68534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6854aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                    Args))
6855aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor      return ExprError();
6856668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
68579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
68583fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                        Args,
6859668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor                                        E->getLocEnd());
6860668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
6861668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6862668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6863668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_##Name:
6864668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6865668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def"
6866668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Subscript:
6867668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    // Handled below.
6868668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    break;
6869668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6870668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_Conditional:
6871668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("conditional operator is not actually overloadable");
6872668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
6873668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case OO_None:
6874668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  case NUM_OVERLOADED_OPERATORS:
6875668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor    llvm_unreachable("not an overloaded operator?");
6876668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor  }
6877668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor
687860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6879b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Callee.isInvalid())
6880f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
68811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
688260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult First = getDerived().TransformExpr(E->getArg(0));
6883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (First.isInvalid())
6884f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
6885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
688660d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Second;
6887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->getNumArgs() == 2) {
6888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    Second = getDerived().TransformExpr(E->getArg(1));
6889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (Second.isInvalid())
6890f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
6891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
68921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Callee.get() == E->getCallee() &&
6895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      First.get() == E->getArg(0) &&
68961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
689792be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor    return SemaRef.MaybeBindToTemporary(E);
68981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6900b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                 E->getOperatorLoc(),
69019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Callee.get(),
69029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 First.get(),
69039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Second.get());
6904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
690760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6908454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6909454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCallExpr(E);
6910b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6912b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
6913e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult
6914e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6915e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform the callee.
6916e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6917e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (Callee.isInvalid())
6918e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6919e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6920e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform exec config.
6921e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6922e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (EC.isInvalid())
6923e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6924e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6925e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // Transform arguments.
6926e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  bool ArgChanged = false;
69274e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Args;
69284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6929e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                  &ArgChanged))
6930e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return ExprError();
6931e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6932e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  if (!getDerived().AlwaysRebuild() &&
6933e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      Callee.get() == E->getCallee() &&
6934e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne      !ArgChanged)
693592be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor    return SemaRef.MaybeBindToTemporary(E);
6936e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6937e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  // FIXME: Wrong source location information for the '('.
6938e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  SourceLocation FakeLParenLoc
6939e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    = ((Expr *)Callee.get())->getSourceRange().getBegin();
6940e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
69413fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                      Args,
6942e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                                      E->getRParenLoc(), EC.get());
6943e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}
6944e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
6945e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived>
694660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6947454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
6948ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6949ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
6950ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
69514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
695260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
69536eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
6954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
6955f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
69561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
6958ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
6959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
69603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
69611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: Poor source location information here.
69631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation FakeLAngleLoc
6964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  SourceLocation FakeRParenLoc
6967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.PP.getLocForEndOfToken(
6968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  E->getSubExpr()->getSourceRange().getEnd());
6969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
69701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                              E->getStmtClass(),
6971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeLAngleLoc,
6972ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor                                              Type,
6973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
6974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRAngleLoc,
69759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                              SubExpr.get(),
6976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                              FakeRParenLoc);
6977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
698060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6981454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6982454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
698660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6987454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6988454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6989b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6991b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
699260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
6993b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr(
6994454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                      CXXReinterpretCastExpr *E) {
6995454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
6996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
69971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
699960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7000454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7001454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall  return getDerived().TransformCXXNamedCastExpr(E);
7002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
70031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
700560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7006b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr(
7007454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXFunctionalCastExpr *E) {
7008ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7009ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  if (!Type)
7010ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor    return ExprError();
70111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
701260d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr
70136eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    = getDerived().TransformExpr(E->getSubExprAsWritten());
7014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
7015f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
70161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7017b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7018ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor      Type == E->getTypeInfoAsWritten() &&
7019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
70203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
70211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7022ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  return getDerived().RebuildCXXFunctionalCastExpr(Type,
7023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                      /*FIXME:*/E->getSubExpr()->getLocStart(),
70249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   SubExpr.get(),
7025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   E->getRParenLoc());
7026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
70271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
702960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7030454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
7031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (E->isTypeOperand()) {
703257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    TypeSourceInfo *TInfo
703357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      = getDerived().TransformType(E->getTypeOperandSourceInfo());
703457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    if (!TInfo)
7035f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
70361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
703857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        TInfo == E->getTypeOperandSourceInfo())
70393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
70401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
704157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return getDerived().RebuildCXXTypeidExpr(E->getType(),
704257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             E->getLocStart(),
704357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                             TInfo,
7044b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                             E->getLocEnd());
7045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
70461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7047ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman  // We don't know whether the subexpression is potentially evaluated until
7048ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman  // after we perform semantic analysis.  We speculatively assume it is
7049ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman  // unevaluated; it will get fixed later if the subexpression is in fact
7050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // potentially evaluated.
7051ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
70521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
705360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7054b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
7055f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
70561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7057b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getExprOperand())
70593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
70601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
706157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  return getDerived().RebuildCXXTypeidExpr(E->getType(),
706257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor                                           E->getLocStart(),
70639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           SubExpr.get(),
7064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->getLocEnd());
7065b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
706860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
706901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
707001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (E->isTypeOperand()) {
707101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    TypeSourceInfo *TInfo
707201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      = getDerived().TransformType(E->getTypeOperandSourceInfo());
707301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!TInfo)
707401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      return ExprError();
707501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
707601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (!getDerived().AlwaysRebuild() &&
707701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet        TInfo == E->getTypeOperandSourceInfo())
70783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
707901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
70803c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor    return getDerived().RebuildCXXUuidofExpr(E->getType(),
708101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocStart(),
708201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             TInfo,
708301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                             E->getLocEnd());
708401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
708501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
708601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
708701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
708801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
708901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (SubExpr.isInvalid())
709001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return ExprError();
709101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
709201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  if (!getDerived().AlwaysRebuild() &&
709301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      SubExpr.get() == E->getExprOperand())
70943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
709501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
709601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  return getDerived().RebuildCXXUuidofExpr(E->getType(),
709701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocStart(),
709801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           SubExpr.get(),
709901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet                                           E->getLocEnd());
710001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}
710101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
710201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived>
710301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult
7104454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
71053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7106b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
710960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
7111454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXNullPtrLiteralExpr *E) {
71123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
7113b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7115b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
711660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7117454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
7118ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor  DeclContext *DC = getSema().getFunctionLevelDeclContext();
71197a614d8380297fcd2bc23986241905d97222948cRichard Smith  QualType T;
71207a614d8380297fcd2bc23986241905d97222948cRichard Smith  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
71217a614d8380297fcd2bc23986241905d97222948cRichard Smith    T = MD->getThisType(getSema().Context);
71227a614d8380297fcd2bc23986241905d97222948cRichard Smith  else
71237a614d8380297fcd2bc23986241905d97222948cRichard Smith    T = getSema().Context.getPointerType(
71247a614d8380297fcd2bc23986241905d97222948cRichard Smith      getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
71251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7126ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor  if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7127ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor    // Make sure that we capture 'this'.
7128ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor    getSema().CheckCXXThisCapture(E->getLocStart());
71293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7130ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor  }
71314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7132828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
7133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
713660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7137454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
713860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
7139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (SubExpr.isInvalid())
7140f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
71411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      SubExpr.get() == E->getSubExpr())
71443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7146bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7147bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor                                          E->isThrownVariableInScope());
7148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
715160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7152454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
71531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParmVarDecl *Param
71547c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
71557c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           E->getParam()));
7156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Param)
7157f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
71581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
715953cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth  if (!getDerived().AlwaysRebuild() &&
7160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Param == E->getParam())
71613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
71621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7163036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
7164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
716760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7168ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7169ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXScalarValueInitExpr *E) {
7170ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7171ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
7172f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
71734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7175ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo())
71763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
71771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  return getDerived().RebuildCXXScalarValueInitExpr(T,
7179ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
7180ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor                                                    E->getRParenLoc());
7181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
71821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
718460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7185454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
7186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the type that we're allocating
71871bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocTypeInfo
71881bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
71891bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  if (!AllocTypeInfo)
7190f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
71911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the size of the array we're allocating (if any).
719360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
7194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (ArraySize.isInvalid())
7195f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
71961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the placement arguments (if any).
7198b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
71994e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> PlacementArgs;
72004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->getPlacementArgs(),
7201aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  E->getNumPlacementArgs(), true,
7202aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  PlacementArgs, &ArgumentChanged))
72032aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return ExprError();
72042aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
72052aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  // Transform the initializer (if any).
72062aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  Expr *OldInit = E->getInitializer();
72072aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  ExprResult NewInit;
72082aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  if (OldInit)
72092aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    NewInit = getDerived().TransformExpr(OldInit);
72102aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  if (NewInit.isInvalid())
72112aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return ExprError();
72121af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
72132aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  // Transform new operator and delete operator.
72141af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorNew = 0;
72151af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorNew()) {
72161af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorNew = cast_or_null<FunctionDecl>(
72177c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(E->getLocStart(),
72187c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getOperatorNew()));
72191af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorNew)
7220f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
72211af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
72221af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor
72231af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
72241af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
72251af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
72267c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
72277c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
72281af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
7229f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
72301af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
72314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
72331bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor      AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
7234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      ArraySize.get() == E->getArraySize() &&
72352aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl      NewInit.get() == OldInit &&
72361af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorNew == E->getOperatorNew() &&
72371af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete() &&
72381af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      !ArgumentChanged) {
72391af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
72401af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
72411af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorNew)
72425f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman      SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
72431af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
72445f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman      SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
72454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
72462aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
72472ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor      QualType ElementType
72482ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        = SemaRef.Context.getBaseElementType(E->getAllocatedType());
72492ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor      if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
72502ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
72512ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
72525f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman          SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
72532ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor        }
72542ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor      }
72552ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor    }
72562aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
72573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
72581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
72591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72601bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  QualType AllocType = AllocTypeInfo->getType();
72615b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  if (!ArraySize.get()) {
72625b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // If no array size was specified, but the new expression was
72635b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with an array type (e.g., "new T" where T is
72645b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // instantiated with "int[4]"), extract the outer bound from the
72655b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // array type as our array size. We do this with constant and
72665b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    // dependently-sized array types.
72675b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
72685b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    if (!ArrayT) {
72695b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      // Do nothing
72705b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const ConstantArrayType *ConsArrayT
72715b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                                     = dyn_cast<ConstantArrayType>(ArrayT)) {
72724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      ArraySize
72739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
72744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                               ConsArrayT->getSize(),
72759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               SemaRef.Context.getSizeType(),
72769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                               /*FIXME:*/E->getLocStart()));
72775b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      AllocType = ConsArrayT->getElementType();
72785b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    } else if (const DependentSizedArrayType *DepArrayT
72795b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor                              = dyn_cast<DependentSizedArrayType>(ArrayT)) {
72805b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      if (DepArrayT->getSizeExpr()) {
72813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall        ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
72825b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor        AllocType = DepArrayT->getElementType();
72835b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor      }
72845b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor    }
72855b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor  }
72862aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
7287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        E->isGlobalNew(),
7289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
72903fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                        PlacementArgs,
7291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        /*FIXME:*/E->getLocStart(),
72924bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor                                        E->getTypeIdParens(),
7293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                        AllocType,
72941bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor                                        AllocTypeInfo,
72959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                        ArraySize.get(),
72962aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                                        E->getDirectInitRange(),
72972aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                                        NewInit.take());
7298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
72991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
730160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7302454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
730360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Operand = getDerived().TransformExpr(E->getArgument());
7304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Operand.isInvalid())
7305f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73071af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  // Transform the delete operator, if known.
73081af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  FunctionDecl *OperatorDelete = 0;
73091af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  if (E->getOperatorDelete()) {
73101af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    OperatorDelete = cast_or_null<FunctionDecl>(
73117c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                   getDerived().TransformDecl(E->getLocStart(),
73127c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                       E->getOperatorDelete()));
73131af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (!OperatorDelete)
7314f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
73151af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
73164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
73181af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      Operand.get() == E->getArgument() &&
73191af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor      OperatorDelete == E->getOperatorDelete()) {
73201af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark any declarations we need as referenced.
73211af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: instantiation-specific.
73221af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    if (OperatorDelete)
73235f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman      SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
73244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
73255833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    if (!E->getArgument()->isTypeDependent()) {
73265833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      QualType Destroyed = SemaRef.Context.getBaseElementType(
73275833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor                                                         E->getDestroyedType());
73285833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
73295833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
73304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        SemaRef.MarkFunctionReferenced(E->getLocStart(),
73315f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman                                       SemaRef.LookupDestructor(Record));
73325833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor      }
73335833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor    }
73344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
73353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
73361af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor  }
73371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isGlobalDelete(),
7340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                           E->isArrayForm(),
73419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                           Operand.get());
7342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
73431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
734560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7346a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
7347454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                     CXXPseudoDestructorExpr *E) {
734860d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
7349a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  if (Base.isInvalid())
7350f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7352b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  ParsedType ObjectTypePtr;
7353a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  bool MayBePseudoDestructor = false;
73544a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
7355a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              E->getOperatorLoc(),
7356a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        E->isArrow()? tok::arrow : tok::period,
7357a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              ObjectTypePtr,
7358a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              MayBePseudoDestructor);
7359a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (Base.isInvalid())
7360f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
73614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7362b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall  QualType ObjectType = ObjectTypePtr.get();
7363f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7364f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  if (QualifierLoc) {
7365f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    QualifierLoc
7366f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7367f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    if (!QualifierLoc)
736843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      return ExprError();
736943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  }
7370f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  CXXScopeSpec SS;
7371f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  SS.Adopt(QualifierLoc);
73721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7373a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage Destroyed;
7374a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  if (E->getDestroyedTypeInfo()) {
7375a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    TypeSourceInfo *DestroyedTypeInfo
737643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall      = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
7377b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor                                                ObjectType, 0, SS);
7378a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!DestroyedTypeInfo)
7379f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7380a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = DestroyedTypeInfo;
73816b18e740495b67b439fa366367242110365cc4d9Douglas Gregor  } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
7382a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // We aren't likely to be able to resolve the identifier down to a type
7383a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // now anyway, so just retain the identifier.
7384a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7385a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                            E->getDestroyedTypeLoc());
7386a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  } else {
7387a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    // Look for a destructor known with the given name.
7388b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
7389a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                              *E->getDestroyedTypeIdentifier(),
7390a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                E->getDestroyedTypeLoc(),
7391a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                /*Scope=*/0,
7392a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                SS, ObjectTypePtr,
7393a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                false);
7394a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    if (!T)
7395f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
73964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7397a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    Destroyed
7398a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor      = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7399a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                 E->getDestroyedTypeLoc());
7400a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
740126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
740226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *ScopeTypeInfo = 0;
740326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  if (E->getScopeTypeInfo()) {
740443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
740526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    if (!ScopeTypeInfo)
7406f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
7407a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
74084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
74099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
7410a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->getOperatorLoc(),
7411a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                                                     E->isArrow(),
7412f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                                     SS,
741326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     ScopeTypeInfo,
741426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     E->getColonColonLoc(),
7415fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                     E->getTildeLoc(),
7416a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                                     Destroyed);
7417a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}
74181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7419a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived>
742060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7421ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr(
7422454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  UnresolvedLookupExpr *Old) {
7423f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7424f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                 Sema::LookupOrdinaryName);
7425f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7426f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Transform all the decls.
7427f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7428f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall         E = Old->decls_end(); I != E; ++I) {
74297c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
74307c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                 getDerived().TransformDecl(Old->getNameLoc(),
74317c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                            *I));
74329f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
74339f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
74349f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
74359f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
74369f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
74379f54ad4381370c6b771424b53d219e661d6d6706John McCall      else
7438f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
74399f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
7440f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7441f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    // Expand using declarations.
7442f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (isa<UsingDecl>(InstD)) {
7443f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
7444f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7445f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall             E = UD->shadow_end(); I != E; ++I)
7446f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall        R.addDecl(*I);
7447f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      continue;
7448f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    }
7449f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7450f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    R.addDecl(InstD);
7451f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
7452f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7453f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Resolve a kind, but don't do any further analysis.  If it's
7454f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // ambiguous, the callee needs to deal with it.
7455f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  R.resolveKind();
7456f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7457f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Rebuild the nested-name qualifier, if present.
7458f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  CXXScopeSpec SS;
74594c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  if (Old->getQualifierLoc()) {
74604c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    NestedNameSpecifierLoc QualifierLoc
74614c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
74624c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (!QualifierLoc)
7463f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
74644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
74654c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    SS.Adopt(QualifierLoc);
74664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  }
74674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7468c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (Old->getNamingClass()) {
746966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    CXXRecordDecl *NamingClass
747066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
747166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                            Old->getNameLoc(),
747266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
747366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
7474f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
74754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
747666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
7477f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
7478f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7479e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7480e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
74819d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara  // If we have neither explicit template arguments, nor the template keyword,
74829d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara  // it's a normal declaration name.
74839d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara  if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
7484f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7485f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7486f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // If we have template arguments, rebuild them, then rebuild the
7487f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // templateid expression.
7488f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
748902e221bad95aada3190fa6189e38023cba27bc72Rafael Espindola  if (Old->hasExplicitTemplateArgs() &&
749002e221bad95aada3190fa6189e38023cba27bc72Rafael Espindola      getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7491fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              Old->getNumTemplateArgs(),
7492fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7493fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
7494f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
7495e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
74969d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara                                            Old->requiresADL(), &TransArgs);
7497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
74981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
750060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7501454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
75023d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
75033d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  if (!T)
7504f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
75051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
75073d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      T == E->getQueriedTypeSourceInfo())
75083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
75091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
7511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocStart(),
7512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            T,
7513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getLocEnd());
7514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
75151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
751760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
75186ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
75196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
75206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!LhsT)
75216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
75226ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
75236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
75246ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!RhsT)
75256ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return ExprError();
75266ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
75276ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  if (!getDerived().AlwaysRebuild() &&
75286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
75296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SemaRef.Owned(E);
75306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
75316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
75326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocStart(),
75336ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            LhsT, RhsT,
75346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                                            E->getLocEnd());
75356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}
75366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
75376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived>
75386ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult
75394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas GregorTreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
75404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  bool ArgChanged = false;
75414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  llvm::SmallVector<TypeSourceInfo *, 4> Args;
75424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
75434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeSourceInfo *From = E->getArg(I);
75444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeLoc FromTL = From->getTypeLoc();
75454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    if (!isa<PackExpansionTypeLoc>(FromTL)) {
75464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      TypeLocBuilder TLB;
75474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      TLB.reserve(FromTL.getFullDataSize());
75484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      QualType To = getDerived().TransformType(TLB, FromTL);
75494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      if (To.isNull())
75504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor        return ExprError();
75514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
75524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      if (To == From->getType())
75534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor        Args.push_back(From);
75544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      else {
75554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor        Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
75564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor        ArgChanged = true;
75574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      }
75584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      continue;
75594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    }
75604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
75614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    ArgChanged = true;
75624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
75634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    // We have a pack expansion. Instantiate it.
75644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
75654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeLoc PatternTL = ExpansionTL.getPatternLoc();
75664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    SmallVector<UnexpandedParameterPack, 2> Unexpanded;
75674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
75684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
75694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    // Determine whether the set of unexpanded parameter packs can and should
75704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    // be expanded.
75714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    bool Expand = true;
75724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    bool RetainExpansion = false;
75734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    llvm::Optional<unsigned> OrigNumExpansions
75744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      = ExpansionTL.getTypePtr()->getNumExpansions();
75754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
75764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
75774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                             PatternTL.getSourceRange(),
75784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                             Unexpanded,
75794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                             Expand, RetainExpansion,
75804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                             NumExpansions))
75814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      return ExprError();
75824a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
75834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    if (!Expand) {
75844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      // The transform has determined that we should perform a simple
75854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      // transformation on the pack expansion, producing another pack
75864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      // expansion.
75874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
75884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
75894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      TypeLocBuilder TLB;
75904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      TLB.reserve(From->getTypeLoc().getFullDataSize());
75914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
75924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      QualType To = getDerived().TransformType(TLB, PatternTL);
75934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      if (To.isNull())
75944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor        return ExprError();
75954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
75964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      To = getDerived().RebuildPackExpansionType(To,
75974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                                 PatternTL.getSourceRange(),
75984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                                 ExpansionTL.getEllipsisLoc(),
75994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                                 NumExpansions);
76004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      if (To.isNull())
76014ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor        return ExprError();
76024a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
76034ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      PackExpansionTypeLoc ToExpansionTL
76044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor        = TLB.push<PackExpansionTypeLoc>(To);
76054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
76064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
76074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      continue;
76084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    }
76094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
76104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    // Expand the pack expansion by substituting for each argument in the
76114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    // pack(s).
76124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    for (unsigned I = 0; I != *NumExpansions; ++I) {
76134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
76144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      TypeLocBuilder TLB;
76154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      TLB.reserve(PatternTL.getFullDataSize());
76164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      QualType To = getDerived().TransformType(TLB, PatternTL);
76174ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      if (To.isNull())
76184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor        return ExprError();
76194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
76204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
76214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    }
76224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
76234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    if (!RetainExpansion)
76244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      continue;
76254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
76264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    // If we're supposed to retain a pack expansion, do so by temporarily
76274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    // forgetting the partially-substituted parameter pack.
76284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    ForgetPartiallySubstitutedPackRAII Forget(getDerived());
76294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
76304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TypeLocBuilder TLB;
76314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    TLB.reserve(From->getTypeLoc().getFullDataSize());
76324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
76334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    QualType To = getDerived().TransformType(TLB, PatternTL);
76344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    if (To.isNull())
76354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      return ExprError();
76364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
76374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    To = getDerived().RebuildPackExpansionType(To,
76384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                               PatternTL.getSourceRange(),
76394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                               ExpansionTL.getEllipsisLoc(),
76404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                               NumExpansions);
76414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    if (To.isNull())
76424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      return ExprError();
76434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
76444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    PackExpansionTypeLoc ToExpansionTL
76454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor      = TLB.push<PackExpansionTypeLoc>(To);
76464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
76474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
76484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
76494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
76504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  if (!getDerived().AlwaysRebuild() && !ArgChanged)
76514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return SemaRef.Owned(E);
76524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
76534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  return getDerived().RebuildTypeTrait(E->getTrait(),
76544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                       E->getLocStart(),
76554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                       Args,
76564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                                       E->getLocEnd());
76574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor}
76584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
76594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregortemplate<typename Derived>
76604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas GregorExprResult
766121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
766221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
766321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  if (!T)
766421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return ExprError();
766521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
766621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  if (!getDerived().AlwaysRebuild() &&
766721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      T == E->getQueriedTypeSourceInfo())
766821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return SemaRef.Owned(E);
766921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
767021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ExprResult SubExpr;
767121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  {
767221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
767321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
767421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    if (SubExpr.isInvalid())
767521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      return ExprError();
767621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
767721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
767821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      return SemaRef.Owned(E);
767921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
768021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
768121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  return getDerived().RebuildArrayTypeTrait(E->getTrait(),
768221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            E->getLocStart(),
768321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            T,
768421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            SubExpr.get(),
768521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                                            E->getLocEnd());
768621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley}
768721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
768821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived>
768921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult
7690552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7691552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExprResult SubExpr;
7692552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  {
7693552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7694552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7695552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    if (SubExpr.isInvalid())
7696552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      return ExprError();
7697552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7698552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7699552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      return SemaRef.Owned(E);
7700552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
7701552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7702552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  return getDerived().RebuildExpressionTrait(
7703552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7704552622067dc45013d240f73952fece703f5e63bdJohn Wiegley}
7705552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
7706552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived>
7707552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult
7708865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
77092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                               DependentScopeDeclRefExpr *E) {
771000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc
771100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
771200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  if (!QualifierLoc)
7713f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7714e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
77151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
771643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
771743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
771843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
771943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
77202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
77212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
77222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
7723f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
77241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7725f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  if (!E->hasExplicitTemplateArgs()) {
7726f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (!getDerived().AlwaysRebuild() &&
772700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor        QualifierLoc == E->getQualifierLoc() &&
77282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // Note: it is sufficient to compare the Name component of NameInfo:
77292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        // if name has not changed, DNLoc has not changed either.
77302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getDeclName())
77313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
77321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
773300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
7734e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                         TemplateKWLoc,
77352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                         NameInfo,
7736f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                         /*TemplateArgs*/ 0);
7737f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor  }
7738d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
7739d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
7740fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7741fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
7742fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
7743fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
7744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
774500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
7746e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                       TemplateKWLoc,
77472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
7748f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                                       &TransArgs);
7749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
7750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
775260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7753454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
7754321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // CXXConstructExprs are always implicit, so when we have a
7755321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  // 1-argument construction we just transform that argument.
7756321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor  if (E->getNumArgs() == 1 ||
7757321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor      (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7758321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor    return getDerived().TransformExpr(E->getArg(0));
7759321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor
7760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  QualType T = getDerived().TransformType(E->getType());
7763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (T.isNull())
7764f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
7765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
7766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
7767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
77687c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(E->getLocStart(),
77697c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
7770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
7771f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
77721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
77744e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Args;
77754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7776aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
7777aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
77784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      T == E->getType() &&
7781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
7782c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor      !ArgumentChanged) {
77831af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // Mark the constructor as referenced.
77841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor    // FIXME: Instantiation-specific
77855f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman    SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
77863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
7787c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor  }
77881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77894411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor  return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
77904411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor                                              Constructor, E->isElidable(),
77913fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                              Args,
77927cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                              E->hadMultipleCandidates(),
77938c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor                                              E->requiresZeroInitialization(),
7794428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getConstructionKind(),
7795428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                              E->getParenRange());
7796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
77971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression.
7799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
78005132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
78015132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that.
7802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
780360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7804454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
78055132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
7806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
78071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
78084765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should
78094765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated.
7810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor///
78114765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we
78125132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that.
7813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
781460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
78154765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
78165132655e4296b780672e9a96b46a740135073534Douglas Gregor  return getDerived().TransformExpr(E->getSubExpr());
7817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
78181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
782060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
7821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
7822ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                                    CXXTemporaryObjectExpr *E) {
7823ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7824ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
7825f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
78261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  CXXConstructorDecl *Constructor
7828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = cast_or_null<CXXConstructorDecl>(
78294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                  getDerived().TransformDecl(E->getLocStart(),
78307c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                         E->getConstructor()));
7831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!Constructor)
7832f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
78331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
78354e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Args;
7836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  Args.reserve(E->getNumArgs());
78374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7838aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                     &ArgumentChanged))
7839aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
78401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
7842ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
7843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      Constructor == E->getConstructor() &&
784491be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor      !ArgumentChanged) {
784591be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor    // FIXME: Instantiation-specific
78465f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman    SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
78473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.MaybeBindToTemporary(E);
784891be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor  }
78494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7850ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXTemporaryObjectExpr(T,
7851ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                          /*FIXME:*/T->getTypeLoc().getEndLoc(),
78523fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                                    Args,
7853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                    E->getLocEnd());
7854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
78551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
785760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
785801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas GregorTreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
7859dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // Create the local class that will describe the lambda.
7860dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  CXXRecordDecl *Class
7861f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor    = getSema().createLambdaClosureType(E->getIntroducerRange(),
7862f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor                                        /*KnownDependent=*/false);
7863dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
78644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7865dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // Transform the type of the lambda parameters and start the definition of
7866dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // the lambda itself.
7867dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  TypeSourceInfo *MethodTy
78684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    = TransformType(E->getCallOperator()->getTypeSourceInfo());
7869dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  if (!MethodTy)
7870dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    return ExprError();
7871dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
7872c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor  // Transform lambda parameters.
7873c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor  llvm::SmallVector<QualType, 4> ParamTypes;
7874c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor  llvm::SmallVector<ParmVarDecl *, 4> Params;
7875c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor  if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7876c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor        E->getCallOperator()->param_begin(),
7877c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor        E->getCallOperator()->param_size(),
7878c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor        0, ParamTypes, &Params))
7879612409ece080e814f79e06772c690d603f45fbd6Richard Smith    return ExprError();
7880c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor
7881dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // Build the call operator.
7882dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  CXXMethodDecl *CallOperator
7883dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7884adb1d4c18ee83249d4cffc99ef902f98e846092aRichard Smith                                      MethodTy,
7885c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor                                      E->getCallOperator()->getLocEnd(),
7886adb1d4c18ee83249d4cffc99ef902f98e846092aRichard Smith                                      Params);
7887dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7888d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor
7889612409ece080e814f79e06772c690d603f45fbd6Richard Smith  return getDerived().TransformLambdaScope(E, CallOperator);
7890612409ece080e814f79e06772c690d603f45fbd6Richard Smith}
7891612409ece080e814f79e06772c690d603f45fbd6Richard Smith
7892612409ece080e814f79e06772c690d603f45fbd6Richard Smithtemplate<typename Derived>
7893612409ece080e814f79e06772c690d603f45fbd6Richard SmithExprResult
7894612409ece080e814f79e06772c690d603f45fbd6Richard SmithTreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7895612409ece080e814f79e06772c690d603f45fbd6Richard Smith                                             CXXMethodDecl *CallOperator) {
7896d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor  // Introduce the context of the call operator.
7897d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor  Sema::ContextRAII SavedContext(getSema(), CallOperator);
7898d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor
7899dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // Enter the scope of the lambda.
7900dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  sema::LambdaScopeInfo *LSI
7901dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7902dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                                 E->getCaptureDefault(),
7903dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                                 E->hasExplicitParameters(),
7904dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                                 E->hasExplicitResultType(),
7905dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                                 E->isMutable());
79064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7907dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // Transform captures.
7908612409ece080e814f79e06772c690d603f45fbd6Richard Smith  bool Invalid = false;
7909dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  bool FinishedExplicitCaptures = false;
79104a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  for (LambdaExpr::capture_iterator C = E->capture_begin(),
7911dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                                 CEnd = E->capture_end();
7912dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor       C != CEnd; ++C) {
7913dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    // When we hit the first implicit capture, tell Sema that we've finished
7914dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    // the list of explicit captures.
7915dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    if (!FinishedExplicitCaptures && C->isImplicit()) {
7916dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor      getSema().finishLambdaExplicitCaptures(LSI);
7917dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor      FinishedExplicitCaptures = true;
7918dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    }
79194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7920dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    // Capturing 'this' is trivial.
7921dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    if (C->capturesThis()) {
7922dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor      getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7923dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor      continue;
7924dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    }
79254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7926a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    // Determine the capture kind for Sema.
7927a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    Sema::TryCaptureKind Kind
7928a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor      = C->isImplicit()? Sema::TryCapture_Implicit
7929a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor                       : C->getCaptureKind() == LCK_ByCopy
7930a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor                           ? Sema::TryCapture_ExplicitByVal
7931a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor                           : Sema::TryCapture_ExplicitByRef;
7932a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    SourceLocation EllipsisLoc;
7933a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    if (C->isPackExpansion()) {
7934a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor      UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7935a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor      bool ShouldExpand = false;
7936a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor      bool RetainExpansion = false;
7937a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor      llvm::Optional<unsigned> NumExpansions;
79384a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
79394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                               C->getLocation(),
7940a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor                                               Unexpanded,
7941a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor                                               ShouldExpand, RetainExpansion,
7942a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor                                               NumExpansions))
7943a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor        return ExprError();
79444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7945a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor      if (ShouldExpand) {
7946a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor        // The transform has determined that we should perform an expansion;
7947a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor        // transform and capture each of the arguments.
7948a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor        // expansion of the pattern. Do so.
7949a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor        VarDecl *Pack = C->getCapturedVar();
7950a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor        for (unsigned I = 0; I != *NumExpansions; ++I) {
7951a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor          Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7952a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor          VarDecl *CapturedVar
79534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier            = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7954a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor                                                               Pack));
7955a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor          if (!CapturedVar) {
7956a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor            Invalid = true;
7957a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor            continue;
7958a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor          }
79594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7960a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor          // Capture the transformed variable.
79614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier          getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
79624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        }
7963a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor        continue;
7964a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor      }
79654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7966a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor      EllipsisLoc = C->getEllipsisLoc();
7967a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    }
79684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7969dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    // Transform the captured variable.
7970dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    VarDecl *CapturedVar
79714a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7972dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                                                         C->getCapturedVar()));
7973dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    if (!CapturedVar) {
7974dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor      Invalid = true;
7975dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor      continue;
7976dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    }
79774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
7978dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    // Capture the transformed variable.
7979999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor    getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7980dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  }
7981dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  if (!FinishedExplicitCaptures)
7982dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    getSema().finishLambdaExplicitCaptures(LSI);
7983dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
7984dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
7985dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // Enter a new evaluation context to insulate the lambda from any
7986dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // cleanups from the enclosing full-expression.
79874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7988dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
7989dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  if (Invalid) {
79904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7991dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                               /*IsInstantiation=*/true);
7992dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor    return ExprError();
7993dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  }
7994dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
7995dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  // Instantiate the body of the lambda expression.
7996d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor  StmtResult Body = getDerived().TransformStmt(E->getBody());
7997d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor  if (Body.isInvalid()) {
79984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7999d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor                               /*IsInstantiation=*/true);
80004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    return ExprError();
8001d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor  }
8002ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cfDouglas Gregor
80034a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
8004f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor                                   /*CurScope=*/0, /*IsInstantiation=*/true);
800501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor}
800601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
800701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregortemplate<typename Derived>
800801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas GregorExprResult
8009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
8010454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall                                                  CXXUnresolvedConstructExpr *E) {
8011ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8012ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  if (!T)
8013f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
80141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
80164e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Args;
8017aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->arg_size());
80184a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8019aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgumentChanged))
8020aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
80214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
8023ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor      T == E->getTypeSourceInfo() &&
8024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
80253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
80261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // FIXME: we're faking the locations of the commas
8028ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  return getDerived().RebuildCXXUnresolvedConstructExpr(T,
8029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getLParenLoc(),
80303fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                                        Args,
8031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                        E->getRParenLoc());
8032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
80331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
803560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8036865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
80372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                             CXXDependentScopeMemberExpr *E) {
8038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Transform the base of the expression.
803960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
8040aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *OldBase;
8041aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
8042aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType ObjectType;
8043aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->isImplicitAccess()) {
8044aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = E->getBase();
8045aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(OldBase);
8046aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
8047f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
80481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8049aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    // Start the member reference and compute the object's type.
8050b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ParsedType ObjectTy;
8051d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor    bool MayBePseudoDestructor = false;
80529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
8053aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                E->getOperatorLoc(),
8054a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                                      E->isArrow()? tok::arrow : tok::period,
8055d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                ObjectTy,
8056d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor                                                MayBePseudoDestructor);
8057aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
8058f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
8059aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
8060b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall    ObjectType = ObjectTy.get();
8061aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = ((Expr*) Base.get())->getType();
8062aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
8063aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    OldBase = 0;
8064aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(E->getBaseType());
8065aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8066aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
80671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80686cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // Transform the first part of the nested-name-specifier that qualifies
80696cd219879ffce00920189ec1dcea927a42602961Douglas Gregor  // the member name.
8070c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierInScope
80716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor    = getDerived().TransformFirstQualifierInScope(
80727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                            E->getFirstQualifierFoundInScope(),
80737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                            E->getQualifierLoc().getBeginLoc());
80741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
8076a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  if (E->getQualifier()) {
80777c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    QualifierLoc
80787c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
80797c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     ObjectType,
80807c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     FirstQualifierInScope);
80817c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    if (!QualifierLoc)
8082f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
8083a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  }
80841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8085e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8086e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
808743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // TODO: If this is a conversion-function-id, verify that the
808843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // destination type name (if present) resolves the same way after
808943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  // instantiation as it did in the local scope.
809043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall
80912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo
809243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall    = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
80932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (!NameInfo.getName())
8094f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
80951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8096aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!E->hasExplicitTemplateArgs()) {
80973b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // This is a reference to a member without an explicitly-specified
80983b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    // template argument list. Optimize for this common case.
80993b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    if (!getDerived().AlwaysRebuild() &&
8100aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        Base.get() == OldBase &&
8101aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall        BaseType == E->getBaseType() &&
81027c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor        QualifierLoc == E->getQualifierLoc() &&
81032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara        NameInfo.getName() == E->getMember() &&
81043b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor        FirstQualifierInScope == E->getFirstQualifierFoundInScope())
81053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall      return SemaRef.Owned(E);
81061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8108aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                       BaseType,
81093b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->isArrow(),
81103b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                       E->getOperatorLoc(),
81117c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                       QualifierLoc,
8112e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                       TemplateKWLoc,
8113129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       FirstQualifierInScope,
81142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                       NameInfo,
8115129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                       /*TemplateArgs*/ 0);
81163b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
81173b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor
8118d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
8119fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor  if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8120fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              E->getNumTemplateArgs(),
8121fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                              TransArgs))
8122fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    return ExprError();
81231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
8125aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                     BaseType,
8126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->isArrow(),
8127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                     E->getOperatorLoc(),
81287c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                                                     QualifierLoc,
8129e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                     TemplateKWLoc,
81303b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                                                     FirstQualifierInScope,
81312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                                     NameInfo,
8132129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                     &TransArgs);
8133129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}
8134129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
8135129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived>
813660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8137454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
8138129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform the base of the expression.
813960d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base((Expr*) 0);
8140aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
8141aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  if (!Old->isImplicitAccess()) {
8142aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base = getDerived().TransformExpr(Old->getBase());
8143aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (Base.isInvalid())
8144f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
81459138b4e96429cbaae00c52c15c960f72b6645088Richard Smith    Base = getSema().PerformMemberExprBaseConversion(Base.take(),
81469138b4e96429cbaae00c52c15c960f72b6645088Richard Smith                                                     Old->isArrow());
81479138b4e96429cbaae00c52c15c960f72b6645088Richard Smith    if (Base.isInvalid())
81489138b4e96429cbaae00c52c15c960f72b6645088Richard Smith      return ExprError();
81499138b4e96429cbaae00c52c15c960f72b6645088Richard Smith    BaseType = Base.get()->getType();
8150aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  } else {
8151aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    BaseType = getDerived().TransformType(Old->getBaseType());
8152aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
8153129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
81544c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
81554c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  if (Old->getQualifierLoc()) {
81564c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    QualifierLoc
81574c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
81584c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (!QualifierLoc)
8159f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
8160129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
8161129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
8162e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8163e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
81642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  LookupResult R(SemaRef, Old->getMemberNameInfo(),
8165129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                 Sema::LookupOrdinaryName);
8166129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
8167129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Transform all the decls.
8168129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8169129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         E = Old->decls_end(); I != E; ++I) {
81707c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor    NamedDecl *InstD = static_cast<NamedDecl*>(
81717c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                getDerived().TransformDecl(Old->getMemberLoc(),
81727c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor                                                           *I));
81739f54ad4381370c6b771424b53d219e661d6d6706John McCall    if (!InstD) {
81749f54ad4381370c6b771424b53d219e661d6d6706John McCall      // Silently ignore these if a UsingShadowDecl instantiated to nothing.
81759f54ad4381370c6b771424b53d219e661d6d6706John McCall      // This can happen because of dependent hiding.
81769f54ad4381370c6b771424b53d219e661d6d6706John McCall      if (isa<UsingShadowDecl>(*I))
81779f54ad4381370c6b771424b53d219e661d6d6706John McCall        continue;
817834f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis      else {
817934f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis        R.clear();
8180f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
818134f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis      }
81829f54ad4381370c6b771424b53d219e661d6d6706John McCall    }
8183129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
8184129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    // Expand using declarations.
8185129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (isa<UsingDecl>(InstD)) {
8186129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      UsingDecl *UD = cast<UsingDecl>(InstD);
8187129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8188129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall             E = UD->shadow_end(); I != E; ++I)
8189129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall        R.addDecl(*I);
8190129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      continue;
8191129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    }
8192129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
8193129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    R.addDecl(InstD);
8194129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
8195129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
8196129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  R.resolveKind();
8197129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
8198c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  // Determine the naming class.
8199042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth  if (Old->getNamingClass()) {
82004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    CXXRecordDecl *NamingClass
8201c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
820266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                          Old->getMemberLoc(),
820366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor                                                        Old->getNamingClass()));
820466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    if (!NamingClass)
8205f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
82064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
820766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor    R.setNamingClass(NamingClass);
8208c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  }
82094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8210129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  TemplateArgumentListInfo TransArgs;
8211129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  if (Old->hasExplicitTemplateArgs()) {
8212129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setLAngleLoc(Old->getLAngleLoc());
8213129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    TransArgs.setRAngleLoc(Old->getRAngleLoc());
8214fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor    if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8215fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                Old->getNumTemplateArgs(),
8216fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor                                                TransArgs))
8217fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor      return ExprError();
8218129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
8219c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall
8220c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // FIXME: to do this check properly, we will need to preserve the
8221c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // first-qualifier-in-scope here, just in case we had a dependent
8222c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // base (and therefore couldn't do the check) and a
8223c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  // nested-name-qualifier (and therefore could do the lookup).
8224c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall  NamedDecl *FirstQualifierInScope = 0;
82254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
82269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
8227aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                                                  BaseType,
8228129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->getOperatorLoc(),
8229129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  Old->isArrow(),
82304c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                                  QualifierLoc,
8231e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                  TemplateKWLoc,
8232c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall                                                  FirstQualifierInScope,
8233129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  R,
8234129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                              (Old->hasExplicitTemplateArgs()
8235129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                                                  ? &TransArgs : 0));
8236b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8237b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
8238b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
823960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
82402e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
8241eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt  EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
82422e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
82432e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (SubExpr.isInvalid())
82442e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return ExprError();
82452e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
82462e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
82473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
82482e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
82492e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
82502e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}
82512e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
82522e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived>
82532e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult
8254be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
82554f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
82564f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (Pattern.isInvalid())
82574f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return ExprError();
82584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
82594f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor  if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
82604f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor    return SemaRef.Owned(E);
82614f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor
826267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
826367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                                           E->getNumExpansions());
8264be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}
8265ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
8266ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived>
8267ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult
8268ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8269ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // If E is not value-dependent, then nothing will change when we transform it.
8270ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: This is an instantiation-centric view.
8271ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  if (!E->isValueDependent())
8272ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
8273ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
8274ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Note: None of the implementations of TryExpandParameterPacks can ever
8275ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // produce a diagnostic when given only a single unexpanded parameter pack,
82764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  // so
8277ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8278ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  bool ShouldExpand = false;
8279d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor  bool RetainExpansion = false;
8280cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> NumExpansions;
82814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
8282a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie                                           Unexpanded,
8283d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           ShouldExpand, RetainExpansion,
8284d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor                                           NumExpansions))
8285ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return ExprError();
82864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8287089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor  if (RetainExpansion)
8288ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return SemaRef.Owned(E);
82894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8290089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor  NamedDecl *Pack = E->getPack();
8291089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor  if (!ShouldExpand) {
82924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8293089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor                                                              Pack));
8294089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor    if (!Pack)
8295089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor      return ExprError();
8296089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor  }
8297089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor
82984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8299ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // We now know the length of the parameter pack, so build a new expression
8300ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // that stores that length.
83014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
83024a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                            E->getPackLoc(), E->getRParenLoc(),
8303089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor                                            NumExpansions);
8304ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}
8305ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
8306be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived>
8307be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult
8308c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8309c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                          SubstNonTypeTemplateParmPackExpr *E) {
8310c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Default behavior is to do nothing with this transformation.
831191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  return SemaRef.Owned(E);
831291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall}
831391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
831491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCalltemplate<typename Derived>
831591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallExprResult
831691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallTreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
831791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                                          SubstNonTypeTemplateParmExpr *E) {
831891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  // Default behavior is to do nothing with this transformation.
8319c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  return SemaRef.Owned(E);
8320c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}
8321c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
8322c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived>
8323c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult
832403e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorTreeTransform<Derived>::TransformMaterializeTemporaryExpr(
832503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor                                                  MaterializeTemporaryExpr *E) {
832603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  return getDerived().TransformExpr(E->GetTemporaryExpr());
832703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor}
83284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
832903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregortemplate<typename Derived>
833003e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorExprResult
8331454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
8332ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  return SemaRef.MaybeBindToTemporary(E);
8333ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
8334ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8335ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived>
8336ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult
8337ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
8338d8b5ca14277e142506daed181ecff9151dfae32cJordy Rose  return SemaRef.Owned(E);
8339ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
8340ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8341ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived>
8342ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult
8343eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick BeardTreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8344eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8345eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  if (SubExpr.isInvalid())
8346eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard    return ExprError();
8347eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard
8348eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  if (!getDerived().AlwaysRebuild() &&
8349eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard      SubExpr.get() == E->getSubExpr())
8350eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard    return SemaRef.Owned(E);
8351eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard
8352eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
8353ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
8354ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8355ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived>
8356ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult
8357ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8358ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  // Transform each of the elements.
8359ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  llvm::SmallVector<Expr *, 8> Elements;
8360ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  bool ArgChanged = false;
83614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8362ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                  /*IsCall=*/false, Elements, &ArgChanged))
8363ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ExprError();
83644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8365ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (!getDerived().AlwaysRebuild() && !ArgChanged)
8366ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return SemaRef.MaybeBindToTemporary(E);
83674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8368ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8369ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                              Elements.data(),
8370ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                              Elements.size());
8371ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
8372ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8373ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived>
8374ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult
8375ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCDictionaryLiteral(
83764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                                    ObjCDictionaryLiteral *E) {
8377ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  // Transform each of the elements.
8378ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8379ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  bool ArgChanged = false;
8380ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8381ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
83824a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8383ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (OrigElement.isPackExpansion()) {
8384ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // This key/value element is a pack expansion.
8385ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8386ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8387ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8388ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8389ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8390ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // Determine whether the set of unexpanded parameter packs can
8391ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // and should be expanded.
8392ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      bool Expand = true;
8393ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      bool RetainExpansion = false;
8394ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8395ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8396ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      SourceRange PatternRange(OrigElement.Key->getLocStart(),
8397ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                               OrigElement.Value->getLocEnd());
8398ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek     if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8399ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                               PatternRange,
8400ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                               Unexpanded,
8401ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                               Expand, RetainExpansion,
8402ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                               NumExpansions))
8403ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        return ExprError();
8404ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8405ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      if (!Expand) {
8406ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        // The transform has determined that we should perform a simple
84074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        // transformation on the pack expansion, producing another pack
8408ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        // expansion.
8409ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8410ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8411ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        if (Key.isInvalid())
8412ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          return ExprError();
8413ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8414ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        if (Key.get() != OrigElement.Key)
8415ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          ArgChanged = true;
8416ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8417ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8418ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        if (Value.isInvalid())
8419ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          return ExprError();
84204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8421ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        if (Value.get() != OrigElement.Value)
8422ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          ArgChanged = true;
8423ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
84244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        ObjCDictionaryElement Expansion = {
8425ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8426ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        };
8427ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        Elements.push_back(Expansion);
8428ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        continue;
8429ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      }
8430ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8431ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // Record right away that the argument was changed.  This needs
8432ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // to happen even if the array expands to nothing.
8433ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      ArgChanged = true;
84344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8435ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // The transform has determined that we should perform an elementwise
8436ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // expansion of the pattern. Do so.
8437ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      for (unsigned I = 0; I != *NumExpansions; ++I) {
8438ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8439ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8440ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        if (Key.isInvalid())
8441ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          return ExprError();
8442ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8443ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8444ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        if (Value.isInvalid())
8445ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          return ExprError();
8446ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
84474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier        ObjCDictionaryElement Element = {
8448ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          Key.get(), Value.get(), SourceLocation(), NumExpansions
8449ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        };
8450ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8451ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        // If any unexpanded parameter packs remain, we still have a
8452ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        // pack expansion.
8453ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        if (Key.get()->containsUnexpandedParameterPack() ||
8454ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek            Value.get()->containsUnexpandedParameterPack())
8455ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek          Element.EllipsisLoc = OrigElement.EllipsisLoc;
84564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8457ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek        Elements.push_back(Element);
8458ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      }
8459ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8460ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      // We've finished with this pack expansion.
8461ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      continue;
8462ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    }
8463ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8464ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // Transform and check key.
8465ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8466ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Key.isInvalid())
8467ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return ExprError();
84684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8469ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Key.get() != OrigElement.Key)
8470ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      ArgChanged = true;
84714a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8472ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    // Transform and check value.
8473ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    ExprResult Value
8474ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      = getDerived().TransformExpr(OrigElement.Value);
8475ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Value.isInvalid())
8476ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      return ExprError();
84774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8478ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    if (Value.get() != OrigElement.Value)
8479ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      ArgChanged = true;
84804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
84814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    ObjCDictionaryElement Element = {
8482ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8483ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    };
8484ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    Elements.push_back(Element);
8485ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  }
84864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8487ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (!getDerived().AlwaysRebuild() && !ArgChanged)
8488ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return SemaRef.MaybeBindToTemporary(E);
8489ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8490ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8491ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                   Elements.data(),
8492ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                   Elements.size());
8493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
84951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
849660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8497454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
849881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  TypeSourceInfo *EncodedTypeInfo
849981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor    = getDerived().TransformType(E->getEncodedTypeSourceInfo());
850081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor  if (!EncodedTypeInfo)
8501f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
85021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
850481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor      EncodedTypeInfo == E->getEncodedTypeSourceInfo())
85053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
8506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
8507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
850881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor                                            EncodedTypeInfo,
8509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                            E->getRParenLoc());
8510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
85111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
8513f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>::
8514f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8515f85e193739c953358c865005855253af4f68a497John McCall  ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8516f85e193739c953358c865005855253af4f68a497John McCall  if (result.isInvalid()) return ExprError();
8517f85e193739c953358c865005855253af4f68a497John McCall  Expr *subExpr = result.take();
8518f85e193739c953358c865005855253af4f68a497John McCall
8519f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
8520f85e193739c953358c865005855253af4f68a497John McCall      subExpr == E->getSubExpr())
8521f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(E);
8522f85e193739c953358c865005855253af4f68a497John McCall
8523f85e193739c953358c865005855253af4f68a497John McCall  return SemaRef.Owned(new(SemaRef.Context)
8524f85e193739c953358c865005855253af4f68a497John McCall      ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8525f85e193739c953358c865005855253af4f68a497John McCall}
8526f85e193739c953358c865005855253af4f68a497John McCall
8527f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
8528f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>::
8529f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
85304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  TypeSourceInfo *TSInfo
8531f85e193739c953358c865005855253af4f68a497John McCall    = getDerived().TransformType(E->getTypeInfoAsWritten());
8532f85e193739c953358c865005855253af4f68a497John McCall  if (!TSInfo)
8533f85e193739c953358c865005855253af4f68a497John McCall    return ExprError();
85344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8535f85e193739c953358c865005855253af4f68a497John McCall  ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
85364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (Result.isInvalid())
8537f85e193739c953358c865005855253af4f68a497John McCall    return ExprError();
85384a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8539f85e193739c953358c865005855253af4f68a497John McCall  if (!getDerived().AlwaysRebuild() &&
8540f85e193739c953358c865005855253af4f68a497John McCall      TSInfo == E->getTypeInfoAsWritten() &&
8541f85e193739c953358c865005855253af4f68a497John McCall      Result.get() == E->getSubExpr())
8542f85e193739c953358c865005855253af4f68a497John McCall    return SemaRef.Owned(E);
85434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8544f85e193739c953358c865005855253af4f68a497John McCall  return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
85454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                                      E->getBridgeKeywordLoc(), TSInfo,
8546f85e193739c953358c865005855253af4f68a497John McCall                                      Result.get());
8547f85e193739c953358c865005855253af4f68a497John McCall}
8548f85e193739c953358c865005855253af4f68a497John McCall
8549f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived>
855060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8551454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
855292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Transform arguments.
855392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  bool ArgChanged = false;
85544e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> Args;
8555aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Args.reserve(E->getNumArgs());
85564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8557aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  &ArgChanged))
8558aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
85594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
856092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (E->getReceiverKind() == ObjCMessageExpr::Class) {
856192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Class message: transform the receiver type.
856292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    TypeSourceInfo *ReceiverTypeInfo
856392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      = getDerived().TransformType(E->getClassReceiverTypeInfo());
856492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!ReceiverTypeInfo)
8565f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall      return ExprError();
85664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
856792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // If nothing changed, just retain the existing message send.
856892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    if (!getDerived().AlwaysRebuild() &&
856992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor        ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
857092be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor      return SemaRef.MaybeBindToTemporary(E);
857192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
857292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    // Build a new class message send.
8573207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis    SmallVector<SourceLocation, 16> SelLocs;
8574207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis    E->getSelectorLocs(SelLocs);
857592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
857692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getSelector(),
8577207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis                                               SelLocs,
857892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getMethodDecl(),
857992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getLeftLoc(),
85803fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                               Args,
858192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                               E->getRightLoc());
858292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  }
858392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
858492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Instance message: transform the receiver
858592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
858692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         "Only class and instance messages may be instantiated");
858760d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Receiver
858892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor    = getDerived().TransformExpr(E->getInstanceReceiver());
858992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (Receiver.isInvalid())
8590f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
859192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor
859292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // If nothing changed, just retain the existing message send.
859392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
859492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor      Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
859592be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor    return SemaRef.MaybeBindToTemporary(E);
85964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
859792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // Build a new instance message send.
8598207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis  SmallVector<SourceLocation, 16> SelLocs;
8599207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis  E->getSelectorLocs(SelLocs);
86009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCMessageExpr(Receiver.get(),
860192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getSelector(),
8602207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis                                             SelLocs,
860392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getMethodDecl(),
860492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getLeftLoc(),
86053fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                             Args,
860692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor                                             E->getRightLoc());
8607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
86091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
861060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8611454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
86123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
8613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
86151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
861660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8617454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
86183fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall  return SemaRef.Owned(E);
8619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
86211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
862260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8623454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
8624f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
862560d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
8626f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
8627f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
8628f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor
8629f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // We don't need to transform the ivar; it will never change.
86304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8631f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
8632f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
8633f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
86343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
86354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
86369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
8637f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->getLocation(),
8638f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                             E->isArrow(), E->isFreeIvar());
8639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
86411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
864260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8643454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
864412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // 'super' and types never change. Property never changes. Just
864512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  // retain the existing expression.
864612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (!E->isObjectReceiver())
86473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
86484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8649e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // Transform the base expression.
865060d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
8651e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (Base.isInvalid())
8652f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
86534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8654e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // We don't need to transform the property; it will never change.
86554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8656e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  // If nothing changed, just retain the existing expression.
8657e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
8658e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor      Base.get() == E->getBase())
86593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
8660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
866112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  if (E->isExplicitProperty())
866212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall    return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
866312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getExplicitProperty(),
866412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                   E->getLocation());
866512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall
866612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall  return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
86673c3b7f90a863af43fa63043d396553ecf205351cJohn McCall                                                 SemaRef.Context.PseudoObjectTy,
866812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertyGetter(),
866912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getImplicitPropertySetter(),
867012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall                                                 E->getLocation());
8671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
86731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
867460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8675ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8676ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  // Transform the base expression.
8677ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8678ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (Base.isInvalid())
8679ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ExprError();
8680ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8681ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  // Transform the key expression.
8682ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8683ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (Key.isInvalid())
8684ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return ExprError();
8685ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8686ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  // If nothing changed, just retain the existing expression.
8687ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  if (!getDerived().AlwaysRebuild() &&
8688ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek      Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8689ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek    return SemaRef.Owned(E);
8690ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
86914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8692ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                  Base.get(), Key.get(),
8693ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                  E->getAtIndexMethodDecl(),
8694ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                                  E->setAtIndexMethodDecl());
8695ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek}
8696ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek
8697ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived>
8698ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult
8699454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
8700f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // Transform the base expression.
870160d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Base = getDerived().TransformExpr(E->getBase());
8702f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (Base.isInvalid())
8703f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
87044a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8705f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  // If nothing changed, just retain the existing expression.
8706f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor  if (!getDerived().AlwaysRebuild() &&
8707f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor      Base.get() == E->getBase())
87083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
87094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
87109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
8711f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor                                         E->isArrow());
8712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
87141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
871560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8716454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
8717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  bool ArgumentChanged = false;
87184e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> SubExprs;
8719aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  SubExprs.reserve(E->getNumSubExprs());
87204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8721aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  SubExprs, &ArgumentChanged))
8722aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return ExprError();
87231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (!getDerived().AlwaysRebuild() &&
8725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      !ArgumentChanged)
87263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall    return SemaRef.Owned(E);
87271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
87293fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer                                               SubExprs,
8730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                               E->getRParenLoc());
8731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
87331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
873460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
8735454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
8736c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockDecl *oldBlock = E->getBlockDecl();
87374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8738c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8739c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8740c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
8741c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
87420586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian  blockScope->TheDecl->setBlockMissingReturnType(
87430586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian                         oldBlock->blockMissingReturnType());
87444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8745686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<ParmVarDecl*, 4> params;
8746686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<QualType, 4> paramTypes;
87474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8748a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian  // Parameter substitution.
8749c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8750c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_begin(),
8751c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               oldBlock->param_size(),
875200b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis                                               0, paramTypes, &params)) {
875300b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis    getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
875492be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor    return ExprError();
875500b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis  }
8756c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
8757c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  const FunctionType *exprFunctionType = E->getFunctionType();
875884b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  QualType exprResultType =
875984b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman      getDerived().TransformType(exprFunctionType->getResultType());
8760a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor
8761a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  // Don't allow returning a objc interface by value.
876284b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  if (exprResultType->isObjCObjectType()) {
87634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier    getSema().Diag(E->getCaretLocation(),
87644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier                   diag::err_object_cannot_be_passed_returned_by_value)
876584b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman      << 0 << exprResultType;
876600b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis    getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
8767a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    return ExprError();
8768a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor  }
8769711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
8770c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  QualType functionType = getDerived().RebuildFunctionProtoType(
877184b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman                                                        exprResultType,
8772c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.data(),
8773c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        paramTypes.size(),
8774c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                                        oldBlock->isVariadic(),
8775eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith                                                        false, 0, RQ_None,
8776c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                               exprFunctionType->getExtInfo());
8777c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  blockScope->FunctionType = functionType;
8778711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
8779711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Set the parameters on the block decl.
8780c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  if (!params.empty())
87814278c654b645402554eb52a48e9c7097c9f1233aDavid Blaikie    blockScope->TheDecl->setParams(params);
878284b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman
878384b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  if (!oldBlock->blockMissingReturnType()) {
878484b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman    blockScope->HasImplicitReturnType = false;
878584b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman    blockScope->ReturnType = exprResultType;
878684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  }
87874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8788711c52bb20d0c69063b52a99826fb7d2835501f1John McCall  // Transform the body
8789c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  StmtResult body = getDerived().TransformStmt(E->getBody());
879000b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis  if (body.isInvalid()) {
879100b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis    getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
8792711c52bb20d0c69063b52a99826fb7d2835501f1John McCall    return ExprError();
879300b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis  }
8794711c52bb20d0c69063b52a99826fb7d2835501f1John McCall
8795c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG
8796c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // In builds with assertions, make sure that we captured everything we
8797c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  // captured before.
8798fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor  if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8799fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor    for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8800fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor           e = oldBlock->capture_end(); i != e; ++i) {
8801fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      VarDecl *oldCapture = i->getVariable();
8802fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor
8803fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      // Ignore parameter packs.
8804fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      if (isa<ParmVarDecl>(oldCapture) &&
8805fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor          cast<ParmVarDecl>(oldCapture)->isParameterPack())
8806fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor        continue;
8807c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
8808fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      VarDecl *newCapture =
8809fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor        cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8810fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor                                                 oldCapture));
8811fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor      assert(blockScope->CaptureMap.count(newCapture));
8812fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor    }
8813ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor    assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
8814c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  }
8815c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif
8816c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall
8817c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall  return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8818c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall                                    /*Scope=*/0);
8819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
88211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
882260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
882361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8824b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  llvm_unreachable("Cannot transform asType expressions yet");
882561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}
8826276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
8827276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmantemplate<typename Derived>
8828276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanExprResult
8829276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanTreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
8830dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  QualType RetTy = getDerived().TransformType(E->getType());
8831dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  bool ArgumentChanged = false;
88324e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer  SmallVector<Expr*, 8> SubExprs;
8833dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  SubExprs.reserve(E->getNumSubExprs());
8834dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8835dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman                                  SubExprs, &ArgumentChanged))
8836dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    return ExprError();
8837dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman
8838dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  if (!getDerived().AlwaysRebuild() &&
8839dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman      !ArgumentChanged)
8840dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman    return SemaRef.Owned(E);
8841dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman
88423fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer  return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
8843dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman                                        RetTy, E->getOp(), E->getRParenLoc());
8844276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman}
88454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
8846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
8847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction
8848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===//
8849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
88501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
885185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
885285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                    SourceLocation Star) {
88532865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildPointerType(PointeeType, Star,
8854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                  getDerived().getBaseEntity());
8855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
88571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
885885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
885985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                         SourceLocation Star) {
88602865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildBlockPointerType(PointeeType, Star,
8861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                       getDerived().getBaseEntity());
8862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
88641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
88651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
886685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
886785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             bool WrittenAsLValue,
886885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                             SourceLocation Sigil) {
88692865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
887085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                    Sigil, getDerived().getBaseEntity());
8871b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
8872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor
88731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived>
88741eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
887585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
887685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 QualType ClassType,
887785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceLocation Sigil) {
88782865474261a608c7873b87ba4af110d17907896dJohn McCall  return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
887985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        Sigil, getDerived().getBaseEntity());
8880577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8881577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8882577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
88831eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
8884577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8885577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         ArrayType::ArraySizeModifier SizeMod,
8886577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         const llvm::APInt *Size,
8887577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         Expr *SizeExpr,
8888577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         unsigned IndexTypeQuals,
8889577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                         SourceRange BracketsRange) {
8890577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  if (SizeExpr || !Size)
8891577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8892577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  IndexTypeQuals, BracketsRange,
8893577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                  getDerived().getBaseEntity());
88941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
88951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  QualType Types[] = {
88961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
88971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
88981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
8899577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  };
8900577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8901577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  QualType SizeType;
8902577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  for (unsigned I = 0; I != NumTypes; ++I)
8903577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8904577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      SizeType = Types[I];
8905577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor      break;
8906577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor    }
89071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
890801f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman  // Note that we can return a VariableArrayType here in the case where
890901f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman  // the element type was a dependent VariableArrayType.
891001f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman  IntegerLiteral *ArraySize
891101f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman      = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
891201f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman                               /*FIXME*/BracketsRange.getBegin());
891301f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman  return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
8914577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                IndexTypeQuals, BracketsRange,
89151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                getDerived().getBaseEntity());
8916577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
89171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8918577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
89191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
89201eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
8921577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 ArrayType::ArraySizeModifier SizeMod,
8922577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 const llvm::APInt &Size,
892385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
892485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 SourceRange BracketsRange) {
89251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
892685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                        IndexTypeQuals, BracketsRange);
8927577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8928577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8929577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
89301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
89311eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
8932577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
893385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                 unsigned IndexTypeQuals,
893485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                                   SourceRange BracketsRange) {
89351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
893685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall                                       IndexTypeQuals, BracketsRange);
8937577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
89381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8939577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
89401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
89411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
8942577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
89439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                 Expr *SizeExpr,
8944577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 unsigned IndexTypeQuals,
8945577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceRange BracketsRange) {
89461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
89479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
8948577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
8949577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8950577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8951577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
89521eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
89531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
8954577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                          ArrayType::ArraySizeModifier SizeMod,
89559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Expr *SizeExpr,
8956577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                       unsigned IndexTypeQuals,
8957577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                   SourceRange BracketsRange) {
89581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
89599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                       SizeExpr,
8960577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                       IndexTypeQuals, BracketsRange);
8961577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
8962577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
8963577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8964577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
8965e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               unsigned NumElements,
8966e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                                               VectorType::VectorKind VecKind) {
8967577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  // FIXME: semantic checking!
8968e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
8969577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
89701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8971577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8972577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8973577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                      unsigned NumElements,
8974577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                 SourceLocation AttributeLoc) {
8975577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8976577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                          NumElements, true);
8977577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  IntegerLiteral *VectorSize
89789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
89799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             AttributeLoc);
89809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
8981577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
89821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8983577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
89841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType
89851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
89869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                           Expr *SizeExpr,
8987577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                  SourceLocation AttributeLoc) {
89889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
8989577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
89901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8991577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
8992577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
89931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          QualType *ParamTypes,
8994577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                                        unsigned NumParamTypes,
89951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                          bool Variadic,
8996eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith                                                         bool HasTrailingReturn,
8997fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                                          unsigned Quals,
8998c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor                                                  RefQualifierKind RefQualifier,
8999fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                            const FunctionType::ExtInfo &Info) {
90001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
9001eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith                                   HasTrailingReturn, Quals, RefQualifier,
9002577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor                                   getDerived().getBaseLocation(),
9003fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   getDerived().getBaseEntity(),
9004fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman                                   Info);
9005577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
90061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9007577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
9008a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9009a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall  return SemaRef.Context.getFunctionNoProtoType(T);
9010a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall}
9011a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall
9012a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived>
9013ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9014ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  assert(D && "no decl found");
9015ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (D->isInvalidDecl()) return QualType();
9016ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
901792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  // FIXME: Doesn't account for ObjCInterfaceDecl!
9018ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  TypeDecl *Ty;
9019ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  if (isa<UsingDecl>(D)) {
9020ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    UsingDecl *Using = cast<UsingDecl>(D);
9021ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(Using->isTypeName() &&
9022ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-typename using");
9023ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
9024ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    // A valid resolved using typename decl points to exactly one type decl.
9025ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(++Using->shadow_begin() == Using->shadow_end());
9026ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
90274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
9028ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  } else {
9029ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9030ed97649e9574b9d854fa4d6109c9333ae0993554John McCall           "UnresolvedUsingTypenameDecl transformed to non-using decl");
9031ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    Ty = cast<UnresolvedUsingTypenameDecl>(D);
9032ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
9033ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
9034ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  return SemaRef.Context.getTypeDeclType(Ty);
9035ed97649e9574b9d854fa4d6109c9333ae0993554John McCall}
9036ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
9037ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived>
90382a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
90392a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                       SourceLocation Loc) {
90402a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildTypeofExprType(E, Loc);
9041577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
9042577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
9043577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
9044577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9045577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor  return SemaRef.Context.getTypeOfType(Underlying);
9046577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
9047577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
9048577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
90492a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
90502a984cad5ac3fdceeff2bd99daa7b90979313475John McCall                                                     SourceLocation Loc) {
90512a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return SemaRef.BuildDecltypeType(E, Loc);
9052577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
9053577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
9054577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived>
9055ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9056ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                            UnaryTransformType::UTTKind UKind,
9057ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                                            SourceLocation Loc) {
9058ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9059ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt}
9060ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
9061ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived>
9062577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
9063833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                                      TemplateName Template,
9064833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                             SourceLocation TemplateNameLoc,
906567714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor                                     TemplateArgumentListInfo &TemplateArgs) {
9066d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
9067577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}
90681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9069dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived>
9070b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9071b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman                                                   SourceLocation KWLoc) {
9072b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  return SemaRef.BuildAtomicType(ValueType, KWLoc);
9073b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}
9074b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
9075b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived>
90761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
9077fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9078d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            bool TemplateKW,
9079d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                            TemplateDecl *Template) {
9080fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
9081d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor                                                  Template);
9082d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
9083d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor
9084d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived>
90851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName
9086fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9087fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            const IdentifierInfo &Name,
9088fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SourceLocation NameLoc,
908943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            QualType ObjectType,
909043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall                                            NamedDecl *FirstQualifierInScope) {
9091fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  UnqualifiedId TemplateName;
9092fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  TemplateName.setIdentifier(&Name, NameLoc);
9093d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
9094e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9095d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
9096e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                       SS, TemplateKWLoc, TemplateName,
9097b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
9098d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
9099d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
910043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall  return Template.get();
9101d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor}
91021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived>
9104ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName
9105fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9106ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            OverloadedOperatorKind Operator,
9107fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor                                            SourceLocation NameLoc,
9108ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor                                            QualType ObjectType) {
9109ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor  UnqualifiedId Name;
9110fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  // FIXME: Bogus location information.
9111e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
9112fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor  Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
9113e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
9114d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  Sema::TemplateTy Template;
9115d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  getSema().ActOnDependentTemplateName(/*Scope=*/0,
9116e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                       SS, TemplateKWLoc, Name,
9117b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall                                       ParsedType::make(ObjectType),
9118d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       /*EnteringContext=*/false,
9119d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor                                       Template);
9120d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor  return Template.template getAsVal<TemplateName>();
9121ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor}
91224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier
9123ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived>
912460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult
9125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor                                                   SourceLocation OpLoc,
91279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *OrigCallee,
91289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *First,
91299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                   Expr *Second) {
91309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Callee = OrigCallee->IgnoreParenCasts();
91319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
91321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Determine whether this should be a builtin operation.
9134f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl  if (Op == OO_Subscript) {
91359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
91369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType())
91379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinArraySubscriptExpr(First,
91389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Callee->getLocStart(),
91399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall                                                       Second, OpLoc);
91401a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman  } else if (Op == OO_Arrow) {
91411a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman    // -> is never a builtin operation.
91429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
91439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  } else if (Second == 0 || isPostIncDec) {
91449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType()) {
9145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // The argument is not of overloadable type, so try to create a
9146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // built-in unary operation.
91472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      UnaryOperatorKind Opc
9148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor        = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
91491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall      return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
9151b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
9152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  } else {
91539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    if (!First->getType()->isOverloadableType() &&
91549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        !Second->getType()->isOverloadableType()) {
9155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // Neither of the arguments is an overloadable type, so try to
9156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      // create a built-in binary operation.
91572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
915860d7b3a319d84d688752be3870615ac0f111fb16John McCall      ExprResult Result
91599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall        = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
9160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      if (Result.isInvalid())
9161f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall        return ExprError();
91621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91633fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer      return Result;
9164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    }
9165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
91661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Compute the transformed set of functions (and function templates) to be
9168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // used during overload resolution.
91696e26689f5d513e24ad7783a4493201930fdeccc0John McCall  UnresolvedSet<16> Functions;
91701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
9172ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    assert(ULE->requiresADL());
9173ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
9174ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // FIXME: Do we have to check
9175ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    // IsAcceptableNonMemberOperatorCandidate for each of these?
91766e26689f5d513e24ad7783a4493201930fdeccc0John McCall    Functions.append(ULE->decls_begin(), ULE->decls_end());
9177ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  } else {
91789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
9179ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
91801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Add any functions found via argument-dependent lookup.
91829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  Expr *Args[2] = { First, Second };
91839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  unsigned NumArgs = 1 + (Second != 0);
91841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for unary operators.
9186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (NumArgs == 1 || isPostIncDec) {
91872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    UnaryOperatorKind Opc
9188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor      = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
91899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
9190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  }
91911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
91925b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor  if (Op == OO_Subscript) {
91935b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    SourceLocation LBrace;
91945b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    SourceLocation RBrace;
91955b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor
91965b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
91975b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
91985b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        LBrace = SourceLocation::getFromRawEncoding(
91995b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor                    NameLoc.CXXOperatorName.BeginOpNameLoc);
92005b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        RBrace = SourceLocation::getFromRawEncoding(
92015b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor                    NameLoc.CXXOperatorName.EndOpNameLoc);
92025b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    } else {
92035b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        LBrace = Callee->getLocStart();
92045b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor        RBrace = OpLoc;
92055b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    }
92065b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor
92075b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor    return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
92085b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor                                                      First, Second);
92095b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor  }
9210f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl
9211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  // Create the overloaded operator invocation for binary operators.
92122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
921360d7b3a319d84d688752be3870615ac0f111fb16John McCall  ExprResult Result
9214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor    = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor  if (Result.isInvalid())
9216f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall    return ExprError();
92171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92183fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer  return Result;
9219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor}
92201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
922126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived>
92224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad RosierExprResult
92239ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
922426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     SourceLocation OperatorLoc,
922526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       bool isArrow,
9226f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                                                       CXXScopeSpec &SS,
922726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                     TypeSourceInfo *ScopeType,
922826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                                       SourceLocation CCLoc,
9229fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                                       SourceLocation TildeLoc,
9230a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                        PseudoDestructorTypeStorage Destroyed) {
92319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  QualType BaseType = Base->getType();
92329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
923326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      (!isArrow && !BaseType->getAs<RecordType>()) ||
92344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier      (isArrow && BaseType->getAs<PointerType>() &&
9235bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif       !BaseType->getAs<PointerType>()->getPointeeType()
9236bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif                                              ->template getAs<RecordType>())){
923726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor    // This pseudo-destructor expression is still a pseudo-destructor.
92389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall    return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
923926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             isArrow? tok::arrow : tok::period,
9240fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                                             SS, ScopeType, CCLoc, TildeLoc,
9241a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                                             Destroyed,
924226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                             /*FIXME?*/true);
924326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  }
92442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
9245a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
92462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
92472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
92482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
92492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  NameInfo.setNamedTypeInfo(DestroyedType);
92502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
92516314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith  // The scope type is now known to be a valid nested name specifier
92526314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith  // component. Tack it on to the end of the nested name specifier.
92536314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith  if (ScopeType)
92546314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith    SS.Extend(SemaRef.Context, SourceLocation(),
92556314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith              ScopeType->getTypeLoc(), CCLoc);
92562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
9257e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
92589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall  return getSema().BuildMemberReferenceExpr(Base, BaseType,
925926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            OperatorLoc, isArrow,
9260e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                            SS, TemplateKWLoc,
9261e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                            /*FIXME: FirstQualifier*/ 0,
92622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                            NameInfo,
926326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor                                            /*TemplateArgs*/ 0);
926426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor}
926526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor
9266577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang
9267577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor
9268577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H
9269