TreeTransform.h revision 4020caec546d221170072d2388b57d151cb26111
157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// 2577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 3577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// The LLVM Compiler Infrastructure 4577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 5577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file is distributed under the University of Illinois Open Source 6577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// License. See LICENSE.TXT for details. 757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===// 8577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 9577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file implements a semantic tree transformation that takes a given 10577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// AST and rebuilds it, possibly transforming some nodes in the process. 11577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 1257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===// 1357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H 15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H 16577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 172d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h" 18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h" 198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor#include "clang/Sema/ParsedTemplate.h" 20dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h" 21781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h" 22c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h" 237cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h" 243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith#include "clang/AST/DeclTemplate.h" 25657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h" 26b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h" 27b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h" 2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h" 2943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h" 3043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h" 3119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h" 3219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h" 33b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h" 34a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h" 357e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h" 36577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm> 37577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 38577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang { 39781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema; 401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one 42577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another. 43577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of 451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template 47577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the 48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the 49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar 50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and 51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters. 52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow 541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can 55577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an 56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The 57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual. 58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which 60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node 61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions, 62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST 63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation 64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g., 65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes 66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create 67577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node. 68577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The 70670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(), 719151c11836f5fbb36cedfe4d22df7e00e77a1d42Douglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), 72577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely 73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations. 74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the 76577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g., 7743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously, 78577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template 80577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX 81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change. 82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild 83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may 84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps. 85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one 871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation 88577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their 89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the 90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking 91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()). 92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 93577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform { 94d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief Private RAII object that helps us forget and then re-remember 95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// the template argument corresponding to a partially-substituted parameter 96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// pack. 97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor class ForgetPartiallySubstitutedPackRAII { 98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Derived &Self; 99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor TemplateArgument Old; 100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 101d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor public: 102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { 103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Old = Self.ForgetPartiallySubstitutedPack(); 104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ~ForgetPartiallySubstitutedPackRAII() { 107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Self.RememberPartiallySubstitutedPack(Old); 108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor }; 110d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected: 112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &SemaRef; 1138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 115577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Initializes a new tree transformer. 116b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } 1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Derived &getDerived() { return static_cast<Derived&>(*this); } 120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Derived &getDerived() const { 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return static_cast<const Derived&>(*this); 124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 12660d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline ExprResult Owned(Expr *E) { return E; } 12760d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline StmtResult Owned(Stmt *S) { return S; } 1289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall 129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the semantic analysis object used for 130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// this tree transform. 131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &getSema() const { return SemaRef; } 1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Whether the transformation should always rebuild AST nodes, even 134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// if none of the children have changed. 135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this function to specify when the transformation 137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// should rebuild all AST nodes. 138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlwaysRebuild() { return false; } 1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the location of the entity being transformed, if that 141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, returns no source-location information. Subclasses can 144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// provide an alternative implementation that provides better location 145577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information. 146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation getBaseLocation() { return SourceLocation(); } 1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the name of the entity being transformed, if that 149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, returns an empty name. Subclasses can provide an alternative 152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// implementation with a more precise name. 153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor DeclarationName getBaseEntity() { return DeclarationName(); } 154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Sets the "base" location and entity when that 156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// information is known based on another transformation. 157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, the source location and entity are ignored. Subclasses can 159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// override this function to provide a customized implementation. 160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor void setBase(SourceLocation Loc, DeclarationName Entity) { } 1611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief RAII object that temporarily sets the base location and entity 163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// used for reporting diagnostics in types. 164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor class TemporaryBase { 165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TreeTransform &Self; 166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OldLocation; 167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclarationName OldEntity; 1681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor public: 170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase(TreeTransform &Self, SourceLocation Location, 1711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName Entity) : Self(Self) { 172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldLocation = Self.getDerived().getBaseLocation(); 173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldEntity = Self.getDerived().getBaseEntity(); 174ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor 175ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor if (Location.isValid()) 176ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor Self.getDerived().setBase(Location, Entity); 177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ~TemporaryBase() { 180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Self.getDerived().setBase(OldLocation, OldEntity); 181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor }; 1831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determine whether the given type \p T has already been 185577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// transformed. 186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 187577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses can provide an alternative implementation of this routine 1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// to short-circuit evaluation when it is known that a given type will 189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// not change. For example, template instantiation need not traverse 190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// non-dependent types. 191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlreadyTransformed(QualType T) { 192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T.isNull(); 193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 194577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 1956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether the given call argument should be dropped, e.g., 1966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// because it is a default argument. 1976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 1986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Subclasses can provide an alternative implementation of this routine to 1996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// determine which kinds of call arguments get dropped. By default, 2006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// CXXDefaultArgument nodes are dropped (prior to transformation). 2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool DropCallArgument(Expr *E) { 2026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return E->isDefaultArgument(); 2036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 204c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Determine whether we should expand a pack expansion with the 2068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// given set of parameter packs into separate arguments by repeatedly 2078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// transforming the pattern. 2088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 209b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor /// By default, the transformer never tries to expand pack expansions. 2108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// Subclasses can override this routine to provide different behavior. 2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param EllipsisLoc The location of the ellipsis that identifies the 2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pack expansion. 2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param PatternRange The source range that covers the entire pattern of 2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// the pack expansion. 2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param Unexpanded The set of unexpanded parameter packs within the 2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pattern. 2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumUnexpanded The number of unexpanded parameter packs in 2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \p Unexpanded. 2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param ShouldExpand Will be set to \c true if the transformer should 2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// expand the corresponding pack expansions into separate arguments. When 2268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// set, \c NumExpansions must also be set. 2278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 228d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \param RetainExpansion Whether the caller should add an unexpanded 229d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// pack expansion after all of the expanded arguments. This is used 230d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// when extending explicitly-specified template argument packs per 231d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// C++0x [temp.arg.explicit]p9. 232d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 2338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumExpansions The number of separate arguments that will be in 234cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// the expanded form of the corresponding pack expansion. This is both an 235cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// input and an output parameter, which can be set by the caller if the 236cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// number of expansions is known a priori (e.g., due to a prior substitution) 237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// and will be set by the callee when the number of expansions is known. 238cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// The callee must set this value when \c ShouldExpand is \c true; it may 239cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// set this value in other cases. 2408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \returns true if an error occurred (e.g., because the parameter packs 2428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// are to be instantiated with arguments of different lengths), false 2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 2448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// must be set. 2458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool TryExpandParameterPacks(SourceLocation EllipsisLoc, 2468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceRange PatternRange, 2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor const UnexpandedParameterPack *Unexpanded, 2488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor unsigned NumUnexpanded, 2498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool &ShouldExpand, 250d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool &RetainExpansion, 251cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> &NumExpansions) { 2528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ShouldExpand = false; 2538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return false; 2548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 2558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 256d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief "Forget" about the partially-substituted pack template argument, 257d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// when performing an instantiation that must preserve the parameter pack 258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// use. 259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// This routine is meant to be overridden by the template instantiator. 261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor TemplateArgument ForgetPartiallySubstitutedPack() { 262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return TemplateArgument(); 263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief "Remember" the partially-substituted pack template argument 266d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// after performing an instantiation that must preserve the parameter pack 267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// use. 268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// This routine is meant to be overridden by the template instantiator. 270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } 271d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 27212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// \brief Note to the derived class when a function parameter pack is 27312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// being expanded. 27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } 27512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor 276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transforms the given type into another type. 277577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by creating a 279a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// TypeSourceInfo for it and delegating to the appropriate 280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// function. This is expensive, but we don't mind, because 281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// this method is deprecated anyway; all users should be 282a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// switched to storing TypeSourceInfos. 283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 284577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \returns the transformed type. 28543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(QualType T); 2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transforms the given type-with-location into a new 288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type-with-location. 289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// 290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by delegating to the 291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// appropriate TransformXXXType to build a new type. Subclasses 292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// may override this function (to take over all type 293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// transformations) or some set of the TransformXXXType functions 294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// to alter the transformation. 29543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TransformType(TypeSourceInfo *DI); 296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transform the given type-with-location into a new 298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type, collecting location information in the given builder 299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// as necessary. 300577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 30143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); 3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 303657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given statement. 304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this routine transforms a statement by delegating to the 30643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// appropriate TransformXXXStmt function to transform a specific kind of 30743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// statement or the TransformExpr() function to transform an expression. 30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to transform statements using some 30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// other mechanism. 31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 31143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \returns the transformed statement. 31260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformStmt(Stmt *S); 3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 314657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given expression. 315657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// 316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine transforms an expression by delegating to the 317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// appropriate TransformXXXExpr function to build a new expression. 318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this function to transform expressions using some 319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// other mechanism. 320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \returns the transformed expression. 32260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformExpr(Expr *E); 3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Transform the given list of expressions. 325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// This routine transforms a list of expressions by invoking 327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \c TransformExpr() for each subexpression. However, it also provides 328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// support for variadic templates by expanding any pack expansions (if the 329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// derived class permits such expansion) along the way. When pack expansions 330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// are present, the number of outputs may not equal the number of inputs. 331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Inputs The set of expressions to be transformed. 333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param NumInputs The number of expressions in \c Inputs. 335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param IsCall If \c true, then this transform is being performed on 337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// function-call arguments, and any arguments that should be dropped, will 338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// be. 339aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Outputs The transformed input expressions will be added to this 341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// vector. 342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param ArgChanged If non-NULL, will be set \c true if any argument changed 344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// due to transformation. 345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \returns true if an error occurred, false otherwise. 347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, 348aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor llvm::SmallVectorImpl<Expr *> &Outputs, 349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged = 0); 350aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given declaration, which is referenced from a type 352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// or expression. 353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 354dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, acts as the identity function on declarations. Subclasses 355dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// may override this function to provide alternate behavior. 3567c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } 35743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 35843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Transform the definition of the given declaration. 35943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, invokes TransformDecl() to transform the declaration. 36143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Decl *TransformDefinition(SourceLocation Loc, Decl *D) { 363c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().TransformDecl(Loc, D); 3647c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor } 3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3666cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// \brief Transform the given declaration, which was the first part of a 3676cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// nested-name-specifier in a member access expression. 3686cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 369c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// This specific declaration transformation only applies to the first 3706cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// identifier in a nested-name-specifier of a member access expression, e.g., 3716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// the \c T in \c x->T::member 3726cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 3736cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// By default, invokes TransformDecl() to transform the declaration. 3746cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// Subclasses may override this function to provide alternate behavior. 375c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { 376c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); 3776cd219879ffce00920189ec1dcea927a42602961Douglas Gregor } 378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 379c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// \brief Transform the given nested-name-specifier with source-location 380c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// information. 381c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// 382c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// By default, transforms all of the types and declarations within the 383c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// nested-name-specifier. Subclasses may override this function to provide 384c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// alternate behavior. 385c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( 386c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 387c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType = QualType(), 388c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 389c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 39081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// \brief Transform the given declaration name. 39181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// 39281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// By default, transforms the types of conversion function, constructor, 39381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// and destructor names and then (if needed) rebuilds the declaration name. 39481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// Identifiers and selectors are returned unmodified. Sublcasses may 39581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// override this function to provide alternate behavior. 3962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo 39743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template name. 4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 401fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param SS The nested-name-specifier that qualifies the template 402fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// name. This nested-name-specifier must already have been transformed. 403fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 404fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param Name The template name to transform. 405fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 406fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param NameLoc The source location of the template name. 407fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 408fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param ObjectType If we're translating a template name within a member 409fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// access expression, this is the type of the object whose member template 410fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// is being referenced. 411fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 412fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param FirstQualifierInScope If the first part of a nested-name-specifier 413fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// also refers to a name within the current (lexical) scope, this is the 414fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// declaration it refers to. 415fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 416fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// By default, transforms the template name by transforming the declarations 417fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// and nested-name-specifiers that occur within the template name. 418fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 419fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName TransformTemplateName(CXXScopeSpec &SS, 420fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 421fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 422fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType = QualType(), 423fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 424fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 425577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template argument. 426577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this operation transforms the type, expression, or 4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// declaration stored within the template argument and constructs a 429670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// new template argument from the transformed result. Subclasses may 430670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// override this function to provide alternate behavior. 431833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// 432833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Returns true if there was an error. 433833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall bool TransformTemplateArgument(const TemplateArgumentLoc &Input, 434833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output); 435833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 436fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \brief Transform the given set of template arguments. 437fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 438fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// By default, this operation transforms all of the template arguments 439fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 440fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// the transformed arguments to the output list. 441fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 4427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// Note that this overload of \c TransformTemplateArguments() is merely 4437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// a convenience function. Subclasses that wish to override this behavior 4447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// should override the iterator-based member template version. 4457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 446fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Inputs The set of template arguments to be transformed. 447fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 448fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param NumInputs The number of template arguments in \p Inputs. 449fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 450fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Outputs The set of transformed template arguments output by this 451fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// routine. 452fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 453fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// Returns true if an error occurred. 454fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, 455fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor unsigned NumInputs, 4567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs) { 4577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); 4587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 4597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 4607f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \brief Transform the given set of template arguments. 4617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// By default, this operation transforms all of the template arguments 4637f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 4647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// the transformed arguments to the output list. 4657f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param First An iterator to the first template argument. 4677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 4687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param Last An iterator one step past the last template argument. 4697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4707f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \param Outputs The set of transformed template arguments output by this 4717f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// routine. 4727f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4737f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// Returns true if an error occurred. 4747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename InputIterator> 4757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor bool TransformTemplateArguments(InputIterator First, 4767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 4777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs); 4787f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 479833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. 480833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void InventTemplateArgumentLoc(const TemplateArgument &Arg, 481833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &ArgLoc); 482833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 483a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// \brief Fakes up a TypeSourceInfo for a type. 484a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *InventTypeSourceInfo(QualType T) { 485a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return SemaRef.Context.getTrivialTypeSourceInfo(T, 486833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().getBaseLocation()); 487833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 49143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); 492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 493577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 49428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult 49528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TransformSEHHandler(Stmt *Handler); 49628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 49743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 49843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformTemplateSpecializationType(TypeLocBuilder &TLB, 49943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL, 50043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template); 50143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 50243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 50343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 50443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL, 505087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 506087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS); 507a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 508a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType 509a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 51094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 51194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc); 51294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 51321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms the parameters of a function type into the 51421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// given vectors. 51521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 51621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// The result vectors should be kept in sync; null entries in the 51721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// variables vector are acceptable. 51821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 51921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// Return true on error. 520a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor bool TransformFunctionTypeParams(SourceLocation Loc, 521a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 522a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 52321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVectorImpl<QualType> &PTypes, 524a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor llvm::SmallVectorImpl<ParmVarDecl*> *PVars); 52521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 52621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms a single function-type parameter. Return null 52721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// on error. 528fb44de956f27875def889482b5393475060392afJohn McCall /// 529fb44de956f27875def889482b5393475060392afJohn McCall /// \param indexAdjustment - A number to add to the parameter's 530fb44de956f27875def889482b5393475060392afJohn McCall /// scope index; can be negative 5316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, 532fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 5336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions); 53421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 53543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); 536833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 53760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); 53860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); 5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 54160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Transform##Node(Node *S); 542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 54360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Transform##Node(Node *E); 5447381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 5454bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new pointer type given its pointee type. 548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the pointer type. 550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 55185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new block pointer type given its pointee type. 554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis when building the block pointer 556577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 55785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 558577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 55985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \brief Build a new reference type given the type it references. 560577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 56185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// By default, performs semantic analysis when building the 56285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// reference type. Subclasses may override this routine to provide 56385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// different behavior. 564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 56585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \param LValue whether the type was written with an lvalue sigil 56685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// or an rvalue sigil. 56785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildReferenceType(QualType ReferentType, 56885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool LValue, 56985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new member pointer type given the pointee type and the 572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// class type it refers into. 573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the member pointer 575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 57685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 57785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new array type given the element type, size 580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, size of the array (if known), size expression, and index type 581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// qualifiers. 582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Also by default, all of the other Rebuild*Array 586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildArrayType(QualType ElementType, 587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new constant array type given the element type, size 594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, (known) size of the array, and index type qualifiers. 595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 596577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildConstantArrayType(QualType ElementType, 599577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 60185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 60285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 603577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new incomplete array type given the element type, size 605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, and index type qualifiers. 606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildIncompleteArrayType(QualType ElementType, 610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 61185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 61285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new variable-length array type given the element type, 615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildVariableArrayType(QualType ElementType, 620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new dependent-sized array type given the element type, 626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedArrayType(QualType ElementType, 631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 635577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 636577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new vector type given the element type and 637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 64182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 642e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind); 6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new extended vector type given the element type and 645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 646577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new potentially dependently-sized extended vector type 653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// given the element type and number of elements. 654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedExtVectorType(QualType ElementType, 6589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 661577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new function type. 662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the function type. 664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildFunctionProtoType(QualType T, 6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 668fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman bool Variadic, unsigned Quals, 669c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 670fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info); 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Build a new unprototyped function type. 673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType RebuildFunctionNoProtoType(QualType ResultType); 674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 675ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// \brief Rebuild an unresolved typename type, given the decl that 676ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// the UnresolvedUsingTypenameDecl was transformed to. 677ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType RebuildUnresolvedUsingType(Decl *D); 678ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typedef type. 680162e1c1b487352434552147967c3dd296ebee2f7Richard Smith QualType RebuildTypedefType(TypedefNameDecl *Typedef) { 681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Typedef); 682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new class/struct/union type. 685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildRecordType(RecordDecl *Record) { 686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Record); 687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new Enum type. 690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildEnumType(EnumDecl *Enum) { 691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Enum); 692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 6937da2431c23ef1ee8acb114e39692246e1801afc2John McCall 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(expr) type. 695577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typeof type. 697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); 699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(type) type. 701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, builds a new TypeOfType with the given underlying type. 703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypeOfType(QualType Underlying); 704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 705ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// \brief Build a new unary transform type. 706ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType RebuildUnaryTransformType(QualType BaseType, 707ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 708ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc); 709ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++0x decltype type. 711577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 712577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the decltype type. 713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 7142a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71634b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Build a new C++0x auto type. 71734b41d939a1328f484511c6002ba2456db879a29Richard Smith /// 71834b41d939a1328f484511c6002ba2456db879a29Richard Smith /// By default, builds a new AutoType with the given deduced type. 71934b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType RebuildAutoType(QualType Deduced) { 72034b41d939a1328f484511c6002ba2456db879a29Richard Smith return SemaRef.Context.getAutoType(Deduced); 72134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 72234b41d939a1328f484511c6002ba2456db879a29Richard Smith 723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new template specialization type. 724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the template 726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// specialization type. Subclasses may override this routine to provide 727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTemplateSpecializationType(TemplateName Template, 729833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateLoc, 73067714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args); 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 732075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// \brief Build a new parenthesized type. 733075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// 734075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// By default, builds a new ParenType type from the inner type. 735075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 736075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType RebuildParenType(QualType InnerType) { 737075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return SemaRef.Context.getParenType(InnerType); 738075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 739075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new qualified name type. 741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 742465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// By default, builds a new ElaboratedType type from the keyword, 743465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// the nested-name-specifier and the named type. 744465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 74521e413fe6305a198564d436ac515497716c47844John McCall QualType RebuildElaboratedType(SourceLocation KeywordLoc, 74621e413fe6305a198564d436ac515497716c47844John McCall ElaboratedTypeKeyword Keyword, 7479e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 7489e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualType Named) { 7499e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 7509e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 7519e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Named); 7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 753577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 754577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to a template-id. 755577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 756e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// By default, builds a new DependentNameType type from the 757e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// nested-name-specifier and the given type. Subclasses may override 758e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// this routine to provide different behavior. 75933500955d731c73717af52088b7fc0e7a85681e7John McCall QualType RebuildDependentTemplateSpecializationType( 76094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeKeyword Keyword, 76194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 76294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const IdentifierInfo *Name, 76394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor SourceLocation NameLoc, 76467714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args) { 76594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Rebuild the template name. 76694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // TODO: avoid TemplateName abstraction 767fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor CXXScopeSpec SS; 768fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.Adopt(QualifierLoc); 76994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateName InstName 770fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); 77194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 77294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.isNull()) 77394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 77494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 77594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // If it's still dependent, make a dependent specialization. 77694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.getAsDependentTemplateName()) 77794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, 77894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 77994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Name, 78094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Args); 78194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 78294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Otherwise, make an elaborated type wrapping a non-dependent 78394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // specialization. 78494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType T = 78594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 78694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (T.isNull()) return QualType(); 78794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 78894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) 78994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return T; 79094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 79194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 79294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 79394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T); 79494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 79594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 796577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to an identifier. 797577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 798577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typename type 799e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// (or elaborated type). Subclasses may override this routine to provide 800577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 801e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 802e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation KeywordLoc, 8032494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 8042494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor const IdentifierInfo *Id, 805e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation IdLoc) { 8064033642464e8ba0982f88f34cffad808d247b393Douglas Gregor CXXScopeSpec SS; 8072494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor SS.Adopt(QualifierLoc); 808e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 8092494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { 8104033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // If the name is still dependent, just build a new dependent name type. 8114033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!SemaRef.computeDeclContext(SS)) 8122494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getDependentNameType(Keyword, 8132494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 8142494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor Id); 8154033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 817465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (Keyword == ETK_None || Keyword == ETK_Typename) 8182494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, 819e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor *Id, IdLoc); 820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 823e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara // We had a dependent elaborated-type-specifier that has been transformed 8244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // into a non-dependent elaborated-type-specifier. Find the tag we're 8254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // referring to. 826e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 8274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor DeclContext *DC = SemaRef.computeDeclContext(SS, false); 8284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!DC) 8294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8315613876991c80a684595fe8de1f039296a0657ffJohn McCall if (SemaRef.RequireCompleteDeclContext(SS, DC)) 8325613876991c80a684595fe8de1f039296a0657ffJohn McCall return QualType(); 8335613876991c80a684595fe8de1f039296a0657ffJohn McCall 8344033642464e8ba0982f88f34cffad808d247b393Douglas Gregor TagDecl *Tag = 0; 8354033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.LookupQualifiedName(Result, DC); 8364033642464e8ba0982f88f34cffad808d247b393Douglas Gregor switch (Result.getResultKind()) { 8374033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFound: 8384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFoundInCurrentInstantiation: 8394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 840c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Found: 8424033642464e8ba0982f88f34cffad808d247b393Douglas Gregor Tag = Result.getAsSingle<TagDecl>(); 8434033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundOverloaded: 8464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundUnresolvedValue: 8474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor llvm_unreachable("Tag lookup cannot find non-tags"); 8484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 849c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8504033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Ambiguous: 8514033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Let the LookupResult structure handle ambiguities. 8524033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8554033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!Tag) { 856446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // Check where the name exists but isn't a tag type and use that to emit 857446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // better diagnostics. 858446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 859446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.LookupQualifiedName(Result, DC); 860446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky switch (Result.getResultKind()) { 861446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::Found: 862446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundOverloaded: 863446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundUnresolvedValue: { 8643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NamedDecl *SomeDecl = Result.getRepresentativeDecl(); 865446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky unsigned Kind = 0; 866446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky if (isa<TypedefDecl>(SomeDecl)) Kind = 1; 867162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; 868162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; 869446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; 870446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); 871446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 8723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 873446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky default: 874446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // FIXME: Would be nice to highlight just the source range. 875446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 876446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky << Kind << Id << DC; 877446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 878446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky } 8794033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 881465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 882bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, 883bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu IdLoc, *Id)) { 884e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 8854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 8864033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Build the elaborated-type-specifier type. 8904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor QualType T = SemaRef.Context.getTypeDeclType(Tag); 8912494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 8922494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 8932494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T); 894dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8962fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// \brief Build a new pack expansion type. 8972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// 8982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// By default, builds a new PackExpansionType type from the given pattern. 8992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 9002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType RebuildPackExpansionType(QualType Pattern, 9012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor SourceRange PatternRange, 902cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 903cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 904cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, 905cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 9062fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 9072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 908d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier, a flag 909d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// indicating whether the "template" keyword was provided, and the template 910d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// that the template name refers to. 911d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 912d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, builds the new template name directly. Subclasses may override 913d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// this routine to provide different behavior. 914fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 915d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 916d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template); 917d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 918d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier and the 919d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// name that is referred to as a template. 920d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 921d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 922d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 923d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// template name. Subclasses may override this routine to provide different 924d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// behavior. 925fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 926fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 927fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 92843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 92943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope); 9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 931ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// \brief Build a new template name given a nested name specifier and the 932ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// overloaded operator name that is referred to as a template. 933ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// 934ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// By default, performs semantic analysis to determine whether the name can 935ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 936ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// template name. Subclasses may override this routine to provide different 937ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// behavior. 938fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 939ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 940fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 941ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType); 9421aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 9431aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// \brief Build a new template name given a template template parameter pack 9441aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// and the 9451aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// 9461aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 9471aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 9481aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// template name. Subclasses may override this routine to provide different 9491aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// behavior. 9501aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, 9511aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) { 9521aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); 9531aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 9541aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 95543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new compound statement. 95643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 95743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 95843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 95960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 96043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor MultiStmtArg Statements, 96143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation RBraceLoc, 96243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 9639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 96443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 96543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 96643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 96743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new case statement. 96843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 96943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 97043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 97160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 9729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, 97343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EllipsisLoc, 9749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 97543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc) { 9769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 97743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ColonLoc); 97843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to a new case statement. 98143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 98243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 98343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 98460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 9859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().ActOnCaseStmtBody(S, Body); 9869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return S; 98743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new default statement. 99043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 99143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 99243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 99360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, 99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc, 9959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt) { 9969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /*CurScope=*/0); 99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new label statement. 100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 100243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 100343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 100457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, 100557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ColonLoc, Stmt *SubStmt) { 100657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); 100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new "if" statement. 101043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 101143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 101243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 101360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, 101457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Then, 101557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ElseLoc, Stmt *Else) { 101644aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); 101743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Start building a new switch statement. 102043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 102143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 102243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 102360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, 102457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Expr *Cond, VarDecl *CondVar) { 10259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, 1026d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall CondVar); 102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to the switch statement. 103043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 103143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 103360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 103457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Stmt *Switch, Stmt *Body) { 10359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 103643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 103843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new while statement. 103943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 104043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 104143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 104257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, 104357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Body) { 10449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); 104543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new do-while statement. 104843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 104943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 105043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 105160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 1052ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation WhileLoc, SourceLocation LParenLoc, 1053ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Cond, SourceLocation RParenLoc) { 10549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 10559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, RParenLoc); 105643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 105743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 105843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new for statement. 105943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 106043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 106143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1062ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 1063ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Stmt *Init, Sema::FullExprArg Cond, 1064ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner VarDecl *CondVar, Sema::FullExprArg Inc, 1065ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation RParenLoc, Stmt *Body) { 10669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 1067ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner CondVar, Inc, RParenLoc, Body); 106843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new goto statement. 107143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 107243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 107343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1074ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, 1075ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label) { 107657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); 107743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 107843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 107943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new indirect goto statement. 108043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 108143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 108243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 108360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 1084ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation StarLoc, 1085ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Target) { 10869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 108743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new return statement. 109043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 109143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 109243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1093ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { 10949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnReturnStmt(ReturnLoc, Result); 109543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 109743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new declaration statement. 109843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 109943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 110043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 110160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, 11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation StartLoc, 110343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EndLoc) { 1104406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); 1105406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); 110643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1108703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// \brief Build a new inline asm statement. 1109703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// 1110703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// By default, performs semantic analysis to build the new statement. 1111703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// Subclasses may override this routine to provide different behavior. 111260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildAsmStmt(SourceLocation AsmLoc, 1113703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsSimple, 1114703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsVolatile, 1115703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumOutputs, 1116703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumInputs, 1117ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1118703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Constraints, 1119703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Exprs, 11209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *AsmString, 1121703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Clobbers, 1122703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson SourceLocation RParenLoc, 1123703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool MSAsm) { 1124c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 1125703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson NumInputs, Names, move(Constraints), 11269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs, AsmString, Clobbers, 1127703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson RParenLoc, MSAsm); 1128703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 11294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 11304dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @try statement. 11314dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 113460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 11359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *TryBody, 11368f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor MultiStmtArg CatchStmts, 11379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Finally) { 11389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), 11399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Finally); 11404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 11414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 1142be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Rebuild an Objective-C exception declaration. 1143be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1144be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new declaration. 1145be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1146be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1147be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TInfo, QualType T) { 1148ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara return getSema().BuildObjCExceptionDecl(TInfo, T, 1149ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 1150ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 1151ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 1152be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1153c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1154be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Build a new Objective-C @catch statement. 1155be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1156be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1157be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 115860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1159be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor SourceLocation RParenLoc, 1160be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var, 11619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 1162be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 11639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body); 1164be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1165c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @finally statement. 11674dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11694dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 117060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 11719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 11729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 11734dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 1174c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11758fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @throw statement. 1176d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// 1177d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1178d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 117960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 11809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 11819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1182d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 1183c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11848fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @synchronized statement. 11858fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// 11868fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// By default, performs semantic analysis to build the new statement. 11878fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// Subclasses may override this routine to provide different behavior. 118860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 11899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Object, 11909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 11919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, 11929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 11938fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor } 1194c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor 1195f85e193739c953358c865005855253af4f68a497John McCall /// \brief Build a new Objective-C @autoreleasepool statement. 1196f85e193739c953358c865005855253af4f68a497John McCall /// 1197f85e193739c953358c865005855253af4f68a497John McCall /// By default, performs semantic analysis to build the new statement. 1198f85e193739c953358c865005855253af4f68a497John McCall /// Subclasses may override this routine to provide different behavior. 1199f85e193739c953358c865005855253af4f68a497John McCall StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, 1200f85e193739c953358c865005855253af4f68a497John McCall Stmt *Body) { 1201f85e193739c953358c865005855253af4f68a497John McCall return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); 1202f85e193739c953358c865005855253af4f68a497John McCall } 1203f85e193739c953358c865005855253af4f68a497John McCall 1204f85e193739c953358c865005855253af4f68a497John McCall 1205c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// \brief Build a new Objective-C fast enumeration statement. 1206c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// 1207c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1208c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 120960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 1210f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation LParenLoc, 1211f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Element, 1212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Collection, 1213f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation RParenLoc, 1214f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Body) { 1215c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, 12169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element, 12179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection, 1218c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor RParenLoc, 12199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 1220c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor } 1221c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 122243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ exception declaration. 122343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 122443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new decaration. 122543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1226ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 1227a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Declarator, 1228ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation StartLoc, 1229ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation IdLoc, 1230ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara IdentifierInfo *Id) { 1231efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, 1232efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor StartLoc, IdLoc, Id); 1233efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor if (Var) 1234efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor getSema().CurContext->addDecl(Var); 1235efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor return Var; 123643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 123743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 123843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ catch statement. 123943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 124043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 124143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 124260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 1243f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall VarDecl *ExceptionDecl, 1244f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Handler) { 12459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 12469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler)); 124743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 124943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ try statement. 125043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 125143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 125243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 125360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, 1254f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *TryBlock, 1255f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiStmtArg Handlers) { 12569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); 125743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1259ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Build a new C++0x range-based for statement. 1260ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1261ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to build the new statement. 1262ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1263ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, 1264ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc, 1265ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *Range, Stmt *BeginEnd, 1266ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Expr *Cond, Expr *Inc, 1267ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *LoopVar, 1268ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation RParenLoc) { 1269ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, 1270ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond, Inc, LoopVar, RParenLoc); 1271ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1272ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1273ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Attach body to a C++0x range-based for statement. 1274ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1275ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to finish the new statement. 1276ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1277ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { 1278ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().FinishCXXForRangeStmt(ForRange, Body); 1279ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1280ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 128128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHTryStmt(bool IsCXXTry, 128228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 128328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 128428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler) { 128528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); 128628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 128728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 128828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHExceptStmt(SourceLocation Loc, 128928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 129028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 129128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); 129228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 129328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 129428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, 129528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 129628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHFinallyBlock(Loc,Block); 129728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 129828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression that references a declaration. 1300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 130360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 1304f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall LookupResult &R, 1305f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall bool RequiresADL) { 1306f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 1307f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 1308f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1309f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1310f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Build a new expression that references a declaration. 1311f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// 1312f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// By default, performs semantic analysis to build the new expression. 1313f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Subclasses may override this routine to provide different behavior. 131440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 1315f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ValueDecl *VD, 1316f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall const DeclarationNameInfo &NameInfo, 1317f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TemplateArgumentListInfo *TemplateArgs) { 1318a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor CXXScopeSpec SS; 131940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 1320dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 1321dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: loses template args. 13222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 13232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); 1324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression in parentheses. 13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 133060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 1331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParen) { 13329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 1333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1335a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Build a new pseudo-destructor expression. 13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1337a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1338a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// Subclasses may override this routine to provide different behavior. 133960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 1340f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation OperatorLoc, 1341f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool isArrow, 1342f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 1343f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor TypeSourceInfo *ScopeType, 1344f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation CCLoc, 1345f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation TildeLoc, 1346a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed); 13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary operator expression. 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 135260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 13532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc, 13549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 13559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); 1356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Build a new builtin offsetof expression. 13598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 13608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// By default, performs semantic analysis to build the new expression. 13618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// Subclasses may override this routine to provide different behavior. 136260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type, 1364f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::OffsetOfComponent *Components, 13658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComponents, 13668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 13678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 13688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor NumComponents, RParenLoc); 13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1370c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1371f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec_step expression with a 1372f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// type argument. 13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1376f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, 1377f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation OpLoc, 1378f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1379f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 1380f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); 1381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1383f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec step expression with an 1384f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// expression argument. 13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1387b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1388f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, 1389f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1390f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 139160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1392e72c55b9a11be9f00fa3f66f7ad6b73b2814e963Chandler Carruth = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); 1393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1394f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 13951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new array subscript expression. 14001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 140360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildArraySubscriptExpr(Expr *LHS, 1404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LBracketLoc, 14059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 1406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RBracketLoc) { 14079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, 14089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LBracketLoc, RHS, 1409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RBracketLoc); 1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new call expression. 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 141660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 1417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Args, 1418e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation RParenLoc, 1419e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Expr *ExecConfig = 0) { 14209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, 1421e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move(Args), RParenLoc, ExecConfig); 1422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member access 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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 1429f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool isArrow, 143040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1431f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &MemberNameInfo, 1432f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ValueDecl *Member, 1433f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FoundDecl, 1434d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *ExplicitTemplateArgs, 1435f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FirstQualifierInScope) { 1436d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (!Member->getDeclName()) { 1437f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // We have a reference to an unnamed field. This is always the 1438f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // base of an anonymous struct/union member access, i.e. the 1439f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // field is always of record type. 144040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); 1441f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall assert(Member->getType()->isRecordType() && 1442f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall "unnamed member not of record type?"); 14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1444429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult BaseResult = 1445429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley getSema().PerformObjectMemberConversion(Base, 1446429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley QualifierLoc.getNestedNameSpecifier(), 1447429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley FoundDecl, Member); 1448429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (BaseResult.isInvalid()) 1449f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1450429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 1451f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); 14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr *ME = 14539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall new (getSema().Context) MemberExpr(Base, isArrow, 14542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Member, MemberNameInfo, 1455f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall cast<FieldDecl>(Member)->getType(), 1456f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK, OK_Ordinary); 1457d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return getSema().Owned(ME); 1458d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson } 14591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 146083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor CXXScopeSpec SS; 146140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 146283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 1463429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base); 1464429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (BaseResult.isInvalid()) 1465429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return ExprError(); 1466429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 14679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 1468aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 14696bb8017bb9e828d118e15e59d71c66bba323c364John McCall // FIXME: this involves duplicating earlier analysis in a lot of 14706bb8017bb9e828d118e15e59d71c66bba323c364John McCall // cases; we should avoid this when possible. 14712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 14726bb8017bb9e828d118e15e59d71c66bba323c364John McCall R.addDecl(FoundDecl); 1473c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R.resolveKind(); 1474c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 14759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 1476129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 1477c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, ExplicitTemplateArgs); 1478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new binary operator expression. 14811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 148460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 14852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc, 14869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, Expr *RHS) { 14879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); 1488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new conditional operator expression. 14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 149460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildConditionalOperator(Expr *Cond, 149556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, 149656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *LHS, 149756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation ColonLoc, 149856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *RHS) { 14999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 15009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS, RHS); 1501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C-style cast expression. 15041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 150760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 15089d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 1511b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 15129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr); 1513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new compound literal expression. 15161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 151960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 152042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo, 1521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 152342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 15249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new extended vector element access expression. 15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 153160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildExtVectorElementExpr(Expr *Base, 1532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 1533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation AccessorLoc, 1534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor IdentifierInfo &Accessor) { 1535aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 1536129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall CXXScopeSpec SS; 15372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 15389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1539129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall OpLoc, /*IsArrow*/ false, 1540129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, /*FirstQualifierInScope*/ 0, 15412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 1542129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /* TemplateArgs */ 0); 1543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new initializer list expression. 15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 154960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildInitList(SourceLocation LBraceLoc, 1550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Inits, 1551e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor SourceLocation RBraceLoc, 1552e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor QualType ResultTy) { 155360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1554e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); 1555e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor if (Result.isInvalid() || ResultTy->isDependentType()) 1556e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1557c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1558e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // Patch in the result type we were given, which may have been computed 1559e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // when the initial InitListExpr was built. 1560e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); 1561e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor ILE->setType(ResultTy); 1562e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new designated initializer expression. 15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 156960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDesignatedInitExpr(Designation &Desig, 1570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg ArrayExprs, 1571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation EqualOrColonLoc, 1572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool GNUSyntax, 15739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 157460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 15769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1578f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.release(); 1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new value-initialized expression. 15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds the implicit value initialization without performing 1587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// any semantic analysis. Subclasses may override this routine to provide 1588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 158960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildImplicitValueInitExpr(QualType T) { 1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); 1591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new \c va_arg expression. 15941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 159760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 15989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, TypeSourceInfo *TInfo, 15992cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RParenLoc) { 16002cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara return getSema().BuildVAArgExpr(BuiltinLoc, 16019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, TInfo, 16022cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara RParenLoc); 1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression list in parentheses. 16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 160960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg SubExprs, 1611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1612c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, 1613f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian move(SubExprs)); 1614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new address-of-label expression. 16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis, using the name of the label 1619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// rather than attempting to map the label statement itself. 1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 162160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 1622ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation LabelLoc, LabelDecl *Label) { 162357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 1624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new GNU statement expression. 16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 163060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildStmtExpr(SourceLocation LParenLoc, 16319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt, 1632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 16339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); 1634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1636b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new __builtin_choose_expr expression. 1637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 164060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 16419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, Expr *LHS, Expr *RHS, 1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.ActOnChooseExpr(BuiltinLoc, 16449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, LHS, RHS, 1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1648f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// \brief Build a new generic selection expression. 1649f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// 1650f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// By default, performs semantic analysis to build the new expression. 1651f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Subclasses may override this routine to provide different behavior. 1652f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 1653f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation DefaultLoc, 1654f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 1655f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *ControllingExpr, 1656f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **Types, 1657f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr **Exprs, 1658f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs) { 1659f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 1660f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr, Types, Exprs, 1661f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne NumAssocs); 1662f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 1663f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new overloaded operator call expression. 1665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// The semantic analysis provides the behavior of template instantiation, 1668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// copying with transformations that turn what looks like an overloaded 16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// operator call into a use of a builtin operator, performing 1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument-dependent lookup, etc. Subclasses may override this routine to 1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 167260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 16749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee, 16759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 16769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second); 16771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++ "named" cast expression, such as static_cast or 1679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// reinterpret_cast. 1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine dispatches to one of the more-specific routines 16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 1683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 168460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 1685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Stmt::StmtClass Class, 1686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 16879d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 16909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (Class) { 1693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXStaticCastExprClass: 16949d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 16951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 16969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 1697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXDynamicCastExprClass: 16999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 17001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 17049d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 17051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, 1707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 17081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXConstCastExprClass: 17109d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor default: 1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(false && "Invalid C++ named cast"); 1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor break; 1717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1719f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ static_cast expression. 1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 172660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17289d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1733c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 17349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1735c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1736c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ dynamic_cast expression. 1740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 174360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 1744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17459d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1750c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 17519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1752c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1753c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ reinterpret_cast expression. 1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 176060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 1761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17629d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1767c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 17689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1769c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1770c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ const_cast expression. 1774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 177760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 1778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17799d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1784c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 17859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1786c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1787c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ functional-style cast expression. 1791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1794ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 1795ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1796ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor Expr *Sub, 1797ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1798ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 1799f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(&Sub, 1), 1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(type) expression. 1804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 180760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 180857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 180957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *Operand, 1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1811c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 181257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 181501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(expr) expression. 1817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 182060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 182157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 18229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand, 1823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 18249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 182557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 18261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 182801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(type) expression. 182901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 183001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 183101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 183201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 183301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 183401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *Operand, 183501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 183601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 183701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 183801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 183901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 184001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(expr) expression. 184101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 184201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 184301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 184401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 184501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 184601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *Operand, 184701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 184801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 184901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 185001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 185101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "this" expression. 1853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new "this" expression without performing any 18551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// semantic analysis. Subclasses may override this routine to provide 1856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 185760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 1858ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType ThisType, 1859ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor bool isImplicit) { 1860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().Owned( 1861828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, 1862828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor isImplicit)); 1863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ throw expression. 1866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 186960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { 18709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXThrow(ThrowLoc, Sub); 1871b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ default-argument expression. 1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new default-argument expression, which does not 1876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// require any semantic analysis. Subclasses may override this routine to 1877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 187860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, 1879036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 1880036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, 1881036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param)); 1882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ zero-initialization expression. 1885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1888ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 1889ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1890ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1891ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, 18921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MultiExprArg(getSema(), 0, 0), 1893ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc); 1894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "new" expression. 1897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 190060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, 19011bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor bool UseGlobal, 19021bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementLParen, 19031bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg PlacementArgs, 19041bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementRParen, 19051bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceRange TypeIdParens, 19061bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocatedType, 19071bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo, 19081bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor Expr *ArraySize, 19091bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorLParen, 19101bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg ConstructorArgs, 19111bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorRParen) { 19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getSema().BuildCXXNew(StartLoc, UseGlobal, 1913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementLParen, 1914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(PlacementArgs), 1915b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementRParen, 19164bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor TypeIdParens, 19171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedType, 19181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedTypeInfo, 19199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize, 1920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorLParen, 1921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(ConstructorArgs), 1922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorRParen); 1923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "delete" expression. 1926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 192960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 1930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsGlobalDelete, 1931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrayForm, 19329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 1933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 19349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand); 1935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary type trait expression. 1938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 194160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, 19423d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation StartLoc, 19433d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T, 19443d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation RParenLoc) { 19453d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); 1946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 19486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// \brief Build a new binary type trait expression. 19496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// 19506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// By default, performs semantic analysis to build the new expression. 19516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Subclasses may override this routine to provide different behavior. 19526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, 19536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation StartLoc, 19546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT, 19556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT, 19566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParenLoc) { 19576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); 19586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 196021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// \brief Build a new array type trait expression. 196121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// 196221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// By default, performs semantic analysis to build the new expression. 196321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// Subclasses may override this routine to provide different behavior. 196421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, 196521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation StartLoc, 196621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *TSInfo, 196721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *DimExpr, 196821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParenLoc) { 196921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); 197021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 197121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 1972552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// \brief Build a new expression trait expression. 1973552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// 1974552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// By default, performs semantic analysis to build the new expression. 1975552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// Subclasses may override this routine to provide different behavior. 1976552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult RebuildExpressionTrait(ExpressionTrait Trait, 1977552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation StartLoc, 1978552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *Queried, 1979552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParenLoc) { 1980552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); 1981552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 1982552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new (previously unresolved) declaration reference 1984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// expression. 1985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 198800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor ExprResult RebuildDependentScopeDeclRefExpr( 198900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 19902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 1991f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall const TemplateArgumentListInfo *TemplateArgs) { 1992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 199300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SS.Adopt(QualifierLoc); 1994f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1995f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (TemplateArgs) 19962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, 1997f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall *TemplateArgs); 1998f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 19992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); 2000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new template-id expression. 2003b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 200660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 2007f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult &R, 2008f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool RequiresADL, 2009d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &TemplateArgs) { 2010f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); 2011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 201760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstructExpr(QualType T, 20184411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor SourceLocation Loc, 2019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor, 2020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsElidable, 20218c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor MultiExprArg Args, 20228c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor bool RequiresZeroInit, 2023428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth CXXConstructExpr::ConstructionKind ConstructKind, 2024428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange ParenRange) { 2025ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConvertedArgs(SemaRef); 2026c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, 20274411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor ConvertedArgs)) 2028f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2029c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20304411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, 20318c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(ConvertedArgs), 2032428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth RequiresZeroInit, ConstructKind, 2033428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth ParenRange); 2034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2040ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 2041ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2042ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2043ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2044ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2046b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2051b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2053b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2054ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 2055ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2056ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2057ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2058ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2059b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2060b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2062b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member reference expression. 2065b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 206860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 20697c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualType BaseType, 20707c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor bool IsArrow, 20717c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SourceLocation OperatorLoc, 20727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2073129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NamedDecl *FirstQualifierInScope, 20742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 2075129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 2076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 20777c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SS.Adopt(QualifierLoc); 20781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2080aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2081129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 20822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberNameInfo, 20832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemplateArgs); 2084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2085b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2086129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Build a new member reference expression. 20873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// 20883b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// By default, performs semantic analysis to build the new expression. 20893b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// Subclasses may override this routine to provide different behavior. 209060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, 2091aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType, 2092129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 2093129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool IsArrow, 20944c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2095c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope, 2096129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall LookupResult &R, 2097129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 20983b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor CXXScopeSpec SS; 20994c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2102aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2103c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall SS, FirstQualifierInScope, 2104c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, TemplateArgs); 21053b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// \brief Build a new noexcept expression. 21082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// 21092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// By default, performs semantic analysis to build the new expression. 21102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// Subclasses may override this routine to provide different behavior. 21112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 21122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 21132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 21142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 2115ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Build a new expression to compute the length of a parameter pack. 2116ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 2117ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, 2118ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc, 2119ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length) { 2120ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2121ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc, Pack, PackLoc, 2122ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor RParenLoc, Length); 2123ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 2124ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 2125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new Objective-C @encode expression. 2126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 212960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 213081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodeTypeInfo, 2131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 213281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, 2133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc)); 21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 2135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 213692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C class message. 213760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 213892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2139f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelectorLoc, 214092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2141c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 214292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 214392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 214492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return SemaRef.BuildClassMessage(ReceiverTypeInfo, 214592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo->getType(), 214692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2147f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLoc, 2148f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 214992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 215092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 215192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C instance message. 215260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(Expr *Receiver, 215392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2154f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelectorLoc, 215592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2156c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 215792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 215892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 21599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildInstanceMessage(Receiver, 21609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver->getType(), 216192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2162f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLoc, 2163f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 216492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 216592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 2166f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C ivar reference expression. 2167f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2168f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2169f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 217060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 2171f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor SourceLocation IvarLoc, 2172f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow, bool IsFreeIvar) { 2173f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // FIXME: We lose track of the IsFreeIvar bit. 2174f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2175429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2176f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, 2177f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 217860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2179f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IvarLoc, 2180d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, 2181ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall false); 2182429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2183f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2184c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2185f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2186f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2187c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2188429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2189c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IvarLoc, IsArrow, SS, 2190f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2191c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2192f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2193f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2194e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor 2195e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// \brief Build a new Objective-C property reference expression. 2196e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// 2197e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2198e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 219960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 2200e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor ObjCPropertyDecl *Property, 2201e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor SourceLocation PropertyLoc) { 2202e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor CXXScopeSpec SS; 2203429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2204e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, 2205e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Sema::LookupMemberName); 2206e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor bool IsArrow = false; 220760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2208e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FIME:*/PropertyLoc, 2209d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2210429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2211f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2212c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2213e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.get()) 2214e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor return move(Result); 2215c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2216429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2217c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/PropertyLoc, IsArrow, 2218c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SS, 2219e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FirstQualifierInScope=*/0, 2220c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2221e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*TemplateArgs=*/0); 2222e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor } 2223c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 222412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// \brief Build a new Objective-C property reference expression. 22259cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// 22269cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// By default, performs semantic analysis to build the new expression. 222712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// Subclasses may override this routine to provide different behavior. 222812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 222912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Getter, 223012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Setter, 223112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation PropertyLoc) { 223212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // Since these expressions can only be value-dependent, we do not 223312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // need to perform semantic analysis again. 223412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Owned( 223512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 223612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall VK_LValue, OK_ObjCProperty, 223712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyLoc, Base)); 22389cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor } 22399cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor 2240f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C "isa" expression. 2241f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2242f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2243f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 224460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 2245f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow) { 2246f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2247429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2248f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, 2249f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 225060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2251f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IsaLoc, 2252d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2253429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2254f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2255c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2256f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2257f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2258c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2259429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IsaLoc, IsArrow, SS, 2261f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2262c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2263f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2264f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2265c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new shuffle vector expression. 2267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2269b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 227060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 2271f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MultiExprArg SubExprs, 2272f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation RParenLoc) { 2273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Find the declaration for __builtin_shufflevector 22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo &Name 2275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.Context.Idents.get("__builtin_shufflevector"); 2276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 2277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 2278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); 22791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Build a reference to the __builtin_shufflevector builtin 2281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); 2282429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Callee 2283429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), 2284429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley VK_LValue, BuiltinLoc)); 2285429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Callee = SemaRef.UsualUnaryConversions(Callee.take()); 2286429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Callee.isInvalid()) 2287429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return ExprError(); 22881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Build the CallExpr 2290b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor unsigned NumSubExprs = SubExprs.size(); 2291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Expr **Subs = (Expr **)SubExprs.release(); 2292429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult TheCall = SemaRef.Owned( 2293429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), 2294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Subs, NumSubExprs, 22955291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor Builtin->getCallResultType(), 2296f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr::getValueKindForType(Builtin->getResultType()), 2297429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley RParenLoc)); 22981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Type-check the __builtin_shufflevector expression. 2300429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); 2301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 230243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 23038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Build a new template argument pack expansion. 23048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 23058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// By default, performs semantic analysis to build a new pack expansion 23068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// for a template argument. Subclasses may override this routine to provide 23078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// different behavior. 23088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 2309cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 2310cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 23118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor switch (Pattern.getArgument().getKind()) { 23127a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor case TemplateArgument::Expression: { 23137a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor ExprResult Result 231467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 231567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor EllipsisLoc, NumExpansions); 23167a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor if (Result.isInvalid()) 23177a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(); 23187a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor 23197a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(Result.get(), Result.get()); 23207a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor } 2321dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 23228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Template: 2323a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgumentLoc(TemplateArgument( 2324a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getArgument().getAsTemplate(), 23252be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor NumExpansions), 2326b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Pattern.getTemplateQualifierLoc(), 2327a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getTemplateNameLoc(), 2328a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor EllipsisLoc); 23298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Null: 23318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Integral: 23328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Declaration: 23338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Pack: 2334a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 23358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm_unreachable("Pack expansion pattern has no parameter packs"); 23368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Type: 23388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (TypeSourceInfo *Expansion 23398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 2340cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor EllipsisLoc, 2341cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions)) 23428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 23438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expansion); 23448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor break; 23458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 23468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(); 23488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 23498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 2350dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// \brief Build a new expression pack expansion. 2351dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// 2352dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// By default, performs semantic analysis to build a new pack expansion 2353dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// for an expression. Subclasses may override this routine to provide 2354dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// different behavior. 235567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 235667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) { 235767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 2358dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2359dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 236043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate: 2361c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TransformTypeInObjectScope(TypeLoc TL, 2362c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2363c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope, 2364c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS); 2365b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 2366b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 2367b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType ObjectType, 2368b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor NamedDecl *FirstQualifierInScope, 2369b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS); 2370577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}; 2371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 237243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 237360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { 237443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!S) 237543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return SemaRef.Owned(S); 23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 237743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor switch (S->getStmtClass()) { 237843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::NoStmtClass: break; 23791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 238043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform individual statement nodes 238143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 238243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 238363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node) 238443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) 23854bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 23861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 238743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform expressions by calling TransformExpr. 238843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) 23897381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 239043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class: 23914bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 239243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor { 239360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 239443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (E.isInvalid()) 2395f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 23961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); 239843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 23991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 240243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2405670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived> 240660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 2407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!E) 2408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(E); 2409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (E->getStmtClass()) { 2411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::NoStmtClass: break; 2412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break; 24137381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 2414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 2415454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 24164bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 24171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 2420657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor} 2421657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor 2422657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived> 2423aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs, 2424aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor unsigned NumInputs, 2425aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool IsCall, 2426aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor llvm::SmallVectorImpl<Expr *> &Outputs, 2427aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged) { 2428aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor for (unsigned I = 0; I != NumInputs; ++I) { 2429aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor // If requested, drop call arguments that need to be dropped. 2430aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 2431aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (ArgChanged) 2432aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2433aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2434aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor break; 2435aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2436aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2437dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 2438dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expr *Pattern = Expansion->getPattern(); 2439dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2440dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 2441dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 2442dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 2443dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2444dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 2445dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // be expanded. 2446dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor bool Expand = true; 2447d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 244867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 244967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = Expansion->getNumExpansions(); 245067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 2451dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 2452dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Pattern->getSourceRange(), 2453dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Unexpanded.data(), 2454dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Unexpanded.size(), 2455d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, RetainExpansion, 2456d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 2457dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2458dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2459dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (!Expand) { 2460dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform a simple 2461dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // transformation on the pack expansion, producing another pack 2462dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion. 2463dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 2464dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult OutPattern = getDerived().TransformExpr(Pattern); 2465dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (OutPattern.isInvalid()) 2466dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2467dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2468dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 246967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Expansion->getEllipsisLoc(), 247067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions); 2471dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2472dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2473dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2474dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2475dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2476dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2477dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2478dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2479dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2480dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform an elementwise 2481dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion of the pattern. Do so. 2482cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 2483dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 2484dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().TransformExpr(Pattern); 2485dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2486dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2487dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 248877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.get()->containsUnexpandedParameterPack()) { 248967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), 249067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor OrigNumExpansions); 249177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.isInvalid()) 249277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 249377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 249477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 2495dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2496dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2497dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2498dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2499dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2500dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2501dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2502dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2503aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ExprResult Result = getDerived().TransformExpr(Inputs[I]); 2504aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.isInvalid()) 2505aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return true; 2506aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2507aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.get() != Inputs[I] && ArgChanged) 2508aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2509aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2510aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Outputs.push_back(Result.get()); 2511aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2512aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2513aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return false; 2514aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor} 2515aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2516aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived> 2517c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc 2518c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc( 2519c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 2520c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2521c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope) { 2522c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 2523c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 2524c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifier = Qualifier.getPrefix()) 2525c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifiers.push_back(Qualifier); 2526c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2527c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec SS; 2528c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor while (!Qualifiers.empty()) { 2529c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 2530c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 2531c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2532c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor switch (QNNS->getKind()) { 2533c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Identifier: 2534c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, 2535c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor *QNNS->getAsIdentifier(), 2536c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2537c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc(), 2538c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, false, SS, 2539c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, false)) 2540c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2541c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2542c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2543c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2544c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Namespace: { 2545c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceDecl *NS 2546c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceDecl>( 2547c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl( 2548c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2549c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespace())); 2550c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 2551c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2552c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2553c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2554c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::NamespaceAlias: { 2555c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceAliasDecl *Alias 2556c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceAliasDecl>( 2557c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl(Q.getLocalBeginLoc(), 2558c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespaceAlias())); 2559c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 2560c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2561c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2562c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2563c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2564c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Global: 2565c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // There is no meaningful transformation that one could perform on the 2566c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // global scope. 2567c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 2568c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2569c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2570c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2571c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpec: { 2572c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 2573c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, SS); 2574c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2575c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (!TL) 2576c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2577c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2578c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || 2579c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor (SemaRef.getLangOptions().CPlusPlus0x && 2580c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TL.getType()->isEnumeralType())) { 2581c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor assert(!TL.getType().hasLocalQualifiers() && 2582c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor "Can't get cv-qualifiers here"); 2583c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, 2584c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2585c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2586c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 258700c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // If the nested-name-specifier is an invalid type def, don't emit an 258800c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // error because a previous error should have already been emitted. 258900c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); 259000c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { 259100c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 259200c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu << TL.getType() << SS.getRange(); 259300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu } 2594c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2595c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 25967c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 2597c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 25987c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor // The qualifier-in-scope and object type only apply to the leftmost entity. 2599c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope = 0; 26007c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType = QualType(); 2601c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2602c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2603c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Don't rebuild the nested-name-specifier if we don't have to. 2604c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 2605c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor !getDerived().AlwaysRebuild()) 2606c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NNS; 2607c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2608c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // If we can re-use the source-location data from the original 2609c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // nested-name-specifier, do so. 2610c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.location_size() == NNS.getDataLength() && 2611c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 2612c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 2613c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2614c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Allocate new nested-name-specifier location information. 2615c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return SS.getWithLocInContext(SemaRef.Context); 2616c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 2617c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2618c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 26192577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo 26202577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived> 262143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 26222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name = NameInfo.getName(); 262381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor if (!Name) 26242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 262581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 262681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor switch (Name.getNameKind()) { 262781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::Identifier: 262881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 262981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCOneArgSelector: 263081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 263181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXOperatorName: 26323e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 263381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXUsingDirective: 26342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NameInfo; 26351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 263681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConstructorName: 263781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXDestructorName: 263881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConversionFunctionName: { 26392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *NewTInfo; 26402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CanQualType NewCanTy; 26412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 264243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewTInfo = getDerived().TransformType(OldTInfo); 264343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NewTInfo) 264443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return DeclarationNameInfo(); 264543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 26462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 26472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara else { 26482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewTInfo = 0; 26492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 265043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 26512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (NewT.isNull()) 26522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 26532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy = SemaRef.Context.getCanonicalType(NewT); 26542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 26551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName NewName 26572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 26582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy); 26592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NewNameInfo(NameInfo); 26602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setName(NewName); 26612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setNamedTypeInfo(NewTInfo); 26622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NewNameInfo; 266381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor } 26641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 26651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(0 && "Unknown name kind."); 26672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 266881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor} 266981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 267081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived> 26711eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 2672fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, 2673fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 2674fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 2675fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType, 2676fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope) { 2677fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 2678fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *Template = QTN->getTemplateDecl(); 2679fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor assert(Template && "qualified template name must refer to a template"); 2680fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2681fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2682fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2683fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2684fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2685fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2686fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2687fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2688fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == QTN->getQualifier() && 2689fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2690fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2691fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2692fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), 2693fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate); 2694fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2695fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2696fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 2697fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SS.getScopeRep()) { 2698fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These apply to the scope specifier, not the template. 2699fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType = QualType(); 2700fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope = 0; 2701fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2702fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2703fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2704fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == DTN->getQualifier() && 2705fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType.isNull()) 2706fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2707fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2708fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DTN->isIdentifier()) { 2709fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, 2710fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor *DTN->getIdentifier(), 2711fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NameLoc, 2712fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType, 2713fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope); 2714fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2715fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2716fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, 2717fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType); 2718fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2719fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2720fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 2721fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2722fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2723fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2724fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2725fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2726fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2727fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2728fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2729fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2730fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2731fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(TransTemplate); 2732fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2733fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2734fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SubstTemplateTemplateParmPackStorage *SubstPack 2735fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack()) { 2736fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateTemplateParmDecl *TransParam 2737fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateTemplateParmDecl>( 2738fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); 2739fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransParam) 2740fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2741fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2742fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2743fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransParam == SubstPack->getParameterPack()) 2744fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2745fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2746fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(TransParam, 2747fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SubstPack->getArgumentPack()); 2748fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2749fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2750fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These should be getting filtered out before they reach the AST. 2751fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor llvm_unreachable("overloaded function decl survived to here"); 2752fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2753fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor} 2754fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2755fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived> 2756833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc( 2757833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg, 2758833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2759833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation Loc = getDerived().getBaseLocation(); 2760670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor switch (Arg.getKind()) { 2761670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Null: 27629f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("null template argument in TreeTransform"); 2763833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2764833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2765833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 2766833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, 2767a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); 2768c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2769833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2770833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2771788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 2772b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor case TemplateArgument::TemplateExpansion: { 2773b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLocBuilder Builder; 2774b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor TemplateName Template = Arg.getAsTemplate(); 2775b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) 2776b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); 2777b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 2778b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); 2779b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2780b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (Arg.getKind() == TemplateArgument::Template) 2781b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2782b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2783b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc); 2784b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else 2785b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2786b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2787b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc, Loc); 2788b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2789a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 2790b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2791a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2792833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 2793833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); 2794833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2795833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2796833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 2797670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Integral: 2798833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 2799828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); 2800833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2801833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2802833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2803833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2804833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived> 2805833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument( 2806833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc &Input, 2807833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2808833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg = Input.getArgument(); 2809833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 2810833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 2811833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 2812833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = Input; 2813833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 28141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2815670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Type: { 2816a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = Input.getTypeSourceInfo(); 2817833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (DI == NULL) 2818a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 2819833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2820833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DI = getDerived().TransformType(DI); 2821833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!DI) return true; 2822833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2823833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 2824833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2825670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 28261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2827670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Declaration: { 2828833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: we should never have to transform one of these. 2829972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor DeclarationName Name; 2830972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) 2831972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor Name = ND->getDeclName(); 2832788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemporaryBase Rebase(*this, Input.getLocation(), Name); 28337c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); 2834833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!D) return true; 2835833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2836828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Expr *SourceExpr = Input.getSourceDeclExpression(); 2837828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (SourceExpr) { 2838828bff2079b6a91ecd7ed5b842c59527d7682789John McCall EnterExpressionEvaluationContext Unevaluated(getSema(), 2839f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 284060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(SourceExpr); 28419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceExpr = (E.isInvalid() ? 0 : E.take()); 2842828bff2079b6a91ecd7ed5b842c59527d7682789John McCall } 2843828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 2844828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); 2845833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2846670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 28471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2848788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: { 2849b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); 2850b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (QualifierLoc) { 2851b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); 2852b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (!QualifierLoc) 2853b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor return true; 2854b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2855b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 28561d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 28571d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor SS.Adopt(QualifierLoc); 2858788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateName Template 28591d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), 28601d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor Input.getTemplateNameLoc()); 2861788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor if (Template.isNull()) 2862788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return true; 2863c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2864b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, 2865788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateNameLoc()); 2866788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return false; 2867788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 2868a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2869a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 2870a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor llvm_unreachable("Caller should expand pack expansions"); 2871a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2872670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Expression: { 2873670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Template argument expressions are not potentially evaluated. 28741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(getSema(), 2875f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2877833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Expr *InputExpr = Input.getSourceExpression(); 2878833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 2879833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2880223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner ExprResult E = getDerived().TransformExpr(InputExpr); 2881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (E.isInvalid()) return true; 28829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); 2883833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2884670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 28851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2886670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Pack: { 2887670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor llvm::SmallVector<TemplateArgument, 4> TransformedArgs; 2888670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor TransformedArgs.reserve(Arg.pack_size()); 28891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 2890670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor AEnd = Arg.pack_end(); 2891670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor A != AEnd; ++A) { 28921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2893833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: preserve source information here when we start 2894833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // caring about parameter packs. 2895833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2896828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc InputArg; 2897828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc OutputArg; 2898828bff2079b6a91ecd7ed5b842c59527d7682789John McCall getDerived().InventTemplateArgumentLoc(*A, InputArg); 2899828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) 2900833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2901833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2902828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TransformedArgs.push_back(OutputArg.getArgument()); 2903670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2904910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor 2905910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *TransformedArgsPtr 2906910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; 2907910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor std::copy(TransformedArgs.begin(), TransformedArgs.end(), 2908910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgsPtr); 2909910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, 2910910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgs.size()), 2911910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Input.getLocInfo()); 2912833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2913670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2914670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2916670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Work around bogus GCC warning 2917833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2918670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor} 2919670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 29207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information 29217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator. 29227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator> 29237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator { 29247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TreeTransform<Derived> &Self; 29257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter; 29267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic: 29287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 29297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 29307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef typename std::iterator_traits<InputIterator>::difference_type 29317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor difference_type; 29327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 29337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 29357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 2936fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 29377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 29387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 29397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { return &Arg; } 29417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 29427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator() { } 29447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 29467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter) 29477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Self(Self), Iter(Iter) { } 29487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator &operator++() { 29507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Iter; 29517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 2952fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor } 2953fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 29547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator operator++(int) { 29557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator Old(*this); 29567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 29577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 29587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 29597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor reference operator*() const { 29617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Result; 29627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Self.InventTemplateArgumentLoc(*Iter, Result); 29637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Result; 29647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 29657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { return pointer(**this); } 29677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocInventIterator &X, 29697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 29707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter == Y.Iter; 29717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 2972fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 29737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocInventIterator &X, 29747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 29757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter != Y.Iter; 29767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 29777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}; 29787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29797f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived> 29807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator> 29817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, 29827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 29837f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentListInfo &Outputs) { 29847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor for (; First != Last; ++First) { 29857f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentLoc Out; 29867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc In = *First; 29878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 29888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().getKind() == TemplateArgument::Pack) { 29898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Unpack argument packs, which we translate them into separate 29908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // arguments. 29917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // FIXME: We could do much better if we could guarantee that the 29927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // TemplateArgumentLocInfo for the pack expansion would be usable for 29937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // all of the template arguments in the argument pack. 29947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocInventIterator<Derived, 29957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgument::pack_iterator> 29967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator; 29977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (TransformTemplateArguments(PackLocIterator(*this, 29987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_begin()), 29997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator(*this, 30007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_end()), 30017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Outputs)) 30027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return true; 30038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().isPackExpansion()) { 30088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // We have a pack expansion, for which we will be substituting into 30098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // the pattern. 30108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation Ellipsis; 3011cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions; 30128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc Pattern 3013cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, 3014cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor getSema().Context); 30158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 30178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 30188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 30198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Determine whether the set of unexpanded parameter packs can and should 30218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // be expanded. 30228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool Expand = true; 3023d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3024cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 30258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TryExpandParameterPacks(Ellipsis, 30268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Pattern.getSourceRange(), 30278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Unexpanded.data(), 30288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Unexpanded.size(), 3029d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, 3030d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3031d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 30328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (!Expand) { 30358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform a simple 30368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // transformation on the pack expansion, producing another pack 30378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion. 30388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc OutPattern; 30398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 30408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) 30418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3043cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 3044cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 30458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (Out.getArgument().isNull()) 30468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 30498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform an elementwise 30538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion of the pattern. Do so. 3054cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 30558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 30568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 30588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 306077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().containsUnexpandedParameterPack()) { 3061cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3062cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 306377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().isNull()) 306477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 306577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 306677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 30678491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 30688491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30703cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 30713cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 30723cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 30733cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 30743cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 30753cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 30763cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 30773cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 3078cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3079cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 30803cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (Out.getArgument().isNull()) 30813cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 30823cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 30833cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor Outputs.addArgument(Out); 30843cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 3085d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 30868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The simple case: 30908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(In, Out)) 30917f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return true; 30927f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 30937f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor Outputs.addArgument(Out); 30947f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor } 30957f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 30967f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return false; 30977f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 30987f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor} 30997f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 3100577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3101577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation 3102577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3103577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3104577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 310543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) { 3106577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3107577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T; 31081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3109a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Temporary workaround. All of these transformations should 3110a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // eventually turn into transformations on TypeLocs. 3111c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 3112c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor getDerived().getBaseLocation()); 3113c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 311443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *NewDI = getDerived().TransformType(DI); 31151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3116a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (!NewDI) 3117a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 31181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3119a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return NewDI->getType(); 3120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 312343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 3124a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlreadyTransformed(DI->getType())) 3125a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return DI; 31261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder TLB; 31281bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 3129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLoc TL = DI->getTypeLoc(); 3130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TLB.reserve(TL.getFullDataSize()); 31311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 313243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, TL); 3133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return 0; 31351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3136a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3140a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 314143fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 3142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall switch (T.getTypeLocClass()) { 3143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 3144a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 3145a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall case TypeLoc::CLASS: \ 314643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); 3147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 3148a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 31509f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unhandled type loc!"); 3151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types 3155a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers 3156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function 3157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but 3158a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients. 31591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 31601eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3161a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 316243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualifiedTypeLoc T) { 3163a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Quals = T.getType().getLocalQualifiers(); 3164a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 316543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 3166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3167577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 31681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3169a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Silently suppress qualifiers if the result type can't be qualified. 3170a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: this is the right thing for template instantiation, but 3171a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // probably not for other clients. 3172a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result->isFunctionType() || Result->isReferenceType()) 3173a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 31741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3175f85e193739c953358c865005855253af4f68a497John McCall // Suppress Objective-C lifetime qualifiers if they don't make sense for the 3176e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // resulting type. 3177e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (Quals.hasObjCLifetime()) { 3178e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (!Result->isObjCLifetimeType() && !Result->isDependentType()) 3179e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 31804020caec546d221170072d2388b57d151cb26111Douglas Gregor else if (Result.getObjCLifetime()) { 3181e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // Objective-C ARC: 3182e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // A lifetime qualifier applied to a substituted template parameter 3183e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // overrides the lifetime qualifier from the template argument. 3184e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (const SubstTemplateTypeParmType *SubstTypeParam 3185e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = dyn_cast<SubstTemplateTypeParmType>(Result)) { 3186e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor QualType Replacement = SubstTypeParam->getReplacementType(); 3187e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qualifiers Qs = Replacement.getQualifiers(); 3188e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs.removeObjCLifetime(); 3189e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement 3190e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), 3191e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs); 3192e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Result = SemaRef.Context.getSubstTemplateTypeParmType( 3193e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor SubstTypeParam->getReplacedParameter(), 3194e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement); 3195e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor TLB.TypeWasModifiedSafely(Result); 3196e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } else { 31974020caec546d221170072d2388b57d151cb26111Douglas Gregor // Otherwise, complain about the addition of a qualifier to an 31984020caec546d221170072d2388b57d151cb26111Douglas Gregor // already-qualified type. 31994020caec546d221170072d2388b57d151cb26111Douglas Gregor SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); 32004020caec546d221170072d2388b57d151cb26111Douglas Gregor SemaRef.Diag(R.getBegin(), diag::err_attr_objc_lifetime_redundant) 32014020caec546d221170072d2388b57d151cb26111Douglas Gregor << Result << R; 32024020caec546d221170072d2388b57d151cb26111Douglas Gregor 3203e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 3204e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3205e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3206e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 32072865474261a608c7873b87ba4af110d17907896dJohn McCall if (!Quals.empty()) { 32082865474261a608c7873b87ba4af110d17907896dJohn McCall Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); 32092865474261a608c7873b87ba4af110d17907896dJohn McCall TLB.push<QualifiedTypeLoc>(Result); 32102865474261a608c7873b87ba4af110d17907896dJohn McCall // No location information to preserve. 32112865474261a608c7873b87ba4af110d17907896dJohn McCall } 3212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3214a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 321643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 3217b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc 3218b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 321943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 322043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 3221b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS) { 3222b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TL.getType(); 322343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 3224b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TL; 3225b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 322643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder TLB; 322743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result; 3228b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 322943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (isa<TemplateSpecializationType>(T)) { 3230b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateSpecializationTypeLoc SpecTL 3231b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3232b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 323343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template = 3234b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor getDerived().TransformTemplateName(SS, 3235b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3236b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTemplateNameLoc(), 323743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, UnqualLookup); 3238b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Template.isNull()) 3239b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3240b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3241b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3242b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Template); 324343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else if (isa<DependentTemplateSpecializationType>(T)) { 3244b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3245b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3246a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3247b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3248b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().RebuildTemplateName(SS, 3249b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 3250b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getNameLoc(), 3251b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, UnqualLookup); 3252a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3253b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3254b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3255b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3256b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL, 3257087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3258087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 325943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else { 326043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // Nothing special needs to be done for these. 3261b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformType(TLB, TL); 326243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 3263b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3264b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Result.isNull()) 3265b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3266b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3267b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); 326843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 326943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 3270c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 3271b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo * 3272b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 3273c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 3274c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *UnqualLookup, 3275c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS) { 3276c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // FIXME: Painfully copy-paste from the above! 3277c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3278b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TSInfo->getType(); 3279c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3280b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TSInfo; 3281c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3282c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLocBuilder TLB; 3283c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType Result; 3284c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3285b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeLoc TL = TSInfo->getTypeLoc(); 3286c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (isa<TemplateSpecializationType>(T)) { 3287c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TemplateSpecializationTypeLoc SpecTL 3288c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3289c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3290b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3291b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().TransformTemplateName(SS, 3292fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3293fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTemplateNameLoc(), 3294c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, UnqualLookup); 3295c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Template.isNull()) 3296b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3297c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3298c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3299c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Template); 3300c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else if (isa<DependentTemplateSpecializationType>(T)) { 3301c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3302c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3303c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3304a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template 3305fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, 33067c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 3307fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getNameLoc(), 33087c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, UnqualLookup); 3309a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3310b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3311a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3312c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3313a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor SpecTL, 3314087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3315087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 3316c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else { 3317c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Nothing special needs to be done for these. 3318c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformType(TLB, TL); 3319c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 3320c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3321c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Result.isNull()) 3322b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3323c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3324b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3325c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 3326c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3327a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline 3328a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 3329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TyLoc NewT = TLB.push<TyLoc>(T.getType()); 3330a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewT.setNameLoc(T.getNameLoc()); 3331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return T.getType(); 3332a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3333a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3334a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3335a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 333643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BuiltinTypeLoc T) { 3337ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 3338ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.setBuiltinLoc(T.getBuiltinLoc()); 3339ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (T.needsExtraLocalData()) 3340ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 3341ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return T.getType(); 3342577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3343577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 33441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3345a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 334643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ComplexTypeLoc T) { 3347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: recurse? 3348a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, T); 3349a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 33501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3351a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3352a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 335343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall PointerTypeLoc TL) { 3354c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType PointeeType 3355c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 335692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (PointeeType.isNull()) 335792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 335892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 335992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor QualType Result = TL.getType(); 3360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (PointeeType->getAs<ObjCObjectType>()) { 336192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // A dependent pointer type 'T *' has is being transformed such 336292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // that an Objective-C class type is being replaced for 'T'. The 336392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // resulting pointer type is an ObjCObjectPointerType, not a 336492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // PointerType. 3365c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 3366c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3367c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 3368c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NewT.setStarLoc(TL.getStarLoc()); 336992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return Result; 337092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 337143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 337292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (getDerived().AlwaysRebuild() || 337392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointeeType != TL.getPointeeLoc().getType()) { 337492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 337592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Result.isNull()) 337692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 337792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 3378f85e193739c953358c865005855253af4f68a497John McCall 3379f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3380f85e193739c953358c865005855253af4f68a497John McCall // pointing to. 3381f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely(Result->getPointeeType()); 3382f85e193739c953358c865005855253af4f68a497John McCall 338392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 338492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3385c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Result; 3386577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3387577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 33881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 33891eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3390a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 339143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BlockPointerTypeLoc TL) { 3392db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor QualType PointeeType 3393c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3394c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (PointeeType.isNull()) 3395c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return QualType(); 3396c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3397c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType Result = TL.getType(); 3398c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getDerived().AlwaysRebuild() || 3399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt PointeeType != TL.getPointeeLoc().getType()) { 3400c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Result = getDerived().RebuildBlockPointerType(PointeeType, 3401db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor TL.getSigilLoc()); 3402db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor if (Result.isNull()) 3403db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return QualType(); 3404db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor } 3405db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor 340639968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 3407db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3408db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return Result; 3409a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 341185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type. Note that somewhat paradoxically we 341285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value 341385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type; we only care if the type was *written* as an l-value type 341485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type. 341585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived> 341685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType 341785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 341843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ReferenceTypeLoc TL) { 341985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall const ReferenceType *T = TL.getTypePtr(); 342085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 342185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // Note that this works with the pointee-as-written. 342285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 342385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (PointeeType.isNull()) 342485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 342585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 342685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType Result = TL.getType(); 342785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (getDerived().AlwaysRebuild() || 342885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall PointeeType != T->getPointeeTypeAsWritten()) { 342985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildReferenceType(PointeeType, 343085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->isSpelledAsLValue(), 343185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getSigilLoc()); 343285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (Result.isNull()) 343385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 343485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 343585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3436f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3437f85e193739c953358c865005855253af4f68a497John McCall // referring to. 3438f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely( 3439f85e193739c953358c865005855253af4f68a497John McCall Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); 3440f85e193739c953358c865005855253af4f68a497John McCall 344185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // r-value references can be rebuilt as l-value references. 344285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall ReferenceTypeLoc NewTL; 344385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (isa<LValueReferenceType>(Result)) 344485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 344585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall else 344685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 344785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 344885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 344985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return Result; 345085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall} 345185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3452a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3453a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3454a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 345543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall LValueReferenceTypeLoc TL) { 345643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3457a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3459a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3460a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3461a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 346243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RValueReferenceTypeLoc TL) { 346343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3464577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 34651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 34671eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 346943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall MemberPointerTypeLoc TL) { 3470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3471577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (PointeeType.isNull()) 3472577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 34731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3474b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); 3475b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* NewClsTInfo = 0; 3476b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (OldClsTInfo) { 3477b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsTInfo = getDerived().TransformType(OldClsTInfo); 3478b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (!NewClsTInfo) 3479b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3480b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 3481b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 3482b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const MemberPointerType *T = TL.getTypePtr(); 3483b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType OldClsType = QualType(T->getClass(), 0); 3484b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType NewClsType; 3485b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsTInfo) 3486b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = NewClsTInfo->getType(); 3487b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara else { 3488b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = getDerived().TransformType(OldClsType); 3489b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsType.isNull()) 3490b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3491b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 34921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3493a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3494a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall PointeeType != T->getPointeeType() || 3496b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType != OldClsType) { 3497b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, 349885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getStarLoc()); 3499a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3500a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3502577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3503a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 3504a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 3505b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewTL.setClassTInfo(NewClsTInfo); 3506a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3507a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3508577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3509577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 35101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 35111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 351343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ConstantArrayTypeLoc TL) { 3514f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ConstantArrayType *T = TL.getTypePtr(); 3515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3517577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3519a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3521a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3522a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildConstantArrayType(ElementType, 3523a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 3524a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSize(), 352585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 352685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3527a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3528a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3529a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3530c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3531a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); 3532a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3533a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 35341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = TL.getSizeExpr(); 3536a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Size) { 3537f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3538a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); 3539a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3540a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3541a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3542a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3543577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3545577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3546577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType( 3547a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 354843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall IncompleteArrayTypeLoc TL) { 3549f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const IncompleteArrayType *T = TL.getTypePtr(); 3550a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3551577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3554a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3555a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3556a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3557a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildIncompleteArrayType(ElementType, 3558a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 355985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 356085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3561a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3562a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3563a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3564c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3565a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 3566a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3568a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(0); 3569577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3570a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3574a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3575a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 357643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VariableArrayTypeLoc TL) { 3577f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VariableArrayType *T = TL.getTypePtr(); 3578a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3582670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Array bounds are not potentially evaluated contexts 3583f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3584670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 358560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3586a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3587a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Size = SizeResult.take(); 3591a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3592a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3593a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3594a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3595a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3596a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildVariableArrayType(ElementType, 3597a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 35989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3599a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 360085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3601a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3602a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3603577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3604c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3605a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); 3606a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3607a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3608a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 36091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3610a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3611577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3614a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3615a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 361643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedArrayTypeLoc TL) { 3617f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedArrayType *T = TL.getTypePtr(); 3618a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3619577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3622670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Array bounds are not potentially evaluated contexts 3623f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 36241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Prefer the expression from the TypeLoc; the other may have been uniqued. 36263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *origSize = TL.getSizeExpr(); 36273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!origSize) origSize = T->getSizeExpr(); 36283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 36293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExprResult sizeResult 36303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = getDerived().TransformExpr(origSize); 36313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (sizeResult.isInvalid()) 3632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *size = sizeResult.get(); 3635a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3636a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3637a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3638a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 36393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size != origSize) { 3640a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedArrayType(ElementType, 3641a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 36423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size, 3643a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 364485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3645a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3646a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 36481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3649a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // We might have any sort of array type now, but fortunately they 3650a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // all have the same location layout. 3651a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3652a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3653a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 36543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall NewTL.setSizeExpr(size); 3655a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3656a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3660577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 3661a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 366243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedExtVectorTypeLoc TL) { 3663f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedExtVectorType *T = TL.getTypePtr(); 3664a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3665a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: ext vector locs should be nested 3666577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3670670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Vector sizes are not potentially evaluated contexts 3671f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3672670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 367360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 3674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size.isInvalid()) 3675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3677a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3678a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3679eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall ElementType != T->getElementType() || 3680eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall Size.get() != T->getSizeExpr()) { 3681a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 36829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size.take(), 3683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor T->getAttributeLoc()); 3684a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3685a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3686a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3687a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Result might be dependent or not. 3689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (isa<DependentSizedExtVectorType>(Result)) { 3690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorTypeLoc NewTL 3691a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 3692a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3697a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3698a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3702a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 370343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VectorTypeLoc TL) { 3704f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3705577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3706577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3707577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3708577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3709a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 371282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 3713e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson T->getVectorKind()); 3714a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3715a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3717c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 3719a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 37201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3721a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3722577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3725a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 372643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ExtVectorTypeLoc TL) { 3727f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3729577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3730577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3732a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3733a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3734a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3735a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildExtVectorType(ElementType, 3736a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getNumElements(), 3737a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /*FIXME*/ SourceLocation()); 3738a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3739a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3740a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3741c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3743a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 37441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3745a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3746577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3747577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 37481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 374921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl * 37506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, 3751fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 37526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 375321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 37546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeSourceInfo *NewDI = 0; 37556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 37576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor // If we're substituting into a pack expansion type and we know the 37586a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc OldTL = OldDI->getTypeLoc(); 37596a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); 37606a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37616a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLocBuilder TLB; 37626a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc NewTL = OldDI->getTypeLoc(); 37636a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TLB.reserve(NewTL.getFullDataSize()); 37646a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37656a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor QualType Result = getDerived().TransformType(TLB, 37666a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc()); 37676a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 37686a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 37696a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37706a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor Result = RebuildPackExpansionType(Result, 37716a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc().getSourceRange(), 37726a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getEllipsisLoc(), 37736a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions); 37746a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 37756a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 37766a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37776a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc NewExpansionTL 37786a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = TLB.push<PackExpansionTypeLoc>(Result); 37796a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 37806a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 37816a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor } else 37826a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = getDerived().TransformType(OldDI); 378321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewDI) 378421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return 0; 378521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 3786fb44de956f27875def889482b5393475060392afJohn McCall if (NewDI == OldDI && indexAdjustment == 0) 378721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return OldParm; 3788fb44de956f27875def889482b5393475060392afJohn McCall 3789fb44de956f27875def889482b5393475060392afJohn McCall ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, 3790fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getDeclContext(), 3791fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getInnerLocStart(), 3792fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getLocation(), 3793fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getIdentifier(), 3794fb44de956f27875def889482b5393475060392afJohn McCall NewDI->getType(), 3795fb44de956f27875def889482b5393475060392afJohn McCall NewDI, 3796fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClass(), 3797fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClassAsWritten(), 3798fb44de956f27875def889482b5393475060392afJohn McCall /* DefArg */ NULL); 3799fb44de956f27875def889482b5393475060392afJohn McCall newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), 3800fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getFunctionScopeIndex() + indexAdjustment); 3801fb44de956f27875def889482b5393475060392afJohn McCall return newParm; 380221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 380321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 380421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 380521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>:: 3806a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TransformFunctionTypeParams(SourceLocation Loc, 3807a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 3808a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 3809a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor llvm::SmallVectorImpl<QualType> &OutParamTypes, 3810a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor llvm::SmallVectorImpl<ParmVarDecl*> *PVars) { 3811fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment = 0; 3812fb44de956f27875def889482b5393475060392afJohn McCall 3813a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor for (unsigned i = 0; i != NumParams; ++i) { 3814a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (ParmVarDecl *OldParm = Params[i]) { 3815fb44de956f27875def889482b5393475060392afJohn McCall assert(OldParm->getFunctionScopeIndex() == i); 3816fb44de956f27875def889482b5393475060392afJohn McCall 38176a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3818406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor ParmVarDecl *NewParm = 0; 3819603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (OldParm->isParameterPack()) { 3820603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3821603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3822603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3823603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Find the parameter packs that could be expanded. 3824c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 3825c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); 3826c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc Pattern = ExpansionTL.getPatternLoc(); 3827c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 3828406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); 3829406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 3830603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3831603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3832d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 38336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions 38346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 38356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions = OrigNumExpansions; 3836c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 3837c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor Pattern.getSourceRange(), 3838603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Unexpanded.data(), 3839603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Unexpanded.size(), 3840d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 3841d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3842d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 3843603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3844603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3845603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3846603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 3847603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 3848603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 384912c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor getDerived().ExpandingFunctionParameterPack(OldParm); 3850cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 3851603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 3852603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor ParmVarDecl *NewParm 38536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 3854fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 38556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OrigNumExpansions); 3856603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (!NewParm) 3857603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3858603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3859a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3860a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3861a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3862603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3863d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3864d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 3865d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // forgetting the partially-substituted parameter pack. 3866d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (RetainExpansion) { 3867d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 3868d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ParmVarDecl *NewParm 38696a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 3870fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 38716a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OrigNumExpansions); 3872d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!NewParm) 3873d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return true; 3874d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3875d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor OutParamTypes.push_back(NewParm->getType()); 3876d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (PVars) 3877d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor PVars->push_back(NewParm); 3878d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 3879d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3880fb44de956f27875def889482b5393475060392afJohn McCall // The next parameter should have the same adjustment as the 3881fb44de956f27875def889482b5393475060392afJohn McCall // last thing we pushed, but we post-incremented indexAdjustment 3882fb44de956f27875def889482b5393475060392afJohn McCall // on every push. Also, if we push nothing, the adjustment should 3883fb44de956f27875def889482b5393475060392afJohn McCall // go down by one. 3884fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment--; 3885fb44de956f27875def889482b5393475060392afJohn McCall 3886603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 3887603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3888603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3889603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3890603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 3891603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 3892406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 3893406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 3894fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 3895406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NumExpansions); 3896406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 3897406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 3898fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 3899406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor llvm::Optional<unsigned>()); 3900603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3901406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 390221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewParm) 390321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3904603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3905a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3906a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3907a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3908603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3909603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3910a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3911a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Deal with the possibility that we don't have a parameter 3912a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // declaration for this parameter. 3913a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor QualType OldType = ParamTypes[i]; 3914603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool IsPackExpansion = false; 3915cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3916406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor QualType NewType; 3917603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (const PackExpansionType *Expansion 3918603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor = dyn_cast<PackExpansionType>(OldType)) { 3919603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3920603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType Pattern = Expansion->getPattern(); 3921603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3922603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 3923603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3924603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3925603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3926d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3927a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 3928603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Unexpanded.data(), 3929603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Unexpanded.size(), 3930d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 3931d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3932d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 393321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3934603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3935603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3936603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 3937603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 3938603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 3939cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 3940603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 3941603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType NewType = getDerived().TransformType(Pattern); 3942603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 3943603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3944603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3945a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 3946a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3947a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 3948603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3949603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3950603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 3951603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3952603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3953603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 39543cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 39553cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 39563cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 39573cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 39583cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor QualType NewType = getDerived().TransformType(Pattern); 39593cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (NewType.isNull()) 39603cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 39613cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 39623cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor OutParamTypes.push_back(NewType); 39633cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (PVars) 39643cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor PVars->push_back(0); 39653cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 3966d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3967603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 3968603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 3969603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor OldType = Expansion->getPattern(); 3970603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor IsPackExpansion = true; 3971406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 3972406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 3973406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 3974406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 3975a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3976603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3977603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 3978603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 39791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3980603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (IsPackExpansion) 3981cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NewType = getSema().Context.getPackExpansionType(NewType, 3982cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 3983603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3984a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 3985a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3986a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 3987577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 39881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3989fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG 3990fb44de956f27875def889482b5393475060392afJohn McCall if (PVars) { 3991fb44de956f27875def889482b5393475060392afJohn McCall for (unsigned i = 0, e = PVars->size(); i != e; ++i) 3992fb44de956f27875def889482b5393475060392afJohn McCall if (ParmVarDecl *parm = (*PVars)[i]) 3993fb44de956f27875def889482b5393475060392afJohn McCall assert(parm->getFunctionScopeIndex() == i); 3994603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3995fb44de956f27875def889482b5393475060392afJohn McCall#endif 3996fb44de956f27875def889482b5393475060392afJohn McCall 3997fb44de956f27875def889482b5393475060392afJohn McCall return false; 3998fb44de956f27875def889482b5393475060392afJohn McCall} 399921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 400021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 400121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType 400221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 400343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionProtoTypeLoc TL) { 40047e010a04fef171049291d8cb3047f118566da090Douglas Gregor // Transform the parameters and return type. 40057e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 40067e010a04fef171049291d8cb3047f118566da090Douglas Gregor // We instantiate in source order, with the return type first followed by 40077e010a04fef171049291d8cb3047f118566da090Douglas Gregor // the parameters, because users tend to expect this (even if they shouldn't 40087e010a04fef171049291d8cb3047f118566da090Douglas Gregor // rely on it!). 40097e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 4010dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // When the function has a trailing return type, we instantiate the 4011dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // parameters before the return type, since the return type can then refer 4012dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // to the parameters themselves (via decltype, sizeof, etc.). 4013dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 401421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVector<QualType, 4> ParamTypes; 401521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; 4016f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionProtoType *T = TL.getTypePtr(); 40177e010a04fef171049291d8cb3047f118566da090Douglas Gregor 4018dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor QualType ResultType; 4019dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4020dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (TL.getTrailingReturn()) { 4021a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4022a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4023a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4024a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4025a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4026dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4027dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4028dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4029dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4030dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4031dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4032dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor else { 4033dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4034dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4035dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4036dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4037a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4038a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4039a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4040a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4041a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4042dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4043dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4044dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4045a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4046a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4047a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType() || 4048bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor T->getNumArgs() != ParamTypes.size() || 4049a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { 4050a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionProtoType(ResultType, 4051a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.data(), 4052a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.size(), 4053a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->isVariadic(), 4054fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getTypeQuals(), 4055c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor T->getRefQualifier(), 4056fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getExtInfo()); 4057a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4058a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4059a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 40601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4061a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 4062796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4063796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4064dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(TL.getTrailingReturn()); 4065a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) 4066a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setArg(i, ParamDecls[i]); 4067a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4068a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4069577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 40701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4071577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4072577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType( 4073a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 407443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionNoProtoTypeLoc TL) { 4075f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionNoProtoType *T = TL.getTypePtr(); 4076a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4077a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (ResultType.isNull()) 4078a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4079a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4080a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4081a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4082a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType()) 4083a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionNoProtoType(ResultType); 4084a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4085a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 4086796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4087796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4088dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(false); 4089a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4090a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4091577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 40921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4093ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType 4094ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 409543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnresolvedUsingTypeLoc TL) { 4096f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const UnresolvedUsingType *T = TL.getTypePtr(); 40977c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 4098ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (!D) 4099ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4100ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4101ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType Result = TL.getType(); 4102ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 4103ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Result = getDerived().RebuildUnresolvedUsingType(D); 4104ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Result.isNull()) 4105ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4106ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 4107ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4108ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // We might get an arbitrary type spec type back. We should at 4109ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // least always get a type spec type, though. 4110ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 4111ed97649e9574b9d854fa4d6109c9333ae0993554John McCall NewTL.setNameLoc(TL.getNameLoc()); 4112ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4113ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Result; 4114ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 4115ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4117a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 411843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypedefTypeLoc TL) { 4119f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypedefType *T = TL.getTypePtr(); 4120162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Typedef 4121162e1c1b487352434552147967c3dd296ebee2f7Richard Smith = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), 4122162e1c1b487352434552147967c3dd296ebee2f7Richard Smith T->getDecl())); 4123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Typedef) 4124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 41251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4126a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4128a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Typedef != T->getDecl()) { 4129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildTypedefType(Typedef); 4130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 4135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 41361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4137a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4141a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 414243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfExprTypeLoc TL) { 4143670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // typeof expressions are not potentially evaluated contexts 4144f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 41451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 414660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 4147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 4149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4152cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall E.get() != TL.getUnderlyingExpr()) { 41532a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 4154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4155a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4156577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 41581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 4160cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4161cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4162cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4163a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4164a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4165577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4168a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 416943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfTypeLoc TL) { 4170cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 4171cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 4172cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (!New_Under_TI) 4173577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 41741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4175a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4176cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 4177cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 4178a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4179a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4180a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 41811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4182a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 4183cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4184cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4185cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4186cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setUnderlyingTInfo(New_Under_TI); 4187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4188a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4192a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 419343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DecltypeTypeLoc TL) { 4194f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DecltypeType *T = TL.getTypePtr(); 4195a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4196670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // decltype expressions are not potentially evaluated contexts 4197f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 41981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 419960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 4200577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4201577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall E.get() != T->getUnderlyingExpr()) { 42062a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 4207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4209577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 4211a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 4213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 42141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4216577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4217577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4218577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4219ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType( 4220ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeLocBuilder &TLB, 4221ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc TL) { 4222ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType Result = TL.getType(); 4223ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result->isDependentType()) { 4224ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const UnaryTransformType *T = TL.getTypePtr(); 4225ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType NewBase = 4226ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); 4227ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Result = getDerived().RebuildUnaryTransformType(NewBase, 4228ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt T->getUTTKind(), 4229ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.getKWLoc()); 4230ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result.isNull()) 4231ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(); 4232ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4233ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4234ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); 4235ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setKWLoc(TL.getKWLoc()); 4236ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setParensRange(TL.getParensRange()); 4237ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); 4238ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return Result; 4239ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 4240ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4241ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 424234b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 424334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc TL) { 424434b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *T = TL.getTypePtr(); 424534b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType OldDeduced = T->getDeducedType(); 424634b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType NewDeduced; 424734b41d939a1328f484511c6002ba2456db879a29Richard Smith if (!OldDeduced.isNull()) { 424834b41d939a1328f484511c6002ba2456db879a29Richard Smith NewDeduced = getDerived().TransformType(OldDeduced); 424934b41d939a1328f484511c6002ba2456db879a29Richard Smith if (NewDeduced.isNull()) 425034b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 425134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 425234b41d939a1328f484511c6002ba2456db879a29Richard Smith 425334b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Result = TL.getType(); 425434b41d939a1328f484511c6002ba2456db879a29Richard Smith if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { 425534b41d939a1328f484511c6002ba2456db879a29Richard Smith Result = getDerived().RebuildAutoType(NewDeduced); 425634b41d939a1328f484511c6002ba2456db879a29Richard Smith if (Result.isNull()) 425734b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 425834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 425934b41d939a1328f484511c6002ba2456db879a29Richard Smith 426034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 426134b41d939a1328f484511c6002ba2456db879a29Richard Smith NewTL.setNameLoc(TL.getNameLoc()); 426234b41d939a1328f484511c6002ba2456db879a29Richard Smith 426334b41d939a1328f484511c6002ba2456db879a29Richard Smith return Result; 426434b41d939a1328f484511c6002ba2456db879a29Richard Smith} 426534b41d939a1328f484511c6002ba2456db879a29Richard Smith 426634b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived> 4267a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 426843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RecordTypeLoc TL) { 4269f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const RecordType *T = TL.getTypePtr(); 4270577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor RecordDecl *Record 42717c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 42727c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4273577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Record) 4274577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4276a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Record != T->getDecl()) { 4279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildRecordType(Record); 4280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 42831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 4285a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 4286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4288577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 429243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall EnumTypeLoc TL) { 4293f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const EnumType *T = TL.getTypePtr(); 4294577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor EnumDecl *Enum 42957c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 42967c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4297577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Enum) 4298577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4300a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4302a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Enum != T->getDecl()) { 4303a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildEnumType(Enum); 4304a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4305a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4306a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4307a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 4309a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 43101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4311a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4312577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43137da2431c23ef1ee8acb114e39692246e1801afc2John McCall 43143cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived> 43153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType( 43163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeLocBuilder &TLB, 431743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall InjectedClassNameTypeLoc TL) { 43183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 43193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.getTypePtr()->getDecl()); 43203cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!D) return QualType(); 43213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 43223cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 43233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 43243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T; 43253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 43263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 4327577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4328577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType( 4329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 433043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateTypeParmTypeLoc TL) { 4331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 4332577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4333577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 43341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 433549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 4336a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 433743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SubstTemplateTypeParmTypeLoc TL) { 43380b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor const SubstTemplateTypeParmType *T = TL.getTypePtr(); 43390b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 43400b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Substitute into the replacement type, which itself might involve something 43410b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // that needs to be transformed. This only tends to occur with default 43420b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // template arguments of template template parameters. 43430b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); 43440b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Replacement = getDerived().TransformType(T->getReplacementType()); 43450b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor if (Replacement.isNull()) 43460b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return QualType(); 43470b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 43480b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Always canonicalize the replacement type. 43490b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement = SemaRef.Context.getCanonicalType(Replacement); 43500b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Result 43510b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), 43520b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement); 43530b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 43540b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Propagate type-source information. 43550b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor SubstTemplateTypeParmTypeLoc NewTL 43560b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); 43570b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 43580b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return Result; 43590b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 436049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 436149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 436249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived> 4363c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 4364c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TypeLocBuilder &TLB, 4365c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 4366c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TransformTypeSpecType(TLB, TL); 4367c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 4368c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 4369c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived> 4370833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 437143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder &TLB, 437243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL) { 437343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall const TemplateSpecializationType *T = TL.getTypePtr(); 4374828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 43751d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // The nested-name-specifier never matters in a TemplateSpecializationType, 43761d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // because we can't have a dependent nested-name-specifier anyway. 43771d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 437843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template 43791d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, T->getTemplateName(), 43801d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor TL.getTemplateNameLoc()); 438143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) 438243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4383833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 438443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 4385dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor} 438643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 43877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace { 43887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \brief Simple iterator that traverses the template arguments in a 43897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// container that provides a \c getArgLoc() member function. 43907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 43917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// This iterator is intended to be used with the iterator form of 43927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \c TreeTransform<Derived>::TransformTemplateArguments(). 43937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename ArgLocContainer> 43947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class TemplateArgumentLocContainerIterator { 43957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgLocContainer *Container; 43967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index; 43977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 43997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 44007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 44017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef int difference_type; 44027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 44037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 44057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 44067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 44087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 44097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { 44117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return &Arg; 44127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 44137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 44147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator() {} 44177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 44197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index) 44207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Container(&Container), Index(Index) { } 44217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator &operator++() { 44237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Index; 44247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 44257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 44267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator operator++(int) { 44287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator Old(*this); 44297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 44307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 44317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 44327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc operator*() const { 44347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Container->getArgLoc(Index); 44357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 44367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { 44387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return pointer(Container->getArgLoc(Index)); 44397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 44407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocContainerIterator &X, 4442f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 44437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Container == Y.Container && X.Index == Y.Index; 44447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 44457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 4447f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 44487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return !(X == Y); 44497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 44507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 44517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor} 44527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 445443fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived> 4455577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 4456833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TypeLocBuilder &TLB, 4457833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc TL, 445843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template) { 4459d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo NewTemplateArgs; 4460d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4461d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 44627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 44637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator; 44647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 44657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 44667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 44677f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 44681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4469833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: maybe don't rebuild if all the template arguments are the same. 4470833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 4471833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType Result = 4472833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().RebuildTemplateSpecializationType(Template, 4473833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TL.getTemplateNameLoc(), 4474d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs); 44751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4476833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!Result.isNull()) { 44773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Specializations of template template parameters are represented as 44783e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // TemplateSpecializationTypes, and substitution of type alias templates 44793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // within a dependent context can transform them into 44803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // DependentTemplateSpecializationTypes. 44813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isa<DependentTemplateSpecializationType>(Result)) { 44823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith DependentTemplateSpecializationTypeLoc NewTL 44833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 44843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setKeywordLoc(TL.getTemplateNameLoc()); 44853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setQualifierLoc(NestedNameSpecifierLoc()); 44863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setNameLoc(TL.getTemplateNameLoc()); 44873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setLAngleLoc(TL.getLAngleLoc()); 44883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setRAngleLoc(TL.getRAngleLoc()); 44893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 44903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 44913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return Result; 44923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 44933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4494833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc NewTL 4495833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = TLB.push<TemplateSpecializationTypeLoc>(Result); 4496833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4497833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setLAngleLoc(TL.getLAngleLoc()); 4498833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setRAngleLoc(TL.getRAngleLoc()); 4499833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4500833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4501833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 45021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4503833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Result; 4504577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 45051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4506a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived> 4507a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 4508a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TypeLocBuilder &TLB, 4509a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 4510087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 4511087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS) { 4512a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 4513a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4514a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 4515a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor typedef TemplateArgumentLocContainerIterator< 4516a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 4517a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 4518a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 4519a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs)) 4520a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4521a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4522a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor // FIXME: maybe don't rebuild if all the template arguments are the same. 4523a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4524a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 4525a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4526a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getSema().Context.getDependentTemplateSpecializationType( 4527a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getKeyword(), 4528a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getQualifier(), 4529a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getIdentifier(), 4530a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4531a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4532a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc NewTL 4533a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4534a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 453594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 453694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); 4537a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 4538a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4539a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4540a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4541a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4542a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4543a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4544a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4545a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4546a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getDerived().RebuildTemplateSpecializationType(Template, 4547a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getNameLoc(), 4548a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4549a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4550a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (!Result.isNull()) { 4551a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor /// FIXME: Wrap this in an elaborated-type-specifier? 4552a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateSpecializationTypeLoc NewTL 4553a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4554a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setTemplateNameLoc(TL.getNameLoc()); 4555a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4556a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4557a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4558a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4559a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4560a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4561a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4562a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor} 4563a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 45641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4565a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4566465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 456743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ElaboratedTypeLoc TL) { 4568f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ElaboratedType *T = TL.getTypePtr(); 4569465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 45709e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 4571465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // NOTE: the qualifier in an ElaboratedType is optional. 45729e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (TL.getQualifierLoc()) { 45739e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc 45749e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 45759e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (!QualifierLoc) 4576465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return QualType(); 4577465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 45781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 457943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 458043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NamedT.isNull()) 458143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4582a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar 45833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // C++0x [dcl.type.elab]p2: 45843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the identifier resolves to a typedef-name or the simple-template-id 45853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // resolves to an alias template specialization, the 45863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // elaborated-type-specifier is ill-formed. 45871804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { 45881804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (const TemplateSpecializationType *TST = 45891804174e1591bf59118f317775b48edd0382c3f0Richard Smith NamedT->getAs<TemplateSpecializationType>()) { 45901804174e1591bf59118f317775b48edd0382c3f0Richard Smith TemplateName Template = TST->getTemplateName(); 45911804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (TypeAliasTemplateDecl *TAT = 45921804174e1591bf59118f317775b48edd0382c3f0Richard Smith dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { 45931804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), 45941804174e1591bf59118f317775b48edd0382c3f0Richard Smith diag::err_tag_reference_non_tag) << 4; 45951804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); 45961804174e1591bf59118f317775b48edd0382c3f0Richard Smith } 45973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 45983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 45993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4600a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4601a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 46029e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc != TL.getQualifierLoc() || 4603e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NamedT != T->getNamedType()) { 460421e413fe6305a198564d436ac515497716c47844John McCall Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), 46059e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor T->getKeyword(), 46069e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc, NamedT); 4607a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4608a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4609a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4611465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4612e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 46139e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4614a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 46161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 46171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 46189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType( 46199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall TypeLocBuilder &TLB, 46209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc TL) { 46219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall const AttributedType *oldType = TL.getTypePtr(); 46229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 46239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (modifiedType.isNull()) 46249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 46259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 46269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType result = TL.getType(); 46279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 46289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // FIXME: dependent operand expressions? 46299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (getDerived().AlwaysRebuild() || 46309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType != oldType->getModifiedType()) { 46319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // TODO: this is really lame; we should really be rebuilding the 46329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // equivalent type from first principles. 46339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType 46349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall = getDerived().TransformType(oldType->getEquivalentType()); 46359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (equivalentType.isNull()) 46369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 46379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), 46389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType, 46399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall equivalentType); 46409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 46419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 46429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 46439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrNameLoc(TL.getAttrNameLoc()); 46449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) 46459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 46469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) 46479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrExprOperand(TL.getAttrExprOperand()); 46489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall else if (TL.hasAttrEnumOperand()) 46499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); 46509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 46519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return result; 46529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 46539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 46549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived> 4655075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 4656075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 4657075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc TL) { 4658075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 4659075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Inner.isNull()) 4660075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4661075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4662075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Result = TL.getType(); 4663075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (getDerived().AlwaysRebuild() || 4664075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner != TL.getInnerLoc().getType()) { 4665075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Result = getDerived().RebuildParenType(Inner); 4666075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Result.isNull()) 4667075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4668075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 4669075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4670075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 4671075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setLParenLoc(TL.getLParenLoc()); 4672075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setRParenLoc(TL.getRParenLoc()); 4673075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Result; 4674075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 4675075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4676075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived> 46774714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, 467843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentNameTypeLoc TL) { 4679f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentNameType *T = TL.getTypePtr(); 4680833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 46812494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc 46822494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 46832494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (!QualifierLoc) 4684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 46851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 468633500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Result 46872494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().RebuildDependentNameType(T->getKeyword(), 468833500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getKeywordLoc(), 46892494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc, 46902494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T->getIdentifier(), 469133500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getNameLoc()); 4692a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4695e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 4696e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType NamedT = ElabT->getNamedType(); 469733500955d731c73717af52088b7fc0e7a85681e7John McCall TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 469833500955d731c73717af52088b7fc0e7a85681e7John McCall 4699e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4700e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 47019e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 470233500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 4703e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 4704e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 47052494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4706e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setNameLoc(TL.getNameLoc()); 4707e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 4708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4709577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 47101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4711577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 471233500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>:: 471333500955d731c73717af52088b7fc0e7a85681e7John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 471443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL) { 471594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 471694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (TL.getQualifierLoc()) { 471794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc 471894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 471994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (!QualifierLoc) 4720a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4721a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4722a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 472343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived() 472494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); 472543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 472643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 472743fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 472843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>:: 472994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 473094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 473194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc) { 473294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const DependentTemplateSpecializationType *T = TL.getTypePtr(); 473394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 473494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 473594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 473694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 473794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 473894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor typedef TemplateArgumentLocContainerIterator< 473994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 474094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 474194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 474294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs)) 474394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 474494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 474594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType Result 474694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), 474794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc, 474894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T->getIdentifier(), 474994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TL.getNameLoc(), 475094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs); 475194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Result.isNull()) 475294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 475394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 475494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 475594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType NamedT = ElabT->getNamedType(); 475694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 475794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the template specialization. 475894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateSpecializationTypeLoc NamedTL 47590a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 4760a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth NamedTL.setTemplateNameLoc(TL.getNameLoc()); 476194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setLAngleLoc(TL.getLAngleLoc()); 476294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setRAngleLoc(TL.getRAngleLoc()); 4763944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 47640a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 476594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 476694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the elaborated type. 476794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 476894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 476994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 47700a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor } else if (isa<DependentTemplateSpecializationType>(Result)) { 47710a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 47720a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4773944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor SpecTL.setKeywordLoc(TL.getKeywordLoc()); 47740a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setQualifierLoc(QualifierLoc); 4775a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth SpecTL.setNameLoc(TL.getNameLoc()); 47760a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 47770a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 4778944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 47790a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 478094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } else { 47810a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor TemplateSpecializationTypeLoc SpecTL 47820a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4783a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth SpecTL.setTemplateNameLoc(TL.getNameLoc()); 47840a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 47850a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 4786944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 47870a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 478894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 478994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return Result; 479094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor} 479194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 479294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived> 47937536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 47947536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypeLoc TL) { 47952fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Pattern 47962fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor = getDerived().TransformType(TLB, TL.getPatternLoc()); 47972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Pattern.isNull()) 47982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 47992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 48002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Result = TL.getType(); 48012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (getDerived().AlwaysRebuild() || 48022fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Pattern != TL.getPatternLoc().getType()) { 48032fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Result = getDerived().RebuildPackExpansionType(Pattern, 48042fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor TL.getPatternLoc().getSourceRange(), 4805cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getEllipsisLoc(), 4806cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getTypePtr()->getNumExpansions()); 48072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Result.isNull()) 48082fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 48092fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 48102fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 48112fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 48122fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor NewT.setEllipsisLoc(TL.getEllipsisLoc()); 48132fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return Result; 48147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 48157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 48167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived> 4817a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4818a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 481943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCInterfaceTypeLoc TL) { 4820ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCInterfaceType is never dependent. 4821c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4822c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return TL.getType(); 4823c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 4824c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4825c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived> 4826c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType 4827c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 482843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectTypeLoc TL) { 4829c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCObjectType is never dependent. 4830c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4831ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 4832577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 48331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4835a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4836a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 483743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectPointerTypeLoc TL) { 4838ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCObjectPointerType is never dependent. 4839c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4840ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 484124fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 484224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 4843577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 484443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation 484543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 484643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 484760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 48481eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 48493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 485043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 485143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 485243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 485360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 485443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 485543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().TransformCompoundStmt(S, false); 485643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 485743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 485843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 485960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 48601eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 486143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 48627114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bool SubStmtInvalid = false; 486343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool SubStmtChanged = false; 4864ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Statements(getSema()); 486543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); 486643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor B != BEnd; ++B) { 486760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Result = getDerived().TransformStmt(*B); 48687114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (Result.isInvalid()) { 48697114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Immediately fail if this was a DeclStmt, since it's very 48707114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // likely that this will cause problems for future statements. 48717114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (isa<DeclStmt>(*B)) 48727114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 48737114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 48747114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Otherwise, just keep processing substatements and fail later. 48757114cbab7eb6e8b714eb22f014327daf2c741c08John McCall SubStmtInvalid = true; 48767114cbab7eb6e8b714eb22f014327daf2c741c08John McCall continue; 48777114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 48781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 487943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SubStmtChanged = SubStmtChanged || Result.get() != *B; 488043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Statements.push_back(Result.takeAs<Stmt>()); 488143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 48821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48837114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (SubStmtInvalid) 48847114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 48857114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 488643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 488743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !SubStmtChanged) 48883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 488943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 489043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 489143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor move_arg(Statements), 489243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRBracLoc(), 489343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 489443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 48951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 489643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 489760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 48981eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 489960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS, RHS; 4900264c1f8ec895952466eab59b84b8b06801e721faEli Friedman { 4901264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // The case value expressions are not potentially evaluated. 4902f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 49031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4904264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the left-hand case value. 4905264c1f8ec895952466eab59b84b8b06801e721faEli Friedman LHS = getDerived().TransformExpr(S->getLHS()); 4906264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (LHS.isInvalid()) 4907f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4909264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the right-hand case value (for the GNU case-range extension). 4910264c1f8ec895952466eab59b84b8b06801e721faEli Friedman RHS = getDerived().TransformExpr(S->getRHS()); 4911264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (RHS.isInvalid()) 4912f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4913264c1f8ec895952466eab59b84b8b06801e721faEli Friedman } 49141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 491543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Build the case statement. 491643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Case statements are always rebuilt so that they will attached to their 491743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transformed switch statement. 491860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 49199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 492043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getEllipsisLoc(), 49219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 492243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getColonLoc()); 492343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Case.isInvalid()) 4924f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 492643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the case 492760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 492843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4929f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 493143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Attach the body to the case statement 49329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 493343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 493443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 493543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 493660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49371eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 493843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the default case 493960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 494043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4941f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 494343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Default statements are always rebuilt 494443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 49459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get()); 494643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 49471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 494843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 494960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { 495160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 495243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4953f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 495557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 495657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getDecl()); 495757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 495857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 495957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 496057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 496143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // FIXME: Pass the real colon location in. 4962ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner return getDerived().RebuildLabelStmt(S->getIdentLoc(), 496357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD), SourceLocation(), 496457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SubStmt.get()); 496543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 49661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 496743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 496860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49691eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 497043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 497160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 49728cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor VarDecl *ConditionVar = 0; 49738cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (S->getConditionVariable()) { 4974c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 49758cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor = cast_or_null<VarDecl>( 4976aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4977aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4978aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 49798cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (!ConditionVar) 4980f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 498199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 49828cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 4983c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 498499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 4985f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4986eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 4987eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Convert the condition to a boolean value. 4988afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 49898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), 49908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 4991afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 4992f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4993eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 49949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 4995afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 499699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 4997c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 49989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 49999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5000f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5001eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 500243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "then" branch. 500360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Then = getDerived().TransformStmt(S->getThen()); 500443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Then.isInvalid()) 5005f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 500743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "else" branch. 500860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Else = getDerived().TransformStmt(S->getElse()); 500943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Else.isInvalid()) 5010f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 501243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 50139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 501499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 501543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Then.get() == S->getThen() && 501643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Else.get() == S->getElse()) 50173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 50181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5019eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, 502044aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Then.get(), 50219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall S->getElseLoc(), Else.get()); 502243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 502343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 502443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 502560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50261eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 502743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition. 502860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 5029d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor VarDecl *ConditionVar = 0; 5030d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (S->getConditionVariable()) { 5031c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 5032d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor = cast_or_null<VarDecl>( 5033aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5034aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5035aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 5036d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (!ConditionVar) 5037f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 503899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 5039d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5040c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 504199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5042f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 504399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 50441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 504543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Rebuild the switch statement. 504660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Switch 50479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), 5048586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor ConditionVar); 504943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Switch.isInvalid()) 5050f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 505243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body of the switch statement. 505360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 505443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5055f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 505743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Complete the switch statement. 50589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 50599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 506043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 506243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 506360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 506543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 506660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 50675656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor VarDecl *ConditionVar = 0; 50685656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (S->getConditionVariable()) { 5069c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 50705656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor = cast_or_null<VarDecl>( 5071aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5072aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5073aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 50745656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (!ConditionVar) 5075f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 507699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 50775656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5078c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 507999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5080f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5081afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5082afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5083afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 50848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), 50858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5086afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5087f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE; 5089afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 509099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 50911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 50939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5094f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5095eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 509643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 509760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 509843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5099f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 510143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 51029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 510399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 510443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 51059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(S); 51061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5107eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, 51089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ConditionVar, Body.get()); 510943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 511260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 511443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 511560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5117f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5119eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Transform the condition 512060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5121eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor if (Cond.isInvalid()) 5122f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5123eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 512443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 512543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Cond.get() == S->getCond() && 512643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 51273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 51281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 51309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall /*FIXME:*/S->getWhileLoc(), Cond.get(), 513143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRParenLoc()); 513243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 513443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 513560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) { 513743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the initialization statement 513860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Init = getDerived().TransformStmt(S->getInit()); 513943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Init.isInvalid()) 5140f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 514243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 514360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 514499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *ConditionVar = 0; 514599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (S->getConditionVariable()) { 5146c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 514799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor = cast_or_null<VarDecl>( 5148aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5149aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5150aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 515199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!ConditionVar) 5152f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 515399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 515499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5155c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 515699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5157f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5158afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5159afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5160afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 51618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), 51628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5163afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5164f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5165afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 51669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5167afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 516899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 51691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 51719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5172f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5173eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 517443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the increment 517560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Inc = getDerived().TransformExpr(S->getInc()); 517643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Inc.isInvalid()) 5177f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); 51809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (S->getInc() && !FullInc.get()) 5181f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5182eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 518343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 518460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 518543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5186f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 518843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 518943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Init.get() == S->getInit() && 51909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 519143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Inc.get() == S->getInc() && 519243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 51933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 51941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 519543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 51969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get(), FullCond, ConditionVar, 51979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullInc, S->getRParenLoc(), Body.get()); 519843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 519943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 520043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 520160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52021eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 520357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 520457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getLabel()); 520557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 520657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 520757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 520843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Goto statements must always be rebuilt, to resolve the label. 52091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 521057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 521143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 521243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 521343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 521460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52151eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 521660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Target = getDerived().TransformExpr(S->getTarget()); 521743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Target.isInvalid()) 5218f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 522043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 522143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Target.get() == S->getTarget()) 52223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 522343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 522443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 52259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Target.get()); 522643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 522743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 522843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 522960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 52313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 523243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 523443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 523560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 52373fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 523843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 524043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 524160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 524360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(S->getRetValue()); 524443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Result.isInvalid()) 5245f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 524643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 52471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: We always rebuild the return statement because there is no way 524843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // to tell whether the return type of the function has changed. 52499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 525043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 525243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 525360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 525543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool DeclChanged = false; 525643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor llvm::SmallVector<Decl *, 4> Decls; 525743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); 525843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor D != DEnd; ++D) { 5259aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), 5260aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor *D); 526143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!Transformed) 5262f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 526443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Transformed != *D) 526543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclChanged = true; 52661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 526743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls.push_back(Transformed); 526843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 52691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 527043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && !DeclChanged) 52713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), 527443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getStartLoc(), S->getEndLoc()); 527543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 527743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 527860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 527943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { 5280c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5281ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Constraints(getSema()); 5282ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Exprs(getSema()); 5283ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVector<IdentifierInfo *, 4> Names; 5284a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson 528560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmString; 5286ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Clobbers(getSema()); 5287703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5288703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool ExprsChanged = false; 5289c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5290703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the outputs. 5291703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 5292ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getOutputIdentifier(I)); 5293c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5294703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 52953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getOutputConstraintLiteral(I)); 5296c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5297703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the output expr. 5298703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *OutputExpr = S->getOutputExpr(I); 529960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(OutputExpr); 5300703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5301f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5303703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != OutputExpr; 5304c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5306703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5307c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5308703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the inputs. 5309703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 5310ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getInputIdentifier(I)); 5311c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5312703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 53133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getInputConstraintLiteral(I)); 5314c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5315703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the input expr. 5316703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *InputExpr = S->getInputExpr(I); 531760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(InputExpr); 5318703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5319f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5320c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5321703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != InputExpr; 5322c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5324703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5325c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5326703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (!getDerived().AlwaysRebuild() && !ExprsChanged) 53273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5328703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5329703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the clobbers. 5330703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 53313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Clobbers.push_back(S->getClobber(I)); 5332703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5333703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the asm string literal. 5334703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson AsmString = SemaRef.Owned(S->getAsmString()); 5335703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5336703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson return getDerived().RebuildAsmStmt(S->getAsmLoc(), 5337703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isSimple(), 5338703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isVolatile(), 5339703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumOutputs(), 5340703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumInputs(), 5341a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson Names.data(), 5342703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Constraints), 5343703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Exprs), 53449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AsmString.get(), 5345703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Clobbers), 5346703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getRParenLoc(), 5347703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isMSAsm()); 534843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 534943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 535043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 535143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 535260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 53544dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body of the @try. 535560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 53564dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (TryBody.isInvalid()) 5357f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5358c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53598f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor // Transform the @catch statements (if present). 53608f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor bool AnyCatchChanged = false; 5361ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> CatchStmts(SemaRef); 53628f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 536360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 53644dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Catch.isInvalid()) 5365f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53668f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (Catch.get() != S->getCatchStmt(I)) 53678f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor AnyCatchChanged = true; 53688f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 53694dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 5370c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53714dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the @finally statement (if present). 537260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Finally; 53734dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (S->getFinallyStmt()) { 53744dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally = getDerived().TransformStmt(S->getFinallyStmt()); 53754dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Finally.isInvalid()) 5376f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53774dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 53784dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 53794dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 53804dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 53814dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor TryBody.get() == S->getTryBody() && 53828f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor !AnyCatchChanged && 53834dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally.get() == S->getFinallyStmt()) 53843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5385c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53864dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 53879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 53889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall move_arg(CatchStmts), Finally.get()); 538943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 539143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 539260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53931eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 5394be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor // Transform the @catch parameter, if there is one. 5395be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var = 0; 5396be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (VarDecl *FromVar = S->getCatchParamDecl()) { 5397be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TSInfo = 0; 5398be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (FromVar->getTypeSourceInfo()) { 5399be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 5400be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!TSInfo) 5401f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5402be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5403c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5404be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor QualType T; 5405be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (TSInfo) 5406be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = TSInfo->getType(); 5407be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor else { 5408be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = getDerived().TransformType(FromVar->getType()); 5409be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (T.isNull()) 5410f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5411be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5412c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5413be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 5414be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!Var) 5415f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5416be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5417c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 541860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 5419be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (Body.isInvalid()) 5420f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5421c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5422c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 5423be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor S->getRParenLoc(), 54249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body.get()); 542543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 542743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 542860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54291eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 54304dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body. 543160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 54324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Body.isInvalid()) 5433f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5434c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54354dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 54364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 54374dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Body.get() == S->getFinallyBody()) 54383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 54394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 54404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 54414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 54429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 544343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 544543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 544660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54471eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 544860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand; 5449d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (S->getThrowExpr()) { 5450d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand = getDerived().TransformExpr(S->getThrowExpr()); 5451d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (Operand.isInvalid()) 5452f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5453d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 5454c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5455d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (!getDerived().AlwaysRebuild() && 5456d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand.get() == S->getThrowExpr()) 54573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return getSema().Owned(S); 5458c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 546043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 546243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 546360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 546443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 54651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCAtSynchronizedStmt *S) { 54668fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the object we are locking. 546760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 54688fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Object.isInvalid()) 5469f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5470c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54718fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the body. 547260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 54738fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Body.isInvalid()) 5474f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5475c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54768fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // If nothing change, just retain the current statement. 54778fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (!getDerived().AlwaysRebuild() && 54788fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Object.get() == S->getSynchExpr() && 54798fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Body.get() == S->getSynchBody()) 54803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 54818fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor 54828fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Build a new statement. 54838fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 54849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Object.get(), Body.get()); 548543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 548643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 548743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 548860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 5489f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( 5490f85e193739c953358c865005855253af4f68a497John McCall ObjCAutoreleasePoolStmt *S) { 5491f85e193739c953358c865005855253af4f68a497John McCall // Transform the body. 5492f85e193739c953358c865005855253af4f68a497John McCall StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); 5493f85e193739c953358c865005855253af4f68a497John McCall if (Body.isInvalid()) 5494f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 5495f85e193739c953358c865005855253af4f68a497John McCall 5496f85e193739c953358c865005855253af4f68a497John McCall // If nothing changed, just retain this statement. 5497f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 5498f85e193739c953358c865005855253af4f68a497John McCall Body.get() == S->getSubStmt()) 5499f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(S); 5500f85e193739c953358c865005855253af4f68a497John McCall 5501f85e193739c953358c865005855253af4f68a497John McCall // Build a new statement. 5502f85e193739c953358c865005855253af4f68a497John McCall return getDerived().RebuildObjCAutoreleasePoolStmt( 5503f85e193739c953358c865005855253af4f68a497John McCall S->getAtLoc(), Body.get()); 5504f85e193739c953358c865005855253af4f68a497John McCall} 5505f85e193739c953358c865005855253af4f68a497John McCall 5506f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 5507f85e193739c953358c865005855253af4f68a497John McCallStmtResult 550843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt( 55091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCForCollectionStmt *S) { 5510c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the element statement. 551160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Element = getDerived().TransformStmt(S->getElement()); 5512c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Element.isInvalid()) 5513f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5514c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5515c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the collection expression. 551660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 5517c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Collection.isInvalid()) 5518f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5519c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5520c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the body. 552160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 5522c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Body.isInvalid()) 5523f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5524c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5525c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // If nothing changed, just retain this statement. 5526c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (!getDerived().AlwaysRebuild() && 5527c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Element.get() == S->getElement() && 5528c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Collection.get() == S->getCollection() && 5529c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Body.get() == S->getBody()) 55303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5531c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5532c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Build a new statement. 5533c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 5534c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /*FIXME:*/S->getForLoc(), 55359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element.get(), 55369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection.get(), 5537c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor S->getRParenLoc(), 55389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 553943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 554043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 554143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 554243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 554360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 554443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 554543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the exception declaration, if any. 554643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *Var = 0; 554743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (S->getExceptionDecl()) { 554843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *ExceptionDecl = S->getExceptionDecl(); 554983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor TypeSourceInfo *T = getDerived().TransformType( 555083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getTypeSourceInfo()); 555183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor if (!T) 5552f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 55531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 555483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, 5555ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 5556ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 5557ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 5558ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (!Var || Var->isInvalidDecl()) 5559f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 556043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 55611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 556243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the actual exception handler. 556360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 5564ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (Handler.isInvalid()) 5565f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 55661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 556743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 556843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !Var && 556943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handler.get() == S->getHandlerBlock()) 55703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 557143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 557243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), 557343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Var, 55749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler.get()); 557543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 557743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 557860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 557943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 558043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the try block itself. 558160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBlock 558243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCompoundStmt(S->getTryBlock()); 558343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (TryBlock.isInvalid()) 5584f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 55851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 558643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the handlers. 558743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool HandlerChanged = false; 5588ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Handlers(SemaRef); 558943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 559060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler 559143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 559243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Handler.isInvalid()) 5593f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 55941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 559543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 559643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handlers.push_back(Handler.takeAs<Stmt>()); 559743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 55981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 559943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 560043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor TryBlock.get() == S->getTryBlock() && 560143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !HandlerChanged) 56023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 560343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 56049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 56051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump move_arg(Handlers)); 560643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5608ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived> 5609ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult 5610ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { 5611ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); 5612ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Range.isInvalid()) 5613ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5614ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5615ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); 5616ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (BeginEnd.isInvalid()) 5617ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5618ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5619ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5620ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Cond.isInvalid()) 5621ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5622ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5623ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Inc = getDerived().TransformExpr(S->getInc()); 5624ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Inc.isInvalid()) 5625ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5626ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5627ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); 5628ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (LoopVar.isInvalid()) 5629ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5630ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5631ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult NewStmt = S; 5632ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (getDerived().AlwaysRebuild() || 5633ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Range.get() != S->getRangeStmt() || 5634ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get() != S->getBeginEndStmt() || 5635ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond.get() != S->getCond() || 5636ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get() != S->getInc() || 5637ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith LoopVar.get() != S->getLoopVarStmt()) 5638ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5639ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5640ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5641ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5642ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5643ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5644ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Body = getDerived().TransformStmt(S->getBody()); 5645ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.isInvalid()) 5646ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5647ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5648ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // Body has changed but we didn't rebuild the for-range statement. Rebuild 5649ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // it now so we have a new statement to attach the body to. 5650ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.get() != S->getBody() && NewStmt.get() == S) 5651ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5652ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5653ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5654ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5655ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5656ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5657ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (NewStmt.get() == S) 5658ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return SemaRef.Owned(S); 5659ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5660ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); 5661ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 5662ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 566328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 566428bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 566528bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { 566628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); 566728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(TryBlock.isInvalid()) return StmtError(); 566828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 566928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); 567028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(!getDerived().AlwaysRebuild() && 567128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.get() == S->getTryBlock() && 567228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.get() == S->getHandler()) 567328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SemaRef.Owned(S); 567428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 567528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), 567628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley S->getTryLoc(), 567728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.take(), 567828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.take()); 567928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 568028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 568128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 568228bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 568328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { 568428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 568528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 568628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 568728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), 568828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 568928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 569028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 569128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 569228bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 569328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { 569428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); 569528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(FilterExpr.isInvalid()) return StmtError(); 569628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 569728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 569828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 569928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 570028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), 570128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley FilterExpr.take(), 570228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 570328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 570428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 570528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 570628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 570728bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { 570828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(isa<SEHFinallyStmt>(Handler)) 570928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); 571028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley else 571128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); 571228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 571328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 571443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 5715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation 5716577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 57171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 571860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5719454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 57203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 57211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 57221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 572460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5725454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 572640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 572740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (E->getQualifierLoc()) { 572840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 572940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 573040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 5731f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5732a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5733dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5734dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *ND 57357c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 57367c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getDecl())); 5737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!ND) 5738f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5740ec8045d3f0375302eadaa63deb373bacaf25a569John McCall DeclarationNameInfo NameInfo = E->getNameInfo(); 5741ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (NameInfo.getName()) { 5742ec8045d3f0375302eadaa63deb373bacaf25a569John McCall NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5743ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (!NameInfo.getName()) 5744f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5745ec8045d3f0375302eadaa63deb373bacaf25a569John McCall } 57462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 57472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!getDerived().AlwaysRebuild() && 574840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 5749a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ND == E->getDecl() && 57502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDecl()->getDeclName() && 5751096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 57521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5753dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // Mark it referenced in the new context regardless. 5754dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: this is a bit instantiation-specific. 5755dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 5756a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 57573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5758a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5759dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5760dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; 5761096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 5762dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgs = &TransArgs; 5763dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 5764dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 5765fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 5766fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 5767fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 5768fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 5769dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall } 5770dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 577140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 577240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor TemplateArgs); 5773577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 57741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 577660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5777454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 57783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5779577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 57801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 578260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5783454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 57843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 578860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5789454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 57903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 579460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5795454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 57963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 580060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5801454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 58023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 58041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 580660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5807f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { 5808f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ControllingExpr = 5809f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne getDerived().TransformExpr(E->getControllingExpr()); 5810f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (ControllingExpr.isInvalid()) 5811f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 5812f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5813f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne llvm::SmallVector<Expr *, 4> AssocExprs; 5814f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes; 5815f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne for (unsigned i = 0; i != E->getNumAssocs(); ++i) { 5816f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); 5817f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (TS) { 5818f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *AssocType = getDerived().TransformType(TS); 5819f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!AssocType) 5820f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 5821f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(AssocType); 5822f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else { 5823f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(0); 5824f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 5825f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5826f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); 5827f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (AssocExpr.isInvalid()) 5828f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 5829f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.push_back(AssocExpr.release()); 5830f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 5831f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5832f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), 5833f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getDefaultLoc(), 5834f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getRParenLoc(), 5835f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr.release(), 5836f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.data(), 5837f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.data(), 5838f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getNumAssocs()); 5839f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 5840f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5841f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived> 5842f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult 5843454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 584460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 5845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5846f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 58493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 58501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 5852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParen()); 5853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 5854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 58551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 585660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5857454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 585860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 5859b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5860f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 58633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 58641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 5866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOpcode(), 58679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 5868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 58691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 587160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 58728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 58738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform the type. 58748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 58758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!Type) 5876f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5877c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 58788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform all of the components into components similar to what the 58798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // parser uses. 5880c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // FIXME: It would be slightly more efficient in the non-dependent case to 5881c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // just map FieldDecls, rather than requiring the rebuilder to look for 5882c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // the fields again. However, __builtin_offsetof is rare enough in 58838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // template code that we don't care. 58848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor bool ExprChanged = false; 5885f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::OffsetOfComponent Component; 58868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor typedef OffsetOfExpr::OffsetOfNode Node; 58878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor llvm::SmallVector<Component, 4> Components; 58888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 58898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const Node &ON = E->getComponent(I); 58908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Component Comp; 589172be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor Comp.isBrackets = true; 589206dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocStart = ON.getSourceRange().getBegin(); 589306dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocEnd = ON.getSourceRange().getEnd(); 58948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor switch (ON.getKind()) { 58958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Array: { 58968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 589760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(FromIndex); 58988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (Index.isInvalid()) 5899f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5900c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 59018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor ExprChanged = ExprChanged || Index.get() != FromIndex; 59028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = true; 59039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Comp.U.E = Index.get(); 59048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 59058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 5906c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 59078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Field: 59088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Identifier: 59098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = false; 59108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.U.IdentInfo = ON.getFieldName(); 591129d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor if (!Comp.U.IdentInfo) 591229d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor continue; 5913c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 59148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 5915c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5916cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor case Node::Base: 5917cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor // Will be recomputed during the rebuild. 5918cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor continue; 59198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 5920c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 59218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.push_back(Comp); 59228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 5923c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 59248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // If nothing changed, retain the existing expression. 59258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!getDerived().AlwaysRebuild() && 59268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Type == E->getTypeSourceInfo() && 59278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor !ExprChanged) 59283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5929c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 59308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Build a new offsetof expression. 59318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 59328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.data(), Components.size(), 59338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor E->getRParenLoc()); 59347cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall} 59357cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 59367cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived> 59377cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult 59387cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 59397cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall assert(getDerived().AlreadyTransformed(E->getType()) && 59407cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall "opaque value expression requires transformation"); 59417cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return SemaRef.Owned(E); 59428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 59438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 59448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived> 594560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5946f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( 5947f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr *E) { 5948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isArgumentType()) { 5949a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 59505557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor 5951a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 59525ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!NewT) 5953f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59555ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!getDerived().AlwaysRebuild() && OldT == NewT) 59563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 59571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5958f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), 5959f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 5960f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 5961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 59621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 596360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr; 59641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump { 5965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // C++0x [expr.sizeof]p1: 5966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The operand is either an expression, which is an unevaluated operand 5967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // [...] 5968f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 59691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 5971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5972f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 59753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 59771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5978f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), 5979f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getOperatorLoc(), 5980f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 5981f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 5982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 598560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5986454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 598760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 5988b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 5989f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 599160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 5992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 5993f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5997b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 5998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 59993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildArraySubscriptExpr(LHS.get(), 6002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLHS()->getLocStart(), 60039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 6004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRBracketLoc()); 6005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 600860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6009454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 6010b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the callee. 601160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6013f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform arguments. 6016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgChanged = false; 6017ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6018aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6019aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 6020aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6021aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgChanged) 60253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Wrong source location information for the '('. 60281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLParenLoc 6029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = ((Expr *)Callee.get())->getSourceRange().getBegin(); 60309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 6032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6033b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 603660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6037454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 603860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6040f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 604240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 604383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (E->hasQualifier()) { 604440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 604540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 604640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 604740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 6048f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 604983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 60501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6051f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *Member 60527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 60537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getMemberDecl())); 6054b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Member) 6055f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60576bb8017bb9e828d118e15e59d71c66bba323c364John McCall NamedDecl *FoundDecl = E->getFoundDecl(); 60586bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (FoundDecl == E->getMemberDecl()) { 60596bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = Member; 60606bb8017bb9e828d118e15e59d71c66bba323c364John McCall } else { 60616bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = cast_or_null<NamedDecl>( 60626bb8017bb9e828d118e15e59d71c66bba323c364John McCall getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 60636bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!FoundDecl) 6064f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60656bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 60666bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6068b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase() && 606940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 60708a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member == E->getMemberDecl() && 60716bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl == E->getFoundDecl() && 6072096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 6073c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60741f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // Mark it referenced in the new context regardless. 60751f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // FIXME: this is a bit instantiation-specific. 60761f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); 60773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60781f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson } 6079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6080d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs; 6081096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 6082d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 6083d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 6084fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6085fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6086fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6087fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 60888a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor } 6089c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bogus source location for the operator 6091b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeOperatorLoc 6092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 6093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6094c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 6095c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 6096c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 6097c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 6098c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 6099c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 61009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 6101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 610240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc, 61032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara E->getMemberNameInfo(), 61048a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member, 61056bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, 6106096832c5ed5b9106fa177ebc148489760c3bc496John McCall (E->hasExplicitTemplateArgs() 6107d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall ? &TransArgs : 0), 6108c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope); 6109b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6111b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 611260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6113454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 611460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6115b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6116f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 611860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6119b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6120f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6122b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6123b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 61253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6127b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 61289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), RHS.get()); 6129b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 61311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 613260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator( 6134454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CompoundAssignOperator *E) { 6135454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformBinaryOperator(E); 6136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 613956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>:: 614056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 614156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Just rebuild the common and RHS expressions and see whether we 614256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // get any changes. 614356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 614456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 614556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (commonExpr.isInvalid()) 614656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 614756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 614856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 614956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (rhs.isInvalid()) 615056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 615156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 615256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (!getDerived().AlwaysRebuild() && 615356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall commonExpr.get() == e->getCommon() && 615456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get() == e->getFalseExpr()) 615556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SemaRef.Owned(e); 615656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 615756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return getDerived().RebuildConditionalOperator(commonExpr.take(), 615856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getQuestionLoc(), 615956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 0, 616056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getColonLoc(), 616156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get()); 616256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 616356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 616456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived> 616560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6166454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 616760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6169f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 617160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6173f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 617560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6177f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 61833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildConditionalOperator(Cond.get(), 618647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getQuestionLoc(), 61879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 618847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getColonLoc(), 61899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get()); 6190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 619360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6194454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 6195a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // Implicit casts are eliminated during transformation, since they 6196a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // will be recomputed by semantic analysis after transformation. 61976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return getDerived().TransformExpr(E->getSubExprAsWritten()); 6198b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 620160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6202454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 6203ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6204ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6205ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6206ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 620760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 62086eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6210f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6212b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6213ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 62153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62179d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 6218ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc(), 62209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 622460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6225454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 622642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *OldT = E->getTypeSourceInfo(); 622742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 622842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall if (!NewT) 6229f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 623160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 6232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 623642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall OldT == NewT && 6237b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInitializer()) 62383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 62401d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // Note: the expression type doesn't necessarily match the 62411d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // type-as-written, but that's okay, because it should always be 62421d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // derivable from the initializer. 62431d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 624442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, 6245b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getInitializer()->getLocEnd(), 62469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get()); 6247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 625060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6251454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 625260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6253b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6254f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6256b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6257b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase()) 62583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bad source location 62611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeOperatorLoc 6262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); 62639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 6264b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessorLoc(), 6265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessor()); 6266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 626960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6270454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 6271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool InitChanged = false; 62721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6273ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6274aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 6275aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Inits, &InitChanged)) 6276aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6277aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && !InitChanged) 62793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), 6282e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor E->getRBraceLoc(), E->getType()); 6283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 628660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6287454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 6288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Designation Desig; 62891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 629043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the initializer value 629160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInit()); 6292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6293f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 629543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the designators. 6296ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); 6297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ExprChanged = false; 6298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 6299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DEnd = E->designators_end(); 6300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D != DEnd; ++D) { 6301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isFieldDesignator()) { 6302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Desig.AddDesignator(Designator::getField(D->getFieldName(), 6303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getDotLoc(), 6304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getFieldLoc())); 6305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 63071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isArrayDesignator()) { 630960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); 6310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Index.isInvalid()) 6311f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArray(Index.get(), 6314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc())); 63151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); 6317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Index.release()); 6318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 63201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(D->isArrayRangeDesignator() && "New kind of designator?"); 632260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Start 6323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformExpr(E->getArrayRangeStart(*D)); 6324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Start.isInvalid()) 6325f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 632760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); 6328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (End.isInvalid()) 6329f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArrayRange(Start.get(), 6332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get(), 6333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc(), 6334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getEllipsisLoc())); 63351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || 6337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get() != E->getArrayRangeEnd(*D); 63381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Start.release()); 6340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(End.release()); 6341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 63421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInit() && 6345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ExprChanged) 63463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), 6349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getEqualOrColonLoc(), 63509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall E->usesGNUSyntax(), Init.get()); 6351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 635460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr( 6356454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall ImplicitValueInitExpr *E) { 63575557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); 6358c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 63595557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // FIXME: Will we ever have proper type location here? Will we actually 63605557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // need to transform the type? 6361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6363f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType()) 63673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildImplicitValueInitExpr(T); 6370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6372b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 637360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6374454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 63759bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 63769bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor if (!TInfo) 6377f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 637960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6381f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 63842cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo == E->getWrittenTypeInfo() && 6385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 63863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 63892cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo, E->getRParenLoc()); 6390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 639360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6394454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 6395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6396ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6397aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 6398aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6399aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6400aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildParenListExpr(E->getLParenLoc(), 6402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Inits), 6403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression. 6407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 6408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always 6409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to 6410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis. 6411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 641260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6413454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 641457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 641557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner E->getLabel()); 641657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 641757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return ExprError(); 641857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 6419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 642057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 6421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 642460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6425454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 642660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt 6427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 6428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubStmt.isInvalid()) 6429f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubStmt.get() == E->getSubStmt()) 64333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildStmtExpr(E->getLParenLoc(), 64369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get(), 6437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 644160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6442454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 644360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6445f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 644760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6449f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 645160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6452b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6453f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6455b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 64593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 64629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond.get(), LHS.get(), RHS.get(), 6463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6464b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 646760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6468454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 64693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 647360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6474454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 6475668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor switch (E->getOperator()) { 6476668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_New: 6477668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Delete: 6478668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_New: 6479668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_Delete: 6480668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 6481f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6482c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6483668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Call: { 6484668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // This is a call to an object's operator(). 6485668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 6486668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6487668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the object itself. 648860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 6489668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor if (Object.isInvalid()) 6490f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6491668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6492668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // FIXME: Poor location information 6493668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor SourceLocation FakeLParenLoc 6494668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6495668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor static_cast<Expr *>(Object.get())->getLocEnd()); 6496668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6497668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the call arguments. 6498ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6499aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 6500aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args)) 6501aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6502668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 65039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, 6504668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor move_arg(Args), 6505668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor E->getLocEnd()); 6506668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6507668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6508668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 6509668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_##Name: 6510668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 6511668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def" 6512668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Subscript: 6513668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Handled below. 6514668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor break; 6515668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6516668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Conditional: 6517668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("conditional operator is not actually overloadable"); 6518f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6519668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6520668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_None: 6521668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case NUM_OVERLOADED_OPERATORS: 6522668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("not an overloaded operator?"); 6523f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6524668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6525668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 652660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6528f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 653060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult First = getDerived().TransformExpr(E->getArg(0)); 6531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (First.isInvalid()) 6532f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 653460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Second; 6535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->getNumArgs() == 2) { 6536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Second = getDerived().TransformExpr(E->getArg(1)); 6537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Second.isInvalid()) 6538f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor First.get() == E->getArg(0) && 65441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 65453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 6548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 65499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee.get(), 65509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First.get(), 65519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second.get()); 6552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 655560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6556454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 6557454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCallExpr(E); 6558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 6561e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult 6562e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 6563e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform the callee. 6564e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6565e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (Callee.isInvalid()) 6566e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6567e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6568e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform exec config. 6569e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 6570e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (EC.isInvalid()) 6571e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6572e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6573e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform arguments. 6574e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne bool ArgChanged = false; 6575e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ASTOwningVector<Expr*> Args(SemaRef); 6576e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6577e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne &ArgChanged)) 6578e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6579e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6580e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (!getDerived().AlwaysRebuild() && 6581e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Callee.get() == E->getCallee() && 6582e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne !ArgChanged) 6583e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return SemaRef.Owned(E); 6584e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6585e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // FIXME: Wrong source location information for the '('. 6586e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation FakeLParenLoc 6587e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne = ((Expr *)Callee.get())->getSourceRange().getBegin(); 6588e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6589e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move_arg(Args), 6590e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne E->getRParenLoc(), EC.get()); 6591e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne} 6592e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6593e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived> 659460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6595454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 6596ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6597ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6598ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6599ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 660060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 66016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6603f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6606ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 66083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Poor source location information here. 66111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLAngleLoc 6612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); 6613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); 6614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRParenLoc 6615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSubExpr()->getSourceRange().getEnd()); 6617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), 66181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getStmtClass(), 6619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeLAngleLoc, 6620ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 6622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 66239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRParenLoc); 6625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 662860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6629454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 6630454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 663460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6635454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 6636454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 664060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr( 6642454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXReinterpretCastExpr *E) { 6643454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 664760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6648454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 6649454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 665360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr( 6655454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXFunctionalCastExpr *E) { 6656ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6657ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6658ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 66591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 666060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 66616eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6663f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6666ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 66683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6670ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return getDerived().RebuildCXXFunctionalCastExpr(Type, 6671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getSubExpr()->getLocStart(), 66729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 667760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6678454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 6679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isTypeOperand()) { 668057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *TInfo 668157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor = getDerived().TransformType(E->getTypeOperandSourceInfo()); 668257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor if (!TInfo) 6683f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 668657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo == E->getTypeOperandSourceInfo()) 66873fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 668957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 669057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 669157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo, 6692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 66941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // We don't know whether the expression is potentially evaluated until 6696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // after we perform semantic analysis, so the expression is potentially 6697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // potentially evaluated. 66981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(SemaRef, 6699f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::PotentiallyPotentiallyEvaluated); 67001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 670160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 6702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6703f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getExprOperand()) 67073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 670957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 671057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 67119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 671660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 671701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 671801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (E->isTypeOperand()) { 671901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *TInfo 672001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet = getDerived().TransformType(E->getTypeOperandSourceInfo()); 672101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!TInfo) 672201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 672301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 672401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 672501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo == E->getTypeOperandSourceInfo()) 67263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 672701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 67283c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor return getDerived().RebuildCXXUuidofExpr(E->getType(), 672901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 673001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo, 673101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 673201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 673301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 673401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // We don't know whether the expression is potentially evaluated until 673501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // after we perform semantic analysis, so the expression is potentially 673601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // potentially evaluated. 673701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 673801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 673901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 674001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (SubExpr.isInvalid()) 674101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 674201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 674301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 674401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get() == E->getExprOperand()) 67453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 674601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 674701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXUuidofExpr(E->getType(), 674801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 674901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get(), 675001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 675101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 675201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 675301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived> 675401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult 6755454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 67563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 676060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 6762454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXNullPtrLiteralExpr *E) { 67633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 676760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6768454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 6769ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor DeclContext *DC = getSema().getFunctionLevelDeclContext(); 67707a614d8380297fcd2bc23986241905d97222948cRichard Smith QualType T; 67717a614d8380297fcd2bc23986241905d97222948cRichard Smith if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) 67727a614d8380297fcd2bc23986241905d97222948cRichard Smith T = MD->getThisType(getSema().Context); 67737a614d8380297fcd2bc23986241905d97222948cRichard Smith else 67747a614d8380297fcd2bc23986241905d97222948cRichard Smith T = getSema().Context.getPointerType( 67757a614d8380297fcd2bc23986241905d97222948cRichard Smith getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); 67761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6777ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!getDerived().AlwaysRebuild() && T == E->getType()) 67783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6780828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); 6781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 678460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6785454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 678660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6788f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 67923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 67949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); 6795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 679860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6799454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 68001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParmVarDecl *Param 68017c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), 68027c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getParam())); 6803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Param) 6804f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 680653cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth if (!getDerived().AlwaysRebuild() && 6807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Param == E->getParam()) 68083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6810036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 6811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 681460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6815ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr( 6816ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr *E) { 6817ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 6818ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 6819f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6820ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 6821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6822ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo()) 68233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6825ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXScalarValueInitExpr(T, 6826ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 6827ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor E->getRParenLoc()); 6828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 683160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6832454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 6833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the type that we're allocating 68341bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocTypeInfo 68351bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); 68361bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor if (!AllocTypeInfo) 6837f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the size of the array we're allocating (if any). 684060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); 6841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (ArraySize.isInvalid()) 6842f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the placement arguments (if any). 6845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6846ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> PlacementArgs(SemaRef); 6847aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getPlacementArgs(), 6848aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor E->getNumPlacementArgs(), true, 6849aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor PlacementArgs, &ArgumentChanged)) 6850aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 68511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 685243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the constructor arguments (if any). 6853ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConstructorArgs(SemaRef); 6854aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, 6855aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ConstructorArgs, &ArgumentChanged)) 6856aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 68571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform constructor, new operator, and delete operator. 68591af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor CXXConstructorDecl *Constructor = 0; 68601af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getConstructor()) { 68611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor = cast_or_null<CXXConstructorDecl>( 68627c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 68637c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 68641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!Constructor) 6865f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 68671af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 68681af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorNew = 0; 68691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorNew()) { 68701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew = cast_or_null<FunctionDecl>( 68717c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 68727c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorNew())); 68731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorNew) 6874f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 68761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 68771af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 68781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 68791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 68807c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 68817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 68821af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 6883f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 6885c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 68871bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 6888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArraySize.get() == E->getArraySize() && 68891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor == E->getConstructor() && 68901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew == E->getOperatorNew() && 68911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete() && 68921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor !ArgumentChanged) { 68931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 68941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 68951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (Constructor) 68961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 68971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorNew) 68981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); 68991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 69001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 69013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 69031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69041bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocType = AllocTypeInfo->getType(); 69055b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArraySize.get()) { 69065b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // If no array size was specified, but the new expression was 69075b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with an array type (e.g., "new T" where T is 69085b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with "int[4]"), extract the outer bound from the 69095b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // array type as our array size. We do this with constant and 69105b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // dependently-sized array types. 69115b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 69125b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArrayT) { 69135b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // Do nothing 69145b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const ConstantArrayType *ConsArrayT 69155b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<ConstantArrayType>(ArrayT)) { 6916c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ArraySize 69179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, 69189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis ConsArrayT->getSize(), 69199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis SemaRef.Context.getSizeType(), 69209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME:*/E->getLocStart())); 69215b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = ConsArrayT->getElementType(); 69225b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const DependentSizedArrayType *DepArrayT 69235b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<DependentSizedArrayType>(ArrayT)) { 69245b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (DepArrayT->getSizeExpr()) { 69253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); 69265b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = DepArrayT->getElementType(); 69275b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 69285b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 69295b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 69301bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor 6931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNewExpr(E->getLocStart(), 6932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalNew(), 6933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 6934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(PlacementArgs), 6935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 69364bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor E->getTypeIdParens(), 6937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor AllocType, 69381bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo, 69399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize.get(), 6940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 6941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(ConstructorArgs), 69421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getLocEnd()); 6943b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 694660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6947454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 694860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 6949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Operand.isInvalid()) 6950f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69521af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform the delete operator, if known. 69531af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 69541af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 69551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 69567c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 69577c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 69581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 6959f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69601af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 6961c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 69631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Operand.get() == E->getArgument() && 69641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete()) { 69651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 69661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 69671af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 69681af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 69695833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 69705833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (!E->getArgument()->isTypeDependent()) { 69715833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType Destroyed = SemaRef.Context.getBaseElementType( 69725833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor E->getDestroyedType()); 69735833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 69745833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 69755833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), 69765833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.LookupDestructor(Record)); 69775833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 69785833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 69795833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 69803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69811af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 69821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), 6984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalDelete(), 6985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrayForm(), 69869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand.get()); 6987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6989b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 699060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6991a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 6992454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXPseudoDestructorExpr *E) { 699360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6994a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor if (Base.isInvalid()) 6995f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6997b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTypePtr; 6998a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor bool MayBePseudoDestructor = false; 69999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7000a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getOperatorLoc(), 7001a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7002a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor ObjectTypePtr, 7003a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor MayBePseudoDestructor); 7004a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Base.isInvalid()) 7005f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7006c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7007b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType ObjectType = ObjectTypePtr.get(); 7008f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 7009f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (QualifierLoc) { 7010f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor QualifierLoc 7011f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 7012f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (!QualifierLoc) 701343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return ExprError(); 701443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 7015f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec SS; 7016f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS.Adopt(QualifierLoc); 70171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7018a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed; 7019a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (E->getDestroyedTypeInfo()) { 7020a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedTypeInfo 702143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 7022b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, 0, SS); 7023a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!DestroyedTypeInfo) 7024f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7025a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = DestroyedTypeInfo; 7026a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else if (ObjectType->isDependentType()) { 7027a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // We aren't likely to be able to resolve the identifier down to a type 7028a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // now anyway, so just retain the identifier. 7029a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 7030a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7031a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else { 7032a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // Look for a destructor known with the given name. 7033b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 7034a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor *E->getDestroyedTypeIdentifier(), 7035a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc(), 7036a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /*Scope=*/0, 7037a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS, ObjectTypePtr, 7038a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor false); 7039a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!T) 7040f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7041c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7042a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed 7043a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 7044a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7045a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 704626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 704726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeTypeInfo = 0; 704826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (E->getScopeTypeInfo()) { 704943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); 705026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (!ScopeTypeInfo) 7051f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7052a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 7053c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 70549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 7055a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->getOperatorLoc(), 7056a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->isArrow(), 7057f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS, 705826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor ScopeTypeInfo, 705926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getColonColonLoc(), 7060fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor E->getTildeLoc(), 7061a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed); 7062a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor} 70631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7064a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived> 706560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7066ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr( 7067454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall UnresolvedLookupExpr *Old) { 7068f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 7069f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Sema::LookupOrdinaryName); 7070f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7071f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Transform all the decls. 7072f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), 7073f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = Old->decls_end(); I != E; ++I) { 70747c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 70757c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getNameLoc(), 70767c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 70779f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 70789f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 70799f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 70809f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 70819f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 70829f54ad4381370c6b771424b53d219e661d6d6706John McCall else 7083f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70849f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7085f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7086f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Expand using declarations. 7087f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (isa<UsingDecl>(InstD)) { 7088f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7089f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7090f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = UD->shadow_end(); I != E; ++I) 7091f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(*I); 7092f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall continue; 7093f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7094f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7095f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(InstD); 7096f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7097f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7098f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Resolve a kind, but don't do any further analysis. If it's 7099f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // ambiguous, the callee needs to deal with it. 7100f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.resolveKind(); 7101f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7102f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Rebuild the nested-name qualifier, if present. 7103f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall CXXScopeSpec SS; 71044c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 71054c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc 71064c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 71074c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7108f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7109c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 71104c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 7111c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } 7112c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7113c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (Old->getNamingClass()) { 711466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor CXXRecordDecl *NamingClass 711566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 711666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNameLoc(), 711766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 711866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7119f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7120c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 712166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7122f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7123f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7124f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have no template arguments, it's a normal declaration name. 7125f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!Old->hasExplicitTemplateArgs()) 7126f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 7127f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7128f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have template arguments, rebuild them, then rebuild the 7129f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // templateid expression. 7130f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 7131fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7132fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7133fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7134fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7135f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7136f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), 7137f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TransArgs); 7138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 714160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7142454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 71433d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 71443d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor if (!T) 7145f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 71483d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor T == E->getQueriedTypeSourceInfo()) 71493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildUnaryTypeTrait(E->getTrait(), 7152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocStart(), 7153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T, 7154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 715860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 71596ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 71606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); 71616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!LhsT) 71626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 71636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 71646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); 71656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!RhsT) 71666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 71676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 71686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!getDerived().AlwaysRebuild() && 71696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) 71706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SemaRef.Owned(E); 71716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 71726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getDerived().RebuildBinaryTypeTrait(E->getTrait(), 71736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocStart(), 71746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT, RhsT, 71756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocEnd()); 71766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 71776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 71786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived> 71796ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult 718021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 718121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 718221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!T) 718321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 718421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 718521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && 718621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T == E->getQueriedTypeSourceInfo()) 718721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 718821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 718921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult SubExpr; 719021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley { 719121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 719221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); 719321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (SubExpr.isInvalid()) 719421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 719521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 719621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) 719721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 719821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 719921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 720021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getDerived().RebuildArrayTypeTrait(E->getTrait(), 720121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocStart(), 720221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T, 720321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr.get(), 720421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocEnd()); 720521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley} 720621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 720721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived> 720821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult 7209552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { 7210552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult SubExpr; 7211552622067dc45013d240f73952fece703f5e63bdJohn Wiegley { 7212552622067dc45013d240f73952fece703f5e63bdJohn Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 7213552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); 7214552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (SubExpr.isInvalid()) 7215552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return ExprError(); 7216552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7217552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) 7218552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return SemaRef.Owned(E); 7219552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 7220552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7221552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getDerived().RebuildExpressionTrait( 7222552622067dc45013d240f73952fece703f5e63bdJohn Wiegley E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); 7223552622067dc45013d240f73952fece703f5e63bdJohn Wiegley} 7224552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7225552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived> 7226552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult 7227865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 72282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DependentScopeDeclRefExpr *E) { 722900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc 723000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 723100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor if (!QualifierLoc) 7232f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 723443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 723543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 723643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 723743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 72382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 72392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 72402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7241f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7243f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!E->hasExplicitTemplateArgs()) { 7244f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!getDerived().AlwaysRebuild() && 724500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor QualifierLoc == E->getQualifierLoc() && 72462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Note: it is sufficient to compare the Name component of NameInfo: 72472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // if name has not changed, DNLoc has not changed either. 72482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDeclName()) 72493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 72501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 725100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 72522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7253f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /*TemplateArgs*/ 0); 7254f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor } 7255d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 7256d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7257fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7258fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7259fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7260fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 726200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 72632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7264f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall &TransArgs); 7265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 726860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7269454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 7270321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // CXXConstructExprs are always implicit, so when we have a 7271321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // 1-argument construction we just transform that argument. 7272321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor if (E->getNumArgs() == 1 || 7273321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) 7274321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor return getDerived().TransformExpr(E->getArg(0)); 7275321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor 7276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); 7277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 7279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 7280f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7282b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 72847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 72857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7287f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7290ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7291aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7292aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7293aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7294aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType() && 7297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 7298c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor !ArgumentChanged) { 72991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark the constructor as referenced. 73001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: Instantiation-specific 7301c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 73023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7303c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor } 73041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73054411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), 73064411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor Constructor, E->isElidable(), 73078c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(Args), 73088c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor E->requiresZeroInitialization(), 7309428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getConstructionKind(), 7310428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getParenRange()); 7311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression. 7314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 73155132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 73165132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that. 7317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 731860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7319454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 73205132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73234765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should 73244765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated. 7325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 73264765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we 73275132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that. 7328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 732960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 73304765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 73315132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 733560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 7337ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXTemporaryObjectExpr *E) { 7338ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7339ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7340f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7342b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 7344c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getDerived().TransformDecl(E->getLocStart(), 73457c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7347f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7350ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Args.reserve(E->getNumArgs()); 7352aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7353aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7354aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 73551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7357ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 735991be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor !ArgumentChanged) { 736091be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor // FIXME: Instantiation-specific 7361ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 73623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.MaybeBindToTemporary(E); 736391be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor } 7364ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7365ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXTemporaryObjectExpr(T, 7366ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 737260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 7374454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXUnresolvedConstructExpr *E) { 7375ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7376ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7377f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7380ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7381aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->arg_size()); 7382aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 7383aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7384aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7385aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7387ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7388b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 73893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 73901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: we're faking the locations of the commas 7392ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXUnresolvedConstructExpr(T, 7393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLParenLoc(), 7394b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7398b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 739960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7400865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 74012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CXXDependentScopeMemberExpr *E) { 7402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the base of the expression. 740360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7404aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *OldBase; 7405aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7406aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType ObjectType; 7407aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->isImplicitAccess()) { 7408aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = E->getBase(); 7409aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(OldBase); 7410aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7411f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7413aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall // Start the member reference and compute the object's type. 7414b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTy; 7415d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool MayBePseudoDestructor = false; 74169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7417aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall E->getOperatorLoc(), 7418a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7419d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ObjectTy, 7420d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor MayBePseudoDestructor); 7421aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7422f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7423aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 7424b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ObjectTy.get(); 7425aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 7426aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7427aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = 0; 7428aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(E->getBaseType()); 7429aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); 7430aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 74311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74326cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // Transform the first part of the nested-name-specifier that qualifies 74336cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // the member name. 7434c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope 74356cd219879ffce00920189ec1dcea927a42602961Douglas Gregor = getDerived().TransformFirstQualifierInScope( 74367c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getFirstQualifierFoundInScope(), 74377c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getQualifierLoc().getBeginLoc()); 74381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74397c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 7440a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (E->getQualifier()) { 74417c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc 74427c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 74437c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, 74447c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor FirstQualifierInScope); 74457c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor if (!QualifierLoc) 7446f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7447a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor } 74481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 744943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 745043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 745143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 745243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 74532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 745443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 74552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7456f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7458aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->hasExplicitTemplateArgs()) { 74593b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // This is a reference to a member without an explicitly-specified 74603b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // template argument list. Optimize for this common case. 74613b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor if (!getDerived().AlwaysRebuild() && 7462aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base.get() == OldBase && 7463aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType == E->getBaseType() && 74647c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc == E->getQualifierLoc() && 74652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getMember() && 74663b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 74673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 74681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7470aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 74713b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->isArrow(), 74723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getOperatorLoc(), 74737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 7474129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall FirstQualifierInScope, 74752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7476129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /*TemplateArgs*/ 0); 74773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 74783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor 7479d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7480fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7481fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7482fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7483fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 74841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7486aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 7488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 74897c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 74903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope, 74912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7492129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall &TransArgs); 7493129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall} 7494129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7495129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived> 749660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7497454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 7498129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform the base of the expression. 749960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7500aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7501aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!Old->isImplicitAccess()) { 7502aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(Old->getBase()); 7503aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7504f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7505aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 7506aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7507aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(Old->getBaseType()); 7508aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 7509129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 75104c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 75114c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 75124c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc 75134c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 75144c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7515f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7516129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7517129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 75182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(SemaRef, Old->getMemberNameInfo(), 7519129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Sema::LookupOrdinaryName); 7520129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7521129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform all the decls. 7522129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), 7523129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = Old->decls_end(); I != E; ++I) { 75247c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 75257c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getMemberLoc(), 75267c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 75279f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 75289f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 75299f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 75309f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 75319f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 753234f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis else { 753334f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis R.clear(); 7534f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 753534f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis } 75369f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7537129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7538129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Expand using declarations. 7539129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (isa<UsingDecl>(InstD)) { 7540129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7541129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7542129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = UD->shadow_end(); I != E; ++I) 7543129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(*I); 7544129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall continue; 7545129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7546129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7547129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(InstD); 7548129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7549129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7550129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.resolveKind(); 7551129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7552c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor // Determine the naming class. 7553042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth if (Old->getNamingClass()) { 7554c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt CXXRecordDecl *NamingClass 7555c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 755666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getMemberLoc(), 755766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 755866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7559f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7560c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 756166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7562c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor } 7563c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7564129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TemplateArgumentListInfo TransArgs; 7565129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->hasExplicitTemplateArgs()) { 7566129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setLAngleLoc(Old->getLAngleLoc()); 7567129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setRAngleLoc(Old->getRAngleLoc()); 7568fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7569fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7570fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7571fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7572129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7573c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 7574c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 7575c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 7576c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 7577c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 7578c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 7579c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 75809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 7581aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7582129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getOperatorLoc(), 7583129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->isArrow(), 75844c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc, 7585c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope, 7586129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R, 7587129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall (Old->hasExplicitTemplateArgs() 7588129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall ? &TransArgs : 0)); 7589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 759260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 75932e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 7594eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 75952e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 75962e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (SubExpr.isInvalid()) 75972e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return ExprError(); 75982e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 75992e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 76003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 76012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 76022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 76032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl} 76042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 76052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived> 76062e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult 7607be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 76084f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 76094f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (Pattern.isInvalid()) 76104f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return ExprError(); 76114f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 76124f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 76134f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return SemaRef.Owned(E); 76144f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 761567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 761667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor E->getNumExpansions()); 7617be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor} 7618ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7619ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived> 7620ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult 7621ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 7622ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // If E is not value-dependent, then nothing will change when we transform it. 7623ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: This is an instantiation-centric view. 7624ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!E->isValueDependent()) 7625ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7626ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7627ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: None of the implementations of TryExpandParameterPacks can ever 7628ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // produce a diagnostic when given only a single unexpanded parameter pack, 7629ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // so 7630ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 7631ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor bool ShouldExpand = false; 7632d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 7633cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 7634ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 7635ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor &Unexpanded, 1, 7636d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, RetainExpansion, 7637d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 7638ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return ExprError(); 7639ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7640d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!ShouldExpand || RetainExpansion) 7641ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7642be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 7643ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // We now know the length of the parameter pack, so build a new expression 7644ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // that stores that length. 7645ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), 7646ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor E->getPackLoc(), E->getRParenLoc(), 7647cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor *NumExpansions); 7648ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor} 7649ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7650be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived> 7651be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult 7652c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 7653c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SubstNonTypeTemplateParmPackExpr *E) { 7654c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Default behavior is to do nothing with this transformation. 7655c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return SemaRef.Owned(E); 7656c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor} 7657c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 7658c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived> 7659c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult 7660454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 76613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 76641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 766560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7666454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 766781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedTypeInfo 766881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 766981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor if (!EncodedTypeInfo) 7670f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 76711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 767381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 76743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 767781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo, 7678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 76801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 7682f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 7683f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 7684f85e193739c953358c865005855253af4f68a497John McCall ExprResult result = getDerived().TransformExpr(E->getSubExpr()); 7685f85e193739c953358c865005855253af4f68a497John McCall if (result.isInvalid()) return ExprError(); 7686f85e193739c953358c865005855253af4f68a497John McCall Expr *subExpr = result.take(); 7687f85e193739c953358c865005855253af4f68a497John McCall 7688f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 7689f85e193739c953358c865005855253af4f68a497John McCall subExpr == E->getSubExpr()) 7690f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 7691f85e193739c953358c865005855253af4f68a497John McCall 7692f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(new(SemaRef.Context) 7693f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); 7694f85e193739c953358c865005855253af4f68a497John McCall} 7695f85e193739c953358c865005855253af4f68a497John McCall 7696f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 7697f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 7698f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 7699f85e193739c953358c865005855253af4f68a497John McCall TypeSourceInfo *TSInfo 7700f85e193739c953358c865005855253af4f68a497John McCall = getDerived().TransformType(E->getTypeInfoAsWritten()); 7701f85e193739c953358c865005855253af4f68a497John McCall if (!TSInfo) 7702f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 7703f85e193739c953358c865005855253af4f68a497John McCall 7704f85e193739c953358c865005855253af4f68a497John McCall ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); 7705f85e193739c953358c865005855253af4f68a497John McCall if (Result.isInvalid()) 7706f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 7707f85e193739c953358c865005855253af4f68a497John McCall 7708f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 7709f85e193739c953358c865005855253af4f68a497John McCall TSInfo == E->getTypeInfoAsWritten() && 7710f85e193739c953358c865005855253af4f68a497John McCall Result.get() == E->getSubExpr()) 7711f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 7712f85e193739c953358c865005855253af4f68a497John McCall 7713f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), 7714f85e193739c953358c865005855253af4f68a497John McCall E->getBridgeKeywordLoc(), TSInfo, 7715f85e193739c953358c865005855253af4f68a497John McCall Result.get()); 7716f85e193739c953358c865005855253af4f68a497John McCall} 7717f85e193739c953358c865005855253af4f68a497John McCall 7718f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 771960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7720454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 772192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Transform arguments. 772292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor bool ArgChanged = false; 7723ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7724aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->getNumArgs()); 7725aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 7726aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 7727aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7728aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 772992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (E->getReceiverKind() == ObjCMessageExpr::Class) { 773092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Class message: transform the receiver type. 773192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor TypeSourceInfo *ReceiverTypeInfo 773292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformType(E->getClassReceiverTypeInfo()); 773392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!ReceiverTypeInfo) 7734f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7735c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 773692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 773792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 773892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 77393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 774092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 774192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new class message send. 774292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 774392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 7744f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis E->getSelectorLoc(), 774592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 774692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 774792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 774892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 774992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 775092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 775192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Instance message: transform the receiver 775292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 775392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor "Only class and instance messages may be instantiated"); 775460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver 775592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformExpr(E->getInstanceReceiver()); 775692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Receiver.isInvalid()) 7757f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 775892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 775992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 776092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 776192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 77623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7763c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 776492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new instance message send. 77659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCMessageExpr(Receiver.get(), 776692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 7767f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis E->getSelectorLoc(), 776892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 776992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 777092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 777192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 7772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 77741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 777560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7776454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 77773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 77801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 778160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7782454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 77833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 77861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 778760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7788454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 7789f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 779060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7791f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 7792f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7793f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor 7794f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // We don't need to transform the ivar; it will never change. 7795c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7796f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 7797f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 7798f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 77993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7800c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 78019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 7802f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->getLocation(), 7803f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow(), E->isFreeIvar()); 7804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 78061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 780760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7808454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 780912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // 'super' and types never change. Property never changes. Just 781012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // retain the existing expression. 781112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!E->isObjectReceiver()) 78123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 78138ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 7814e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // Transform the base expression. 781560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7816e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Base.isInvalid()) 7817f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7818c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7819e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // We don't need to transform the property; it will never change. 7820c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7821e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // If nothing changed, just retain the existing expression. 7822e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (!getDerived().AlwaysRebuild() && 7823e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Base.get() == E->getBase()) 78243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 782612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (E->isExplicitProperty()) 782712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 782812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getExplicitProperty(), 782912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 783012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 783112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 783212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getType(), 783312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertyGetter(), 783412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertySetter(), 783512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 7836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 78381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 783960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7840454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 7841f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 784260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7843f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 7844f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7845c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7846f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 7847f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 7848f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 78493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7850c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 78519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 7852f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow()); 7853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 78551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 785660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7857454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 7858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7859ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> SubExprs(SemaRef); 7860aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs.reserve(E->getNumSubExprs()); 7861aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 7862aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs, &ArgumentChanged)) 7863aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 78641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 78673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 78681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 7870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(SubExprs), 7871b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 78741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 787560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7876454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 7877c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockDecl *oldBlock = E->getBlockDecl(); 7878a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 7879c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); 7880c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 7881c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7882c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 7883ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian // We built a new blockScopeInfo in call to ActOnBlockStart 7884ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian // in above, CapturesCXXThis need be set here from the block 7885ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian // expression. 7886ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian blockScope->CapturesCXXThis = oldBlock->capturesCXXThis(); 7887ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian 7888c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall llvm::SmallVector<ParmVarDecl*, 4> params; 7889c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall llvm::SmallVector<QualType, 4> paramTypes; 7890a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 7891a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Parameter substitution. 7892c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), 7893c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_begin(), 7894c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_size(), 7895c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 0, paramTypes, ¶ms)) 7896a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return true; 7897c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7898c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall const FunctionType *exprFunctionType = E->getFunctionType(); 7899c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType exprResultType = exprFunctionType->getResultType(); 7900c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!exprResultType.isNull()) { 7901c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!exprResultType->isDependentType()) 7902c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = exprResultType; 7903c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall else if (exprResultType != getSema().Context.DependentTy) 7904c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = getDerived().TransformType(exprResultType); 7905a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 7906a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 7907a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // If the return type has not been determined yet, leave it as a dependent 7908a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // type; it'll get set when we process the body. 7909c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType.isNull()) 7910c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = getSema().Context.DependentTy; 7911a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 7912a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // Don't allow returning a objc interface by value. 7913c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType->isObjCObjectType()) { 7914c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall getSema().Diag(E->getCaretLocation(), 7915a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor diag::err_object_cannot_be_passed_returned_by_value) 7916c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall << 0 << blockScope->ReturnType; 7917a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return ExprError(); 7918a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor } 7919711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 7920c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType functionType = getDerived().RebuildFunctionProtoType( 7921c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType, 7922c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.data(), 7923c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.size(), 7924c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->isVariadic(), 7925c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 0, RQ_None, 7926c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall exprFunctionType->getExtInfo()); 7927c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->FunctionType = functionType; 7928711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 7929711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Set the parameters on the block decl. 7930c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!params.empty()) 7931c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setParams(params.data(), params.size()); 7932a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 7933a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // If the return type wasn't explicitly set, it will have been marked as a 7934a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // dependent type (DependentTy); clear out the return type setting so 7935a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // we will deduce the return type when type-checking the block's body. 7936c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType == getSema().Context.DependentTy) 7937c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = QualType(); 7938a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 7939711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Transform the body 7940c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall StmtResult body = getDerived().TransformStmt(E->getBody()); 7941c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (body.isInvalid()) 7942711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return ExprError(); 7943711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 7944c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG 7945c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // In builds with assertions, make sure that we captured everything we 7946c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // captured before. 7947fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (!SemaRef.getDiagnostics().hasErrorOccurred()) { 7948fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), 7949fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor e = oldBlock->capture_end(); i != e; ++i) { 7950fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *oldCapture = i->getVariable(); 7951fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor 7952fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor // Ignore parameter packs. 7953fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (isa<ParmVarDecl>(oldCapture) && 7954fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<ParmVarDecl>(oldCapture)->isParameterPack()) 7955fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor continue; 7956c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7957fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *newCapture = 7958fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 7959fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor oldCapture)); 7960fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor assert(blockScope->CaptureMap.count(newCapture)); 7961fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor } 7962c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall } 7963c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif 7964c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7965c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 7966c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall /*Scope=*/0); 7967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 79691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 797060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7971454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { 7972a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ValueDecl *ND 7973a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 7974a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian E->getDecl())); 7975a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!ND) 7976f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 79772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7978a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!getDerived().AlwaysRebuild() && 7979a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ND == E->getDecl()) { 7980a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Mark it referenced in the new context regardless. 7981a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // FIXME: this is a bit instantiation-specific. 7982a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 7983a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 79843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7985a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 7986a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 79872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); 798840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), 79892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ND, NameInfo, 0); 7990b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 79911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 799261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnertemplate<typename Derived> 799361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerExprResult 799461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { 799561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner assert(false && "Cannot transform asType expressions yet"); 799661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return SemaRef.Owned(E); 799761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner} 799861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 7999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction 8001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 800485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 800585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 80062865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildPointerType(PointeeType, Star, 8007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8008b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 801185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 801285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 80132865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildBlockPointerType(PointeeType, Star, 8014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 80181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 801985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 802085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool WrittenAsLValue, 802185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 80222865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 802385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 80271eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 802885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 802985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType ClassType, 803085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 80312865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 803285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8033577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8034577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8035577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 80361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 8037577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType, 8038577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8039577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 8040577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 8041577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8042577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 8043577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (SizeExpr || !Size) 8044577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 8045577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 8046577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseEntity()); 80471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 80481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Types[] = { 80491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 80501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 80511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 8052577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor }; 8053577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const unsigned NumTypes = sizeof(Types) / sizeof(QualType); 8054577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType SizeType; 8055577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor for (unsigned I = 0; I != NumTypes; ++I) 8056577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 8057577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SizeType = Types[I]; 8058577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor break; 8059577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 80601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 80619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, 80629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME*/BracketsRange.getBegin()); 80631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, 8064577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 80651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDerived().getBaseEntity()); 8066577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 80671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8068577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 80691eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 80701eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 8071577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8072577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 807385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 807485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 80751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, 807685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8077577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8078577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8079577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 80801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 80811eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 8082577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 808385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 808485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 80851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, 808685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8087577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 80881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8089577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 80901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 80911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 8092577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 80939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8094577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8095577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 80961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 80979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8098577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8099577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8100577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8101577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 81021eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 81031eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 8104577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 81059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8106577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8107577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 81081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 81099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8110577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 8115e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson unsigned NumElements, 8116e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind) { 8117577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor // FIXME: semantic checking! 8118e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 8119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 81201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 8123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumElements, 8124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 8125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 8126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NumElements, true); 8127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IntegerLiteral *VectorSize 81289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 81299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis AttributeLoc); 81309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 8131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 81321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 81341eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 81351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 81369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 81389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 8139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 81401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, 81431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 8144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 81451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool Variadic, 8146fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman unsigned Quals, 8147c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 8148fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info) { 81491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, 8150c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor Quals, RefQualifier, 8151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseLocation(), 8152fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman getDerived().getBaseEntity(), 8153fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman Info); 8154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 81551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8156577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8157a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 8158a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return SemaRef.Context.getFunctionNoProtoType(T); 8159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 8160a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 8161a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 8162ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { 8163ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(D && "no decl found"); 8164ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (D->isInvalidDecl()) return QualType(); 8165ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 816692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // FIXME: Doesn't account for ObjCInterfaceDecl! 8167ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeDecl *Ty; 8168ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (isa<UsingDecl>(D)) { 8169ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingDecl *Using = cast<UsingDecl>(D); 8170ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(Using->isTypeName() && 8171ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-typename using"); 8172ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8173ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // A valid resolved using typename decl points to exactly one type decl. 8174ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(++Using->shadow_begin() == Using->shadow_end()); 8175ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 8176c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8177ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } else { 8178ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(isa<UnresolvedUsingTypenameDecl>(D) && 8179ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-using decl"); 8180ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<UnresolvedUsingTypenameDecl>(D); 8181ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 8182ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8183ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return SemaRef.Context.getTypeDeclType(Ty); 8184ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 8185ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8186ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> 81872a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 81882a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 81892a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildTypeofExprType(E, Loc); 8190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 8194577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeOfType(Underlying); 8195577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8196577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8197577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 81982a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 81992a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 82002a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildDecltypeType(E, Loc); 8201577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8202577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8203577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8204ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, 8205ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 8206ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc) { 8207ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); 8208ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 8209ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 8210ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 8211577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 8212833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateName Template, 8213833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateNameLoc, 821467714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &TemplateArgs) { 8215d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 8216577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 82171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8218dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 82191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 8220fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8221d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 8222d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template) { 8223fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, 8224d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor Template); 8225d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 8226d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 8227d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 82281eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 8229fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8230fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 8231fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 823243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 823343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 8234fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor UnqualifiedId TemplateName; 8235fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName.setIdentifier(&Name, NameLoc); 8236d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 8237d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 8238fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /*FIXME:*/SourceLocation(), 8239d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 8240fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName, 8241b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 8242d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 8243d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 824443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return Template.get(); 8245d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 82461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 8248ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 8249fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8250ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 8251fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 8252ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType) { 8253ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId Name; 8254fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // FIXME: Bogus location information. 8255fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; 8256fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); 8257d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 8258d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 8259fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /*FIXME:*/SourceLocation(), 8260d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 8261d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Name, 8262b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 8263d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 8264d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 8265d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return Template.template getAsVal<TemplateName>(); 8266ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 8267c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8268ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived> 826960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8270b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 8271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 82729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *OrigCallee, 82739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 82749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second) { 82759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee = OrigCallee->IgnoreParenCasts(); 82769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 82771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Determine whether this should be a builtin operation. 8279f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) { 82809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 82819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) 82829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinArraySubscriptExpr(First, 82839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee->getLocStart(), 82849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second, OpLoc); 82851a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman } else if (Op == OO_Arrow) { 82861a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman // -> is never a builtin operation. 82879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); 82889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall } else if (Second == 0 || isPostIncDec) { 82899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType()) { 8290b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The argument is not of overloadable type, so try to create a 8291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // built-in unary operation. 82922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 8293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 82941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 82959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 8296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 8297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } else { 82989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 82999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) { 8300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Neither of the arguments is an overloadable type, so try to 8301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // create a built-in binary operation. 83022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 830360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 83049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 8305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 8306f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 83071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 8309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 8310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 83111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Compute the transformed set of functions (and function templates) to be 8313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // used during overload resolution. 83146e26689f5d513e24ad7783a4493201930fdeccc0John McCall UnresolvedSet<16> Functions; 83151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 8317ba13543329afac4a0d01304ec2ec4924d99306a6John McCall assert(ULE->requiresADL()); 8318ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 8319ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // FIXME: Do we have to check 8320ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // IsAcceptableNonMemberOperatorCandidate for each of these? 83216e26689f5d513e24ad7783a4493201930fdeccc0John McCall Functions.append(ULE->decls_begin(), ULE->decls_end()); 8322ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } else { 83239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); 8324ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 83251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Add any functions found via argument-dependent lookup. 83279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Args[2] = { First, Second }; 83289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall unsigned NumArgs = 1 + (Second != 0); 83291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for unary operators. 8331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (NumArgs == 1 || isPostIncDec) { 83322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 8333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 83349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); 8335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 83361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8337f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) 83389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), 8339ba13543329afac4a0d01304ec2ec4924d99306a6John McCall OpLoc, 83409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First, 83419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second); 8342f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl 8343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for binary operators. 83442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 834560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 8346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); 8347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 8348f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 83491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 8351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 83521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 835326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived> 835460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 83559ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 835626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation OperatorLoc, 835726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor bool isArrow, 8358f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 835926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 836026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 8361fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 8362a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed) { 83639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 83649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (Base->isTypeDependent() || Destroyed.getIdentifier() || 836526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor (!isArrow && !BaseType->getAs<RecordType>()) || 8366c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (isArrow && BaseType->getAs<PointerType>() && 8367bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif !BaseType->getAs<PointerType>()->getPointeeType() 8368bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif ->template getAs<RecordType>())){ 836926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // This pseudo-destructor expression is still a pseudo-destructor. 83709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, 837126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor isArrow? tok::arrow : tok::period, 8372fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SS, ScopeType, CCLoc, TildeLoc, 8373a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed, 837426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*FIXME?*/true); 837526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 83762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8377a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 83782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 83792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 83802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 83812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.setNamedTypeInfo(DestroyedType); 83822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 838326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // FIXME: the ScopeType should be tacked onto SS. 83842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 83859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, 838626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor OperatorLoc, isArrow, 838726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SS, /*FIXME: FirstQualifier*/ 0, 83882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 838926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*TemplateArgs*/ 0); 839026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor} 839126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 8392577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang 8393577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8394577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H 8395