TreeTransform.h revision 9e876876afc13aa671cc11a17c19907c599b9ab9
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" 24657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h" 25b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h" 26b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h" 2743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h" 2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h" 2943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h" 3019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h" 3119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h" 32b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h" 33a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h" 347e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h" 35577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm> 36577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 37577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang { 38781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema; 391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one 41577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another. 42577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of 441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide 451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template 46577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the 47577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the 48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar 49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and 50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters. 51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow 531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can 54577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an 55577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The 56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual. 57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which 59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node 60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions, 61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST 62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation 63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g., 64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes 65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create 66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node. 67577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The 69670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(), 70577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), 71577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely 72577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations. 73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the 75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g., 7643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously, 77577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template 79577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX 80577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change. 81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild 82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may 83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps. 84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one 861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation 87577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their 88577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the 89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking 90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()). 91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform { 93d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief Private RAII object that helps us forget and then re-remember 94d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// the template argument corresponding to a partially-substituted parameter 95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// pack. 96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor class ForgetPartiallySubstitutedPackRAII { 97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Derived &Self; 98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor TemplateArgument Old; 99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor public: 101d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { 102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Old = Self.ForgetPartiallySubstitutedPack(); 103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ~ForgetPartiallySubstitutedPackRAII() { 106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Self.RememberPartiallySubstitutedPack(Old); 107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor }; 109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 110577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected: 111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &SemaRef; 1128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Initializes a new tree transformer. 115b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } 1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 117577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Derived &getDerived() { return static_cast<Derived&>(*this); } 119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Derived &getDerived() const { 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return static_cast<const Derived&>(*this); 123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 12560d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline ExprResult Owned(Expr *E) { return E; } 12660d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline StmtResult Owned(Stmt *S) { return S; } 1279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall 128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the semantic analysis object used for 129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// this tree transform. 130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &getSema() const { return SemaRef; } 1311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Whether the transformation should always rebuild AST nodes, even 133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// if none of the children have changed. 134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this function to specify when the transformation 136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// should rebuild all AST nodes. 137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlwaysRebuild() { return false; } 1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the location of the entity being transformed, if that 140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, returns no source-location information. Subclasses can 143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// provide an alternative implementation that provides better location 144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information. 145577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation getBaseLocation() { return SourceLocation(); } 1461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the name of the entity being transformed, if that 148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, returns an empty name. Subclasses can provide an alternative 151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// implementation with a more precise name. 152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor DeclarationName getBaseEntity() { return DeclarationName(); } 153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Sets the "base" location and entity when that 155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// information is known based on another transformation. 156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, the source location and entity are ignored. Subclasses can 158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// override this function to provide a customized implementation. 159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor void setBase(SourceLocation Loc, DeclarationName Entity) { } 1601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief RAII object that temporarily sets the base location and entity 162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// used for reporting diagnostics in types. 163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor class TemporaryBase { 164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TreeTransform &Self; 165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OldLocation; 166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclarationName OldEntity; 1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor public: 169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase(TreeTransform &Self, SourceLocation Location, 1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName Entity) : Self(Self) { 171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldLocation = Self.getDerived().getBaseLocation(); 172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldEntity = Self.getDerived().getBaseEntity(); 173ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor 174ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor if (Location.isValid()) 175ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor Self.getDerived().setBase(Location, Entity); 176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ~TemporaryBase() { 179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Self.getDerived().setBase(OldLocation, OldEntity); 180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor }; 1821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determine whether the given type \p T has already been 184577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// transformed. 185577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses can provide an alternative implementation of this routine 1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// to short-circuit evaluation when it is known that a given type will 188577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// not change. For example, template instantiation need not traverse 189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// non-dependent types. 190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlreadyTransformed(QualType T) { 191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T.isNull(); 192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 1946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether the given call argument should be dropped, e.g., 1956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// because it is a default argument. 1966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 1976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Subclasses can provide an alternative implementation of this routine to 1986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// determine which kinds of call arguments get dropped. By default, 1996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// CXXDefaultArgument nodes are dropped (prior to transformation). 2006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool DropCallArgument(Expr *E) { 2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return E->isDefaultArgument(); 2026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 203c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Determine whether we should expand a pack expansion with the 2058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// given set of parameter packs into separate arguments by repeatedly 2068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// transforming the pattern. 2078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 208b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor /// By default, the transformer never tries to expand pack expansions. 2098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// Subclasses can override this routine to provide different behavior. 2108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param EllipsisLoc The location of the ellipsis that identifies the 2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pack expansion. 2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param PatternRange The source range that covers the entire pattern of 2158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// the pack expansion. 2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param Unexpanded The set of unexpanded parameter packs within the 2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pattern. 2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumUnexpanded The number of unexpanded parameter packs in 2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \p Unexpanded. 2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param ShouldExpand Will be set to \c true if the transformer should 2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// expand the corresponding pack expansions into separate arguments. When 2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// set, \c NumExpansions must also be set. 2268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 227d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \param RetainExpansion Whether the caller should add an unexpanded 228d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// pack expansion after all of the expanded arguments. This is used 229d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// when extending explicitly-specified template argument packs per 230d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// C++0x [temp.arg.explicit]p9. 231d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 2328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumExpansions The number of separate arguments that will be in 233cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// the expanded form of the corresponding pack expansion. This is both an 234cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// input and an output parameter, which can be set by the caller if the 235cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// number of expansions is known a priori (e.g., due to a prior substitution) 236cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// and will be set by the callee when the number of expansions is known. 237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// The callee must set this value when \c ShouldExpand is \c true; it may 238cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// set this value in other cases. 2398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \returns true if an error occurred (e.g., because the parameter packs 2418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// are to be instantiated with arguments of different lengths), false 2428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// must be set. 2448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool TryExpandParameterPacks(SourceLocation EllipsisLoc, 2458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceRange PatternRange, 2468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor const UnexpandedParameterPack *Unexpanded, 2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor unsigned NumUnexpanded, 2488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool &ShouldExpand, 249d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool &RetainExpansion, 250cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> &NumExpansions) { 2518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ShouldExpand = false; 2528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return false; 2538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 2548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 255d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief "Forget" about the partially-substituted pack template argument, 256d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// when performing an instantiation that must preserve the parameter pack 257d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// use. 258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// This routine is meant to be overridden by the template instantiator. 260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor TemplateArgument ForgetPartiallySubstitutedPack() { 261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return TemplateArgument(); 262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief "Remember" the partially-substituted pack template argument 265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// after performing an instantiation that must preserve the parameter pack 266d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// use. 267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// This routine is meant to be overridden by the template instantiator. 269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } 270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 27112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// \brief Note to the derived class when a function parameter pack is 27212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// being expanded. 27312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } 27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor 275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transforms the given type into another type. 276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by creating a 278a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// TypeSourceInfo for it and delegating to the appropriate 279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// function. This is expensive, but we don't mind, because 280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// this method is deprecated anyway; all users should be 281a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// switched to storing TypeSourceInfos. 282577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \returns the transformed type. 28443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(QualType T); 2851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transforms the given type-with-location into a new 287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type-with-location. 288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// 289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by delegating to the 290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// appropriate TransformXXXType to build a new type. Subclasses 291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// may override this function (to take over all type 292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// transformations) or some set of the TransformXXXType functions 293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// to alter the transformation. 29443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TransformType(TypeSourceInfo *DI); 295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transform the given type-with-location into a new 297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type, collecting location information in the given builder 298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// as necessary. 299577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 30043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); 3011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 302657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given statement. 303577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 3041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this routine transforms a statement by delegating to the 30543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// appropriate TransformXXXStmt function to transform a specific kind of 30643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// statement or the TransformExpr() function to transform an expression. 30743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to transform statements using some 30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// other mechanism. 30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \returns the transformed statement. 31160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformStmt(Stmt *S); 3121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 313657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given expression. 314657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// 315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine transforms an expression by delegating to the 316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// appropriate TransformXXXExpr function to build a new expression. 317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this function to transform expressions using some 318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// other mechanism. 319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \returns the transformed expression. 32160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformExpr(Expr *E); 3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 323aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Transform the given list of expressions. 324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// This routine transforms a list of expressions by invoking 326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \c TransformExpr() for each subexpression. However, it also provides 327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// support for variadic templates by expanding any pack expansions (if the 328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// derived class permits such expansion) along the way. When pack expansions 329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// are present, the number of outputs may not equal the number of inputs. 330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Inputs The set of expressions to be transformed. 332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param NumInputs The number of expressions in \c Inputs. 334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param IsCall If \c true, then this transform is being performed on 336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// function-call arguments, and any arguments that should be dropped, will 337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// be. 338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 339aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Outputs The transformed input expressions will be added to this 340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// vector. 341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param ArgChanged If non-NULL, will be set \c true if any argument changed 343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// due to transformation. 344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \returns true if an error occurred, false otherwise. 346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, 347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor llvm::SmallVectorImpl<Expr *> &Outputs, 348aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged = 0); 349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given declaration, which is referenced from a type 351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// or expression. 352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 353dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, acts as the identity function on declarations. Subclasses 354dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// may override this function to provide alternate behavior. 3557c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } 35643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 35743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Transform the definition of the given declaration. 35843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, invokes TransformDecl() to transform the declaration. 36043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 361c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Decl *TransformDefinition(SourceLocation Loc, Decl *D) { 362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().TransformDecl(Loc, D); 3637c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor } 3641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3656cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// \brief Transform the given declaration, which was the first part of a 3666cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// nested-name-specifier in a member access expression. 3676cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 368c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// This specific declaration transformation only applies to the first 3696cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// identifier in a nested-name-specifier of a member access expression, e.g., 3706cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// the \c T in \c x->T::member 3716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 3726cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// By default, invokes TransformDecl() to transform the declaration. 3736cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// Subclasses may override this function to provide alternate behavior. 374c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { 375c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); 3766cd219879ffce00920189ec1dcea927a42602961Douglas Gregor } 377c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given nested-name-specifier. 379577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, transforms all of the types and declarations within the 381dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// nested-name-specifier. Subclasses may override this function to provide 382dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// alternate behavior. 383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, 384a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor SourceRange Range, 385c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor QualType ObjectType = QualType(), 386c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// \brief Transform the given nested-name-specifier with source-location 389c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// information. 390c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// 391c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// By default, transforms all of the types and declarations within the 392c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// nested-name-specifier. Subclasses may override this function to provide 393c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// alternate behavior. 394c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( 395c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 396c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType = QualType(), 397c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 398c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 39981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// \brief Transform the given declaration name. 40081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// 40181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// By default, transforms the types of conversion function, constructor, 40281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// and destructor names and then (if needed) rebuilds the declaration name. 40381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// Identifiers and selectors are returned unmodified. Sublcasses may 40481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// override this function to provide alternate behavior. 4052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo 40643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); 4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 408577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template name. 4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 410d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, transforms the template name by transforming the declarations 4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and nested-name-specifiers that occur within the template name. 412d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 4133b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor TemplateName TransformTemplateName(TemplateName Name, 41443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType = QualType(), 41543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope = 0); 4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 417577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template argument. 418577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this operation transforms the type, expression, or 4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// declaration stored within the template argument and constructs a 421670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// new template argument from the transformed result. Subclasses may 422670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// override this function to provide alternate behavior. 423833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// 424833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Returns true if there was an error. 425833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall bool TransformTemplateArgument(const TemplateArgumentLoc &Input, 426833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output); 427833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 428fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \brief Transform the given set of template arguments. 429fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 430fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// By default, this operation transforms all of the template arguments 431fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 432fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// the transformed arguments to the output list. 433fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 4347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// Note that this overload of \c TransformTemplateArguments() is merely 4357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// a convenience function. Subclasses that wish to override this behavior 4367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// should override the iterator-based member template version. 4377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 438fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Inputs The set of template arguments to be transformed. 439fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 440fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param NumInputs The number of template arguments in \p Inputs. 441fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 442fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Outputs The set of transformed template arguments output by this 443fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// routine. 444fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 445fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// Returns true if an error occurred. 446fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, 447fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor unsigned NumInputs, 4487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs) { 4497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); 4507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 4517f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 4527f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \brief Transform the given set of template arguments. 4537f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4547f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// By default, this operation transforms all of the template arguments 4557f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 4567f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// the transformed arguments to the output list. 4577f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param First An iterator to the first template argument. 4597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 4607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param Last An iterator one step past the last template argument. 4617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \param Outputs The set of transformed template arguments output by this 4637f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// routine. 4647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4657f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// Returns true if an error occurred. 4667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename InputIterator> 4677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor bool TransformTemplateArguments(InputIterator First, 4687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 4697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs); 4707f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 471833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. 472833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void InventTemplateArgumentLoc(const TemplateArgument &Arg, 473833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &ArgLoc); 474833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 475a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// \brief Fakes up a TypeSourceInfo for a type. 476a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *InventTypeSourceInfo(QualType T) { 477a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return SemaRef.Context.getTrivialTypeSourceInfo(T, 478833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().getBaseLocation()); 479833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 481a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 482a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 48343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); 484a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 485577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 48643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 48743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformTemplateSpecializationType(TypeLocBuilder &TLB, 48843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL, 48943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template); 49043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 49143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 49243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 49343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL, 494a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template); 495a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 496a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType 497a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 498a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 49943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix); 50043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 50121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms the parameters of a function type into the 50221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// given vectors. 50321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 50421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// The result vectors should be kept in sync; null entries in the 50521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// variables vector are acceptable. 50621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 50721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// Return true on error. 508a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor bool TransformFunctionTypeParams(SourceLocation Loc, 509a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 510a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 51121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVectorImpl<QualType> &PTypes, 512a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor llvm::SmallVectorImpl<ParmVarDecl*> *PVars); 51321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 51421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms a single function-type parameter. Return null 51521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// on error. 5166a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, 5176a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions); 51821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 51943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); 520833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 52160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); 52260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); 5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 52560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Transform##Node(Node *S); 526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 52760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Transform##Node(Node *E); 5287381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 5294bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new pointer type given its pointee type. 532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 533577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the pointer type. 534577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 53585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 536577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 537577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new block pointer type given its pointee type. 538577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis when building the block pointer 540577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 54185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 542577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 54385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \brief Build a new reference type given the type it references. 544577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 54585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// By default, performs semantic analysis when building the 54685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// reference type. Subclasses may override this routine to provide 54785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// different behavior. 548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 54985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \param LValue whether the type was written with an lvalue sigil 55085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// or an rvalue sigil. 55185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildReferenceType(QualType ReferentType, 55285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool LValue, 55385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 5541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 555577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new member pointer type given the pointee type and the 556577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// class type it refers into. 557577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 558577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the member pointer 559577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 56085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 56185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 5621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 563577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new array type given the element type, size 564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, size of the array (if known), size expression, and index type 565577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// qualifiers. 566577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 567577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 568577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Also by default, all of the other Rebuild*Array 570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildArrayType(QualType ElementType, 571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 5761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new constant array type given the element type, size 578577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, (known) size of the array, and index type qualifiers. 579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildConstantArrayType(QualType ElementType, 583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 58585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 58685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new incomplete array type given the element type, size 589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, and index type qualifiers. 590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 592577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildIncompleteArrayType(QualType ElementType, 594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 59585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 59685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new variable-length array type given the element type, 599577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 601577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 602577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildVariableArrayType(QualType ElementType, 604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new dependent-sized array type given the element type, 610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 611577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedArrayType(QualType ElementType, 615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 619577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new vector type given the element type and 621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 62582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 626e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind); 6271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new extended vector type given the element type and 629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new potentially dependently-sized extended vector type 637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// given the element type and 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. 6411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedExtVectorType(QualType ElementType, 6429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 643577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new function type. 646577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the function type. 648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildFunctionProtoType(QualType T, 6501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 651577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 652fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman bool Variadic, unsigned Quals, 653c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 654fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info); 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 656a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Build a new unprototyped function type. 657a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType RebuildFunctionNoProtoType(QualType ResultType); 658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 659ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// \brief Rebuild an unresolved typename type, given the decl that 660ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// the UnresolvedUsingTypenameDecl was transformed to. 661ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType RebuildUnresolvedUsingType(Decl *D); 662ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typedef type. 664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypedefType(TypedefDecl *Typedef) { 665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Typedef); 666577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new class/struct/union type. 669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildRecordType(RecordDecl *Record) { 670577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Record); 671577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 673577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new Enum type. 674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildEnumType(EnumDecl *Enum) { 675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Enum); 676577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 6777da2431c23ef1ee8acb114e39692246e1801afc2John McCall 6781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(expr) type. 679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typeof type. 681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6822a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); 683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(type) type. 685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, builds a new TypeOfType with the given underlying type. 687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypeOfType(QualType Underlying); 688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++0x decltype type. 690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the decltype type. 692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6932a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69534b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Build a new C++0x auto type. 69634b41d939a1328f484511c6002ba2456db879a29Richard Smith /// 69734b41d939a1328f484511c6002ba2456db879a29Richard Smith /// By default, builds a new AutoType with the given deduced type. 69834b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType RebuildAutoType(QualType Deduced) { 69934b41d939a1328f484511c6002ba2456db879a29Richard Smith return SemaRef.Context.getAutoType(Deduced); 70034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 70134b41d939a1328f484511c6002ba2456db879a29Richard Smith 702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new template specialization type. 703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the template 705577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// specialization type. Subclasses may override this routine to provide 706577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 707577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTemplateSpecializationType(TemplateName Template, 708833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateLoc, 709d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Args); 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 711075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// \brief Build a new parenthesized type. 712075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// 713075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// By default, builds a new ParenType type from the inner type. 714075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 715075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType RebuildParenType(QualType InnerType) { 716075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return SemaRef.Context.getParenType(InnerType); 717075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 718075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new qualified name type. 720577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 721465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// By default, builds a new ElaboratedType type from the keyword, 722465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// the nested-name-specifier and the named type. 723465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 72421e413fe6305a198564d436ac515497716c47844John McCall QualType RebuildElaboratedType(SourceLocation KeywordLoc, 72521e413fe6305a198564d436ac515497716c47844John McCall ElaboratedTypeKeyword Keyword, 7269e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 7279e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualType Named) { 7289e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 7299e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 7309e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Named); 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 732577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 733577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to a template-id. 734577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 735e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// By default, builds a new DependentNameType type from the 736e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// nested-name-specifier and the given type. Subclasses may override 737e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// this routine to provide different behavior. 73833500955d731c73717af52088b7fc0e7a85681e7John McCall QualType RebuildDependentTemplateSpecializationType( 73933500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 7401efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor NestedNameSpecifier *Qualifier, 7411efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SourceRange QualifierRange, 74233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 74333500955d731c73717af52088b7fc0e7a85681e7John McCall SourceLocation NameLoc, 74433500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgumentListInfo &Args) { 74533500955d731c73717af52088b7fc0e7a85681e7John McCall // Rebuild the template name. 74633500955d731c73717af52088b7fc0e7a85681e7John McCall // TODO: avoid TemplateName abstraction 74733500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateName InstName = 7481efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name, 74943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType(), 0); 75033500955d731c73717af52088b7fc0e7a85681e7John McCall 75196fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor if (InstName.isNull()) 75296fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor return QualType(); 75396fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor 75433500955d731c73717af52088b7fc0e7a85681e7John McCall // If it's still dependent, make a dependent specialization. 75533500955d731c73717af52088b7fc0e7a85681e7John McCall if (InstName.getAsDependentTemplateName()) 75633500955d731c73717af52088b7fc0e7a85681e7John McCall return SemaRef.Context.getDependentTemplateSpecializationType( 7571efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor Keyword, Qualifier, Name, Args); 75833500955d731c73717af52088b7fc0e7a85681e7John McCall 75933500955d731c73717af52088b7fc0e7a85681e7John McCall // Otherwise, make an elaborated type wrapping a non-dependent 76033500955d731c73717af52088b7fc0e7a85681e7John McCall // specialization. 76133500955d731c73717af52088b7fc0e7a85681e7John McCall QualType T = 76233500955d731c73717af52088b7fc0e7a85681e7John McCall getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 76333500955d731c73717af52088b7fc0e7a85681e7John McCall if (T.isNull()) return QualType(); 764465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 765a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Keyword == ETK_None && Qualifier == 0) 766aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor return T; 767aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor 768a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T); 7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 770577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 771577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to an identifier. 772577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 773577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typename type 774e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// (or elaborated type). Subclasses may override this routine to provide 775577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 776e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 777e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation KeywordLoc, 7782494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 7792494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor const IdentifierInfo *Id, 780e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation IdLoc) { 7814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor CXXScopeSpec SS; 7822494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor SS.Adopt(QualifierLoc); 783e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 7842494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { 7854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // If the name is still dependent, just build a new dependent name type. 7864033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!SemaRef.computeDeclContext(SS)) 7872494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getDependentNameType(Keyword, 7882494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 7892494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor Id); 7904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 7914033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 792465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (Keyword == ETK_None || Keyword == ETK_Typename) 7932494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, 794e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor *Id, IdLoc); 795465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 796465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 797465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 798e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara // We had a dependent elaborated-type-specifier that has been transformed 7994033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // into a non-dependent elaborated-type-specifier. Find the tag we're 8004033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // referring to. 801e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 8024033642464e8ba0982f88f34cffad808d247b393Douglas Gregor DeclContext *DC = SemaRef.computeDeclContext(SS, false); 8034033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!DC) 8044033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8054033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8065613876991c80a684595fe8de1f039296a0657ffJohn McCall if (SemaRef.RequireCompleteDeclContext(SS, DC)) 8075613876991c80a684595fe8de1f039296a0657ffJohn McCall return QualType(); 8085613876991c80a684595fe8de1f039296a0657ffJohn McCall 8094033642464e8ba0982f88f34cffad808d247b393Douglas Gregor TagDecl *Tag = 0; 8104033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.LookupQualifiedName(Result, DC); 8114033642464e8ba0982f88f34cffad808d247b393Douglas Gregor switch (Result.getResultKind()) { 8124033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFound: 8134033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFoundInCurrentInstantiation: 8144033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 815c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Found: 8174033642464e8ba0982f88f34cffad808d247b393Douglas Gregor Tag = Result.getAsSingle<TagDecl>(); 8184033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 819c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8204033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundOverloaded: 8214033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundUnresolvedValue: 8224033642464e8ba0982f88f34cffad808d247b393Douglas Gregor llvm_unreachable("Tag lookup cannot find non-tags"); 8234033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 824c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Ambiguous: 8264033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Let the LookupResult structure handle ambiguities. 8274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!Tag) { 831446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // Check where the name exists but isn't a tag type and use that to emit 832446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // better diagnostics. 833446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 834446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.LookupQualifiedName(Result, DC); 835446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky switch (Result.getResultKind()) { 836446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::Found: 837446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundOverloaded: 838446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundUnresolvedValue: { 839446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky NamedDecl *SomeDecl = Result.getRepresentativeDecl(); 840446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky unsigned Kind = 0; 841446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky if (isa<TypedefDecl>(SomeDecl)) Kind = 1; 842446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2; 843446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; 844446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); 845446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 846446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky } 847446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky default: 848446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // FIXME: Would be nice to highlight just the source range. 849446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 850446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky << Kind << Id << DC; 851446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 852446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky } 8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 856e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { 857e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 8584033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 8594033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8604033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8614033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8624033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Build the elaborated-type-specifier type. 8634033642464e8ba0982f88f34cffad808d247b393Douglas Gregor QualType T = SemaRef.Context.getTypeDeclType(Tag); 8642494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 8652494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 8662494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T); 867dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 8681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8692fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// \brief Build a new pack expansion type. 8702fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// 8712fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// By default, builds a new PackExpansionType type from the given pattern. 8722fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 8732fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType RebuildPackExpansionType(QualType Pattern, 8742fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor SourceRange PatternRange, 875cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 876cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 877cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, 878cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 8792fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 8802fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 881dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// \brief Build a new nested-name-specifier given the prefix and an 882dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// identifier that names the next step in the nested-name-specifier. 883dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// 884dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, performs semantic analysis when building the new 885dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// nested-name-specifier. Subclasses may override this routine to provide 886dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// different behavior. 887dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 888dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 889a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor IdentifierInfo &II, 890c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor QualType ObjectType, 891c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope); 892dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 893dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// \brief Build a new nested-name-specifier given the prefix and the 894dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// namespace named in the next step in the nested-name-specifier. 895dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// 896dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, performs semantic analysis when building the new 897dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// nested-name-specifier. Subclasses may override this routine to provide 898dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// different behavior. 899dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 900dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 901dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NamespaceDecl *NS); 902dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 903dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// \brief Build a new nested-name-specifier given the prefix and the 90414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// namespace alias named in the next step in the nested-name-specifier. 90514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// 90614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// By default, performs semantic analysis when building the new 90714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// nested-name-specifier. Subclasses may override this routine to provide 90814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// different behavior. 90914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 91014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor SourceRange Range, 91114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NamespaceAliasDecl *Alias); 91214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 91314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor /// \brief Build a new nested-name-specifier given the prefix and the 914dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// type named in the next step in the nested-name-specifier. 915dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// 916dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, performs semantic analysis when building the new 917dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// nested-name-specifier. Subclasses may override this routine to provide 918dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// different behavior. 919dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 920dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 921dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor bool TemplateKW, 922edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor QualType T); 923d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 924d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier, a flag 925d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// indicating whether the "template" keyword was provided, and the template 926d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// that the template name refers to. 927d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 928d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, builds the new template name directly. Subclasses may override 929d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// this routine to provide different behavior. 930d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, 931d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 932d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template); 933d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 934d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier and the 935d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// name that is referred to as a template. 936d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 937d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 938d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 939d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// template name. Subclasses may override this routine to provide different 940d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// behavior. 941d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, 9421efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SourceRange QualifierRange, 9433b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor const IdentifierInfo &II, 94443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 94543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope); 9461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 947ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// \brief Build a new template name given a nested name specifier and the 948ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// overloaded operator name that is referred to as a template. 949ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// 950ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// By default, performs semantic analysis to determine whether the name can 951ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 952ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// template name. Subclasses may override this routine to provide different 953ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// behavior. 954ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, 955ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 956ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType); 9571aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 9581aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// \brief Build a new template name given a template template parameter pack 9591aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// and the 9601aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// 9611aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 9621aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 9631aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// template name. Subclasses may override this routine to provide different 9641aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// behavior. 9651aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, 9661aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) { 9671aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); 9681aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 9691aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 97043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new compound statement. 97143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 97243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 97343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 97460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 97543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor MultiStmtArg Statements, 97643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation RBraceLoc, 97743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 9789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 97943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 98043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 98143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 98243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new case statement. 98343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 98443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 98543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 98660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 9879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, 98843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EllipsisLoc, 9899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 99043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc) { 9919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 99243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ColonLoc); 99343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to a new case statement. 99643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 99960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 10009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().ActOnCaseStmtBody(S, Body); 10019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return S; 100243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new default statement. 100543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 100643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 100860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, 100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc, 10109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt) { 10119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 101243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /*CurScope=*/0); 101343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new label statement. 101643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 101743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 101843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 101957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, 102057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ColonLoc, Stmt *SubStmt) { 102157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); 102243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new "if" statement. 102543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 102643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 102860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, 102957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Then, 103057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ElseLoc, Stmt *Else) { 103144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); 103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Start building a new switch statement. 103543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 103643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 103860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, 103957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Expr *Cond, VarDecl *CondVar) { 10409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, 1041d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall CondVar); 104243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to the switch statement. 104543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 104643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 104743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 104860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 104957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Stmt *Switch, Stmt *Body) { 10509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 105143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 105243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 105343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new while statement. 105443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 105543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 105643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 105757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, 105857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Body) { 10599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); 106043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 106243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new do-while statement. 106343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 106443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 106543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 106660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 1067ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation WhileLoc, SourceLocation LParenLoc, 1068ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Cond, SourceLocation RParenLoc) { 10699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 10709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, RParenLoc); 107143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 107243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 107343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new for statement. 107443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 107543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 107643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1077ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 1078ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Stmt *Init, Sema::FullExprArg Cond, 1079ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner VarDecl *CondVar, Sema::FullExprArg Inc, 1080ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation RParenLoc, Stmt *Body) { 10819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 1082ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner CondVar, Inc, RParenLoc, Body); 108343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new goto statement. 108643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 108743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 108843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1089ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, 1090ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label) { 109157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); 109243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 109343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 109443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new indirect goto statement. 109543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 109643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 109743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 109860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 1099ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation StarLoc, 1100ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Target) { 11019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 110243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new return statement. 110543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 110643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 110743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1108ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { 11099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnReturnStmt(ReturnLoc, Result); 111043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new declaration statement. 111343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 111443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 111543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 111660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, 11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation StartLoc, 111843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EndLoc) { 1119406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); 1120406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); 112143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1123703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// \brief Build a new inline asm statement. 1124703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// 1125703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// By default, performs semantic analysis to build the new statement. 1126703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// Subclasses may override this routine to provide different behavior. 112760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildAsmStmt(SourceLocation AsmLoc, 1128703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsSimple, 1129703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsVolatile, 1130703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumOutputs, 1131703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumInputs, 1132ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1133703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Constraints, 1134703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Exprs, 11359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *AsmString, 1136703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Clobbers, 1137703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson SourceLocation RParenLoc, 1138703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool MSAsm) { 1139c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 1140703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson NumInputs, Names, move(Constraints), 11419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs, AsmString, Clobbers, 1142703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson RParenLoc, MSAsm); 1143703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 11444dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 11454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @try statement. 11464dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11484dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 114960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 11509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *TryBody, 11518f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor MultiStmtArg CatchStmts, 11529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Finally) { 11539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), 11549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Finally); 11554dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 11564dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 1157be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Rebuild an Objective-C exception declaration. 1158be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1159be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new declaration. 1160be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1161be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1162be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TInfo, QualType T) { 1163c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildObjCExceptionDecl(TInfo, T, 1164c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ExceptionDecl->getIdentifier(), 1165be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor ExceptionDecl->getLocation()); 1166be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1168be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Build a new Objective-C @catch statement. 1169be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1170be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1171be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 117260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1173be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor SourceLocation RParenLoc, 1174be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var, 11759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 1176be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 11779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body); 1178be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1179c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11804dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @finally statement. 11814dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11824dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11834dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 118460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 11859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 11869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 11874dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 1188c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11898fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @throw statement. 1190d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// 1191d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1192d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 119360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 11949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 11959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1196d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 1197c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11988fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @synchronized statement. 11998fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// 12008fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// By default, performs semantic analysis to build the new statement. 12018fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// Subclasses may override this routine to provide different behavior. 120260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 12039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Object, 12049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 12059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, 12069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 12078fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor } 1208c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor 1209c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// \brief Build a new Objective-C fast enumeration statement. 1210c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// 1211c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1212c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 121360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 1214f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation LParenLoc, 1215f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Element, 1216f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Collection, 1217f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation RParenLoc, 1218f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Body) { 1219c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, 12209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element, 12219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection, 1222c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor RParenLoc, 12239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 1224c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor } 1225c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 122643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ exception declaration. 122743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 122843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new decaration. 122943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 123083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 1231a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Declarator, 123243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IdentifierInfo *Name, 123383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor SourceLocation Loc) { 123483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc); 123543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 123643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 123743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ catch statement. 123843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 123943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 124043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 124160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 1242f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall VarDecl *ExceptionDecl, 1243f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Handler) { 12449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 12459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler)); 124643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 124843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ try statement. 124943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 125043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 125143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 125260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, 1253f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *TryBlock, 1254f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiStmtArg Handlers) { 12559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); 125643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression that references a declaration. 1259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 126260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 1263f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall LookupResult &R, 1264f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall bool RequiresADL) { 1265f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 1266f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 1267f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1268f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1269f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Build a new expression that references a declaration. 1270f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// 1271f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// By default, performs semantic analysis to build the new expression. 1272f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Subclasses may override this routine to provide different behavior. 127340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 1274f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ValueDecl *VD, 1275f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall const DeclarationNameInfo &NameInfo, 1276f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TemplateArgumentListInfo *TemplateArgs) { 1277a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor CXXScopeSpec SS; 127840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 1279dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 1280dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: loses template args. 12812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 12822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); 1283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression in parentheses. 12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 128960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 1290b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParen) { 12919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 1292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1294a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Build a new pseudo-destructor expression. 12951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1296a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1297a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// Subclasses may override this routine to provide different behavior. 129860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 1299f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation OperatorLoc, 1300f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool isArrow, 1301f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 1302f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor TypeSourceInfo *ScopeType, 1303f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation CCLoc, 1304f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation TildeLoc, 1305a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed); 13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary operator expression. 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 131160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 13122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc, 13139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 13149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); 1315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Build a new builtin offsetof expression. 13188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 13198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// By default, performs semantic analysis to build the new expression. 13208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// Subclasses may override this routine to provide different behavior. 132160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 13228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type, 1323f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::OffsetOfComponent *Components, 13248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComponents, 13258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 13268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 13278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor NumComponents, RParenLoc); 13288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1329c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new sizeof or alignof expression with a type argument. 13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 133460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, 13355ab75172051a6d2ea71a80a79e81c65519fd3462John McCall SourceLocation OpLoc, 1336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool isSizeOf, SourceRange R) { 1337a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); 1338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 13401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new sizeof or alignof expression with an expression 1341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument. 13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 134560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc, 1346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool isSizeOf, SourceRange R) { 134760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 13489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R); 1349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1350f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new array subscript expression. 13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 135960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildArraySubscriptExpr(Expr *LHS, 1360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LBracketLoc, 13619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 1362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RBracketLoc) { 13639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, 13649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LBracketLoc, RHS, 1365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RBracketLoc); 1366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new call expression. 13691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1371b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 137260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 1373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Args, 1374e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation RParenLoc, 1375e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Expr *ExecConfig = 0) { 13769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, 1377e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move(Args), RParenLoc, ExecConfig); 1378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member access expression. 13811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 138460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 1385f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool isArrow, 138640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1387f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &MemberNameInfo, 1388f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ValueDecl *Member, 1389f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FoundDecl, 1390d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *ExplicitTemplateArgs, 1391f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FirstQualifierInScope) { 1392d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (!Member->getDeclName()) { 1393f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // We have a reference to an unnamed field. This is always the 1394f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // base of an anonymous struct/union member access, i.e. the 1395f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // field is always of record type. 139640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); 1397f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall assert(Member->getType()->isRecordType() && 1398f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall "unnamed member not of record type?"); 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 140040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (getSema().PerformObjectMemberConversion(Base, 140140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc.getNestedNameSpecifier(), 14026bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, Member)) 1403f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 14048aa5f407d9e4787ff08bd66e1a2fe39be174fddcDouglas Gregor 1405f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); 14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr *ME = 14079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall new (getSema().Context) MemberExpr(Base, isArrow, 14082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Member, MemberNameInfo, 1409f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall cast<FieldDecl>(Member)->getType(), 1410f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK, OK_Ordinary); 1411d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return getSema().Owned(ME); 1412d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson } 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor CXXScopeSpec SS; 141540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 141683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 14179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().DefaultFunctionArrayConversion(Base); 14189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 1419aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 14206bb8017bb9e828d118e15e59d71c66bba323c364John McCall // FIXME: this involves duplicating earlier analysis in a lot of 14216bb8017bb9e828d118e15e59d71c66bba323c364John McCall // cases; we should avoid this when possible. 14222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 14236bb8017bb9e828d118e15e59d71c66bba323c364John McCall R.addDecl(FoundDecl); 1424c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R.resolveKind(); 1425c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 14269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 1427129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 1428c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, ExplicitTemplateArgs); 1429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new binary operator expression. 14321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 143560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 14362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc, 14379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, Expr *RHS) { 14389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); 1439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new conditional operator expression. 14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1443b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 144560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildConditionalOperator(Expr *Cond, 144656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, 144756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *LHS, 144856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation ColonLoc, 144956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *RHS) { 14509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 14519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS, RHS); 1452b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C-style cast expression. 14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 145860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 14599d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 14619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 1462b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 14639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr); 1464b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new compound literal expression. 14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 147060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 147142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo, 1472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 14739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 147442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 14759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1476b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new extended vector element access expression. 14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 148260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildExtVectorElementExpr(Expr *Base, 1483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 1484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation AccessorLoc, 1485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor IdentifierInfo &Accessor) { 1486aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 1487129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall CXXScopeSpec SS; 14882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 14899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1490129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall OpLoc, /*IsArrow*/ false, 1491129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, /*FirstQualifierInScope*/ 0, 14922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 1493129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /* TemplateArgs */ 0); 1494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1496b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new initializer list expression. 14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 150060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildInitList(SourceLocation LBraceLoc, 1501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Inits, 1502e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor SourceLocation RBraceLoc, 1503e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor QualType ResultTy) { 150460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1505e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); 1506e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor if (Result.isInvalid() || ResultTy->isDependentType()) 1507e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1508c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1509e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // Patch in the result type we were given, which may have been computed 1510e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // when the initial InitListExpr was built. 1511e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); 1512e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor ILE->setType(ResultTy); 1513e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new designated initializer expression. 15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 152060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDesignatedInitExpr(Designation &Desig, 1521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg ArrayExprs, 1522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation EqualOrColonLoc, 1523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool GNUSyntax, 15249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 152560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 15279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1529f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.release(); 1532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new value-initialized expression. 15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds the implicit value initialization without performing 1538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// any semantic analysis. Subclasses may override this routine to provide 1539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 154060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildImplicitValueInitExpr(QualType T) { 1541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); 1542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new \c va_arg expression. 15451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 154860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 15499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, TypeSourceInfo *TInfo, 15502cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RParenLoc) { 15512cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara return getSema().BuildVAArgExpr(BuiltinLoc, 15529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, TInfo, 15532cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara RParenLoc); 1554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression list in parentheses. 15571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 156060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 1561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg SubExprs, 1562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1563c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, 1564f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian move(SubExprs)); 1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new address-of-label expression. 15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 15691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis, using the name of the label 1570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// rather than attempting to map the label statement itself. 1571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 157260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 1573ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation LabelLoc, LabelDecl *Label) { 157457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 1575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new GNU statement expression. 15781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 158160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildStmtExpr(SourceLocation LParenLoc, 15829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt, 1583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 15849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); 1585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new __builtin_choose_expr expression. 1588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 159160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 15929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, Expr *LHS, Expr *RHS, 1593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.ActOnChooseExpr(BuiltinLoc, 15959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, LHS, RHS, 1596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new overloaded operator call expression. 1600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// The semantic analysis provides the behavior of template instantiation, 1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// copying with transformations that turn what looks like an overloaded 16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// operator call into a use of a builtin operator, performing 1605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument-dependent lookup, etc. Subclasses may override this routine to 1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 160760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 1608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 16099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee, 16109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 16119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second); 16121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++ "named" cast expression, such as static_cast or 1614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// reinterpret_cast. 1615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine dispatches to one of the more-specific routines 16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 1618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 161960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Stmt::StmtClass Class, 1621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 16229d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 16259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (Class) { 1628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXStaticCastExprClass: 16299d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 16319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 1632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXDynamicCastExprClass: 16349d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 16369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 16371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 16399d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 16419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, 1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXConstCastExprClass: 16459d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 16479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 16481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor default: 1650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(false && "Invalid C++ named cast"); 1651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor break; 1652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1654f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ static_cast expression. 1658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 166160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 1662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 16639d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 16669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1668c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 16699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1670c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1671c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ dynamic_cast expression. 1675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 167860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 1679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 16809d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 16839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1685c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 16869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1687c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1688c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ reinterpret_cast expression. 1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 169560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 1696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 16979d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1702c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 17039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1704c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1705c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ const_cast expression. 1709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 171260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 1713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17149d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1719c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 17209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1721c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1722c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ functional-style cast expression. 1726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1729ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 1730ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1731ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor Expr *Sub, 1732ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1733ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 1734f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(&Sub, 1), 1735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(type) expression. 1739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 174260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 174357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 174457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *Operand, 1745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1746c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 174757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 1748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 175001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(expr) expression. 1752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 175560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 175657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 17579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand, 1758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 17599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 176057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 17621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 176301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(type) expression. 176401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 176501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 176601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 176701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 176801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 176901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *Operand, 177001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 177101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 177201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 177301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 177401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 177501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(expr) expression. 177601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 177701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 177801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 177901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 178001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 178101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *Operand, 178201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 178301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 178401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 178501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 178601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "this" expression. 1788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new "this" expression without performing any 17901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// semantic analysis. Subclasses may override this routine to provide 1791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 179260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 1793ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType ThisType, 1794ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor bool isImplicit) { 1795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().Owned( 1796828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, 1797828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor isImplicit)); 1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ throw expression. 1801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 180460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { 18059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXThrow(ThrowLoc, Sub); 1806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ default-argument expression. 1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new default-argument expression, which does not 1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// require any semantic analysis. Subclasses may override this routine to 1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 181360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, 1814036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 1815036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, 1816036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param)); 1817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ zero-initialization expression. 1820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1823ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 1824ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1825ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1826ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, 18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MultiExprArg(getSema(), 0, 0), 1828ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc); 1829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "new" expression. 1832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 183560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, 18361bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor bool UseGlobal, 18371bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementLParen, 18381bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg PlacementArgs, 18391bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementRParen, 18401bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceRange TypeIdParens, 18411bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocatedType, 18421bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo, 18431bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor Expr *ArraySize, 18441bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorLParen, 18451bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg ConstructorArgs, 18461bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorRParen) { 18471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getSema().BuildCXXNew(StartLoc, UseGlobal, 1848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementLParen, 1849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(PlacementArgs), 1850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementRParen, 18514bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor TypeIdParens, 18521bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedType, 18531bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedTypeInfo, 18549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize, 1855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorLParen, 1856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(ConstructorArgs), 1857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorRParen); 1858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "delete" expression. 1861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 186460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 1865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsGlobalDelete, 1866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrayForm, 18679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 1868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 18699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand); 1870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary type trait expression. 1873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 187660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, 18773d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation StartLoc, 18783d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T, 18793d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation RParenLoc) { 18803d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); 1881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 18836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// \brief Build a new binary type trait expression. 18846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// 18856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// By default, performs semantic analysis to build the new expression. 18866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Subclasses may override this routine to provide different behavior. 18876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, 18886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation StartLoc, 18896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT, 18906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT, 18916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParenLoc) { 18926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); 18936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 18946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new (previously unresolved) declaration reference 1896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 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. 190000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor ExprResult RebuildDependentScopeDeclRefExpr( 190100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 19022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 1903f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall const TemplateArgumentListInfo *TemplateArgs) { 1904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 190500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SS.Adopt(QualifierLoc); 1906f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1907f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (TemplateArgs) 19082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, 1909f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall *TemplateArgs); 1910f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 19112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); 1912b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new template-id expression. 1915b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1917b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 191860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 1919f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult &R, 1920f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool RequiresADL, 1921d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &TemplateArgs) { 1922f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); 1923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1924b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction 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 RebuildCXXConstructExpr(QualType T, 19304411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor SourceLocation Loc, 1931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor, 1932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsElidable, 19338c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor MultiExprArg Args, 19348c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor bool RequiresZeroInit, 1935428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth CXXConstructExpr::ConstructionKind ConstructKind, 1936428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange ParenRange) { 1937ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConvertedArgs(SemaRef); 1938c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, 19394411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor ConvertedArgs)) 1940f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1941c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 19424411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, 19438c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(ConvertedArgs), 1944428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth RequiresZeroInit, ConstructKind, 1945428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth ParenRange); 1946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 1949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1952ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 1953ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1954ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 1955ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1956ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 1958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 1963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1966ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 1967ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1968ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 1969ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1970ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 1971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 1972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 1973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member reference expression. 1977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 198060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 19817c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualType BaseType, 19827c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor bool IsArrow, 19837c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SourceLocation OperatorLoc, 19847c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1985129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NamedDecl *FirstQualifierInScope, 19862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 1987129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 1988b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 19897c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SS.Adopt(QualifierLoc); 19901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 1992aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 1993129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 19942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberNameInfo, 19952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemplateArgs); 1996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1997b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1998129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Build a new member reference expression. 19993b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// 20003b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// By default, performs semantic analysis to build the new expression. 20013b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// Subclasses may override this routine to provide different behavior. 200260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, 2003aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType, 2004129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 2005129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool IsArrow, 20064c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2007c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope, 2008129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall LookupResult &R, 2009129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 20103b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor CXXScopeSpec SS; 20114c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 20121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2014aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2015c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall SS, FirstQualifierInScope, 2016c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, TemplateArgs); 20173b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20192e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// \brief Build a new noexcept expression. 20202e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// 20212e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// By default, performs semantic analysis to build the new expression. 20222e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// Subclasses may override this routine to provide different behavior. 20232e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 20242e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 20252e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 20262e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 2027ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Build a new expression to compute the length of a parameter pack. 2028ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 2029ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, 2030ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc, 2031ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length) { 2032ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2033ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc, Pack, PackLoc, 2034ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor RParenLoc, Length); 2035ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 2036ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 2037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new Objective-C @encode expression. 2038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2040b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 204160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 204281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodeTypeInfo, 2043b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 204481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, 2045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc)); 20461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 2047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 204892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C class message. 204960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 205092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2051f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelectorLoc, 205292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2053c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 205492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 205592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 205692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return SemaRef.BuildClassMessage(ReceiverTypeInfo, 205792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo->getType(), 205892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2059f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLoc, 2060f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 206192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 206292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 206392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C instance message. 206460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(Expr *Receiver, 206592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2066f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelectorLoc, 206792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2068c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 206992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 207092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 20719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildInstanceMessage(Receiver, 20729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver->getType(), 207392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2074f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLoc, 2075f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 207692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 207792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 2078f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C ivar reference expression. 2079f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2080f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2081f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 208260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 2083f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor SourceLocation IvarLoc, 2084f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow, bool IsFreeIvar) { 2085f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // FIXME: We lose track of the IsFreeIvar bit. 2086f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 20879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Base = BaseArg; 2088f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, 2089f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 209060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2091f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IvarLoc, 2092d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, 2093ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall false); 2094f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.isInvalid()) 2095f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2096c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2097f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2098f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2099c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 21009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 2101c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IvarLoc, IsArrow, SS, 2102f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2103c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2104f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2105f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2106e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor 2107e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// \brief Build a new Objective-C property reference expression. 2108e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// 2109e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2110e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 211160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 2112e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor ObjCPropertyDecl *Property, 2113e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor SourceLocation PropertyLoc) { 2114e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor CXXScopeSpec SS; 21159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Base = BaseArg; 2116e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, 2117e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Sema::LookupMemberName); 2118e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor bool IsArrow = false; 211960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2120e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FIME:*/PropertyLoc, 2121d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2122e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.isInvalid()) 2123f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2124c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2125e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.get()) 2126e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor return move(Result); 2127c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 21289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 2129c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/PropertyLoc, IsArrow, 2130c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SS, 2131e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FirstQualifierInScope=*/0, 2132c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2133e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*TemplateArgs=*/0); 2134e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor } 2135c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 213612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// \brief Build a new Objective-C property reference expression. 21379cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// 21389cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// By default, performs semantic analysis to build the new expression. 213912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// Subclasses may override this routine to provide different behavior. 214012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 214112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Getter, 214212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Setter, 214312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation PropertyLoc) { 214412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // Since these expressions can only be value-dependent, we do not 214512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // need to perform semantic analysis again. 214612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Owned( 214712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 214812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall VK_LValue, OK_ObjCProperty, 214912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyLoc, Base)); 21509cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor } 21519cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor 2152f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C "isa" expression. 2153f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2154f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2155f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 215660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 2157f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow) { 2158f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 21599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Base = BaseArg; 2160f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, 2161f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 216260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2163f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IsaLoc, 2164d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2165f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.isInvalid()) 2166f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2168f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2169f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2170c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 21719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 2172c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IsaLoc, IsArrow, SS, 2173f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2174c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2175f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2176f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2177c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new shuffle vector expression. 2179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 218260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 2183f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MultiExprArg SubExprs, 2184f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation RParenLoc) { 2185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Find the declaration for __builtin_shufflevector 21861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo &Name 2187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.Context.Idents.get("__builtin_shufflevector"); 2188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 2189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 2190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); 21911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Build a reference to the __builtin_shufflevector builtin 2193b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); 21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *Callee 2195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), 2196f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK_LValue, BuiltinLoc); 2197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SemaRef.UsualUnaryConversions(Callee); 21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Build the CallExpr 2200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor unsigned NumSubExprs = SubExprs.size(); 2201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Expr **Subs = (Expr **)SubExprs.release(); 2202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, 2203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Subs, NumSubExprs, 22045291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor Builtin->getCallResultType(), 2205f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr::getValueKindForType(Builtin->getResultType()), 2206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 220760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult OwnedCall(SemaRef.Owned(TheCall)); 22081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Type-check the __builtin_shufflevector expression. 221060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); 2211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 2212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 22131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OwnedCall.release(); 22151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 2216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 221743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 22188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Build a new template argument pack expansion. 22198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 22208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// By default, performs semantic analysis to build a new pack expansion 22218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// for a template argument. Subclasses may override this routine to provide 22228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// different behavior. 22238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 2224cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 2225cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 22268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor switch (Pattern.getArgument().getKind()) { 22277a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor case TemplateArgument::Expression: { 22287a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor ExprResult Result 222967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 223067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor EllipsisLoc, NumExpansions); 22317a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor if (Result.isInvalid()) 22327a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(); 22337a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor 22347a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(Result.get(), Result.get()); 22357a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor } 2236dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 22378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Template: 2238a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgumentLoc(TemplateArgument( 2239a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getArgument().getAsTemplate(), 22402be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor NumExpansions), 2241a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getTemplateQualifierRange(), 2242a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getTemplateNameLoc(), 2243a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor EllipsisLoc); 22448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 22458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Null: 22468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Integral: 22478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Declaration: 22488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Pack: 2249a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 22508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm_unreachable("Pack expansion pattern has no parameter packs"); 22518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 22528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Type: 22538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (TypeSourceInfo *Expansion 22548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 2255cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor EllipsisLoc, 2256cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions)) 22578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 22588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expansion); 22598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor break; 22608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 22618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 22628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(); 22638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 22648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 2265dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// \brief Build a new expression pack expansion. 2266dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// 2267dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// By default, performs semantic analysis to build a new pack expansion 2268dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// for an expression. Subclasses may override this routine to provide 2269dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// different behavior. 227067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 227167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) { 227267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 2273dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2274dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 227543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate: 227643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformTypeInObjectScope(QualType T, 227743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 227843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope, 227943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix); 228043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 228143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T, 228243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 228343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope, 228443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix); 2285c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2286c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TransformTypeInObjectScope(TypeLoc TL, 2287c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2288c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope, 2289c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS); 2290577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}; 2291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 229243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 229360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { 229443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!S) 229543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return SemaRef.Owned(S); 22961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 229743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor switch (S->getStmtClass()) { 229843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::NoStmtClass: break; 22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 230043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform individual statement nodes 230143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 230243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 230363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node) 230443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) 23054bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 23061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 230743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform expressions by calling TransformExpr. 230843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) 23097381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 231043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class: 23114bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 231243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor { 231360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 231443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (E.isInvalid()) 2315f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 23161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); 231843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 23191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 23201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 232243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 23231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2325670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived> 232660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 2327b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!E) 2328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(E); 2329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (E->getStmtClass()) { 2331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::NoStmtClass: break; 2332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break; 23337381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 2334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 2335454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 23364bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 23381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 2340657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor} 2341657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor 2342657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived> 2343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs, 2344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor unsigned NumInputs, 2345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool IsCall, 2346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor llvm::SmallVectorImpl<Expr *> &Outputs, 2347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged) { 2348aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor for (unsigned I = 0; I != NumInputs; ++I) { 2349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor // If requested, drop call arguments that need to be dropped. 2350aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 2351aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (ArgChanged) 2352aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2353aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2354aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor break; 2355aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2356aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2357dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 2358dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expr *Pattern = Expansion->getPattern(); 2359dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2360dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 2361dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 2362dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 2363dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2364dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 2365dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // be expanded. 2366dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor bool Expand = true; 2367d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 236867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 236967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = Expansion->getNumExpansions(); 237067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 2371dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 2372dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Pattern->getSourceRange(), 2373dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Unexpanded.data(), 2374dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Unexpanded.size(), 2375d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, RetainExpansion, 2376d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 2377dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2378dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2379dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (!Expand) { 2380dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform a simple 2381dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // transformation on the pack expansion, producing another pack 2382dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion. 2383dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 2384dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult OutPattern = getDerived().TransformExpr(Pattern); 2385dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (OutPattern.isInvalid()) 2386dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2387dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2388dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 238967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Expansion->getEllipsisLoc(), 239067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions); 2391dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2392dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2393dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2394dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2395dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2396dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2397dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2398dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2399dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2400dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform an elementwise 2401dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion of the pattern. Do so. 2402cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 2403dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 2404dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().TransformExpr(Pattern); 2405dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2406dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2407dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 240877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.get()->containsUnexpandedParameterPack()) { 240967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), 241067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor OrigNumExpansions); 241177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.isInvalid()) 241277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 241377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 241477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 2415dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2416dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2417dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2418dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2419dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2420dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2421dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2422dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2423aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ExprResult Result = getDerived().TransformExpr(Inputs[I]); 2424aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.isInvalid()) 2425aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return true; 2426aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2427aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.get() != Inputs[I] && ArgChanged) 2428aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2429aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2430aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Outputs.push_back(Result.get()); 2431aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2432aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2433aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return false; 2434aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor} 2435aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2436aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived> 2437dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier * 2438dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, 2439a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor SourceRange Range, 2440c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor QualType ObjectType, 2441c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope) { 244243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix = NNS->getPrefix(); 24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 244443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the prefix of this nested name specifier. 2445dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor if (Prefix) { 24461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, 2447c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor ObjectType, 2448c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor FirstQualifierInScope); 2449dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor if (!Prefix) 2450dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return 0; 2451dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2453dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor switch (NNS->getKind()) { 2454dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::Identifier: 245543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Prefix) { 245643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // The object type and qualifier-in-scope really apply to the 245743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // leftmost entity. 245843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType = QualType(); 245943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope = 0; 246043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 246143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 24621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((Prefix || !ObjectType.isNull()) && 2463a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor "Identifier nested-name-specifier with no prefix or object type"); 2464a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && 2465a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor ObjectType.isNull()) 2466dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NNS; 24671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildNestedNameSpecifier(Prefix, Range, 2469a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor *NNS->getAsIdentifier(), 2470c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor ObjectType, 2471c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor FirstQualifierInScope); 24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2473dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::Namespace: { 24741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NamespaceDecl *NS 2475dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor = cast_or_null<NamespaceDecl>( 24767c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Range.getBegin(), 24777c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NNS->getAsNamespace())); 24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (!getDerived().AlwaysRebuild() && 2479dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor Prefix == NNS->getPrefix() && 2480dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NS == NNS->getAsNamespace()) 2481dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NNS; 24821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2483dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); 2484dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 24851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 248614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor case NestedNameSpecifier::NamespaceAlias: { 248714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NamespaceAliasDecl *Alias 248814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor = cast_or_null<NamespaceAliasDecl>( 248914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor getDerived().TransformDecl(Range.getBegin(), 249014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NNS->getAsNamespaceAlias())); 249114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor if (!getDerived().AlwaysRebuild() && 249214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor Prefix == NNS->getPrefix() && 249314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor Alias == NNS->getAsNamespaceAlias()) 249414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return NNS; 249514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 249614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias); 249714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor } 249814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 2499dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::Global: 2500dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor // There is no meaningful transformation that one could perform on the 2501dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor // global scope. 2502dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NNS; 25031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2504dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2505dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::TypeSpec: { 2506fbf2c945f8f8bbfe0459d45c03f9ff34bb445c81Douglas Gregor TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); 250743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0), 250843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 250943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope, 251043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall Prefix); 2511d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (T.isNull()) 2512d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return 0; 25131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2514dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor if (!getDerived().AlwaysRebuild() && 2515dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor Prefix == NNS->getPrefix() && 2516dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor T == QualType(NNS->getAsType(), 0)) 2517dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NNS; 25181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildNestedNameSpecifier(Prefix, Range, 25201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, 2521edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor T); 2522dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 2523dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 25241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2525dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor // Required to silence a GCC warning 25261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 2527dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor} 2528dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 2529dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 2530c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc 2531c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc( 2532c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 2533c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2534c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope) { 2535c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 2536c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 2537c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifier = Qualifier.getPrefix()) 2538c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifiers.push_back(Qualifier); 2539c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2540c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec SS; 2541c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor while (!Qualifiers.empty()) { 2542c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 2543c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 2544c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2545c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor switch (QNNS->getKind()) { 2546c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Identifier: 2547c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, 2548c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor *QNNS->getAsIdentifier(), 2549c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2550c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc(), 2551c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, false, SS, 2552c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, false)) 2553c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2554c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2555c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2556c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2557c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Namespace: { 2558c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceDecl *NS 2559c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceDecl>( 2560c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl( 2561c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2562c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespace())); 2563c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 2564c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2565c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2566c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2567c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::NamespaceAlias: { 2568c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceAliasDecl *Alias 2569c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceAliasDecl>( 2570c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl(Q.getLocalBeginLoc(), 2571c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespaceAlias())); 2572c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 2573c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2574c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2575c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2576c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2577c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Global: 2578c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // There is no meaningful transformation that one could perform on the 2579c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // global scope. 2580c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 2581c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2582c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2583c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2584c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpec: { 2585c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 2586c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, SS); 2587c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2588c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (!TL) 2589c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2590c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2591c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || 2592c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor (SemaRef.getLangOptions().CPlusPlus0x && 2593c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TL.getType()->isEnumeralType())) { 2594c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor assert(!TL.getType().hasLocalQualifiers() && 2595c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor "Can't get cv-qualifiers here"); 2596c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, 2597c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2598c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2599c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2600c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2601c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 2602c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor << TL.getType() << SS.getRange(); 2603c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2604c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 26057c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 2606c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 26077c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor // The qualifier-in-scope and object type only apply to the leftmost entity. 2608c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope = 0; 26097c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType = QualType(); 2610c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2611c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2612c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Don't rebuild the nested-name-specifier if we don't have to. 2613c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 2614c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor !getDerived().AlwaysRebuild()) 2615c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NNS; 2616c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2617c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // If we can re-use the source-location data from the original 2618c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // nested-name-specifier, do so. 2619c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.location_size() == NNS.getDataLength() && 2620c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 2621c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 2622c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2623c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Allocate new nested-name-specifier location information. 2624c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return SS.getWithLocInContext(SemaRef.Context); 2625c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 2626c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2627c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 26282577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo 26292577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived> 263043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 26312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name = NameInfo.getName(); 263281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor if (!Name) 26332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 263481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 263581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor switch (Name.getNameKind()) { 263681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::Identifier: 263781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 263881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCOneArgSelector: 263981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 264081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXOperatorName: 26413e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 264281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXUsingDirective: 26432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NameInfo; 26441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 264581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConstructorName: 264681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXDestructorName: 264781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConversionFunctionName: { 26482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *NewTInfo; 26492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CanQualType NewCanTy; 26502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 265143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewTInfo = getDerived().TransformType(OldTInfo); 265243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NewTInfo) 265343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return DeclarationNameInfo(); 265443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 26552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 26562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara else { 26572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewTInfo = 0; 26582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 265943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 26602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (NewT.isNull()) 26612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 26622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy = SemaRef.Context.getCanonicalType(NewT); 26632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 26641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName NewName 26662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 26672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy); 26682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NewNameInfo(NameInfo); 26692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setName(NewName); 26702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setNamedTypeInfo(NewTInfo); 26712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NewNameInfo; 267281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor } 26731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 26741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(0 && "Unknown name kind."); 26762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 267781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor} 267881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 267981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived> 26801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 26813b6afbb99a1c44b4076f8e15fb7311405941b306Douglas GregorTreeTransform<Derived>::TransformTemplateName(TemplateName Name, 268243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 268343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 26847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor SourceLocation Loc = getDerived().getBaseLocation(); 26857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor 2686d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 26871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *NNS 2688d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), 268943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall /*FIXME*/ SourceRange(Loc), 269043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 269143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope); 2692d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!NNS) 2693d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return TemplateName(); 26941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2695d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (TemplateDecl *Template = QTN->getTemplateDecl()) { 26961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateDecl *TransTemplate 26977c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); 2698d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!TransTemplate) 2699d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return TemplateName(); 27001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2701d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!getDerived().AlwaysRebuild() && 2702d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor NNS == QTN->getQualifier() && 2703d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TransTemplate == Template) 2704d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return Name; 27051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2706d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), 2707d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TransTemplate); 2708d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor } 27091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2710f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // These should be getting filtered out before they make it into the AST. 271143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall llvm_unreachable("overloaded template name survived to here"); 2712d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor } 27131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2714d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 271543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *NNS = DTN->getQualifier(); 271643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NNS) { 271743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NNS = getDerived().TransformNestedNameSpecifier(NNS, 271843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall /*FIXME:*/SourceRange(Loc), 271943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 272043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope); 272143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NNS) return TemplateName(); 272243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 272343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // These apply to the scope specifier, not the template. 272443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType = QualType(); 272543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope = 0; 272643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2728d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!getDerived().AlwaysRebuild() && 2729dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor NNS == DTN->getQualifier() && 2730dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor ObjectType.isNull()) 2731d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return Name; 27321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27331efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor if (DTN->isIdentifier()) { 27341efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor // FIXME: Bad range 27351efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SourceRange QualifierRange(getDerived().getBaseLocation()); 27361efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor return getDerived().RebuildTemplateName(NNS, QualifierRange, 27371efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor *DTN->getIdentifier(), 273843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 273943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope); 27401efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor } 2741c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2742c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), 2743ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor ObjectType); 2744d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor } 27451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2746d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 27471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateDecl *TransTemplate 27487c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); 2749d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!TransTemplate) 2750d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return TemplateName(); 27511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2752d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!getDerived().AlwaysRebuild() && 2753d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TransTemplate == Template) 2754d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return Name; 27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2756d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return TemplateName(TransTemplate); 2757d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor } 27581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27591aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor if (SubstTemplateTemplateParmPackStorage *SubstPack 27601aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack()) { 27611aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor TemplateTemplateParmDecl *TransParam 27621aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor = cast_or_null<TemplateTemplateParmDecl>( 27631aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor getDerived().TransformDecl(Loc, SubstPack->getParameterPack())); 27641aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor if (!TransParam) 27651aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return TemplateName(); 27661aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 27671aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor if (!getDerived().AlwaysRebuild() && 27681aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor TransParam == SubstPack->getParameterPack()) 27691aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return Name; 27701aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 27711aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return getDerived().RebuildTemplateName(TransParam, 27721aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstPack->getArgumentPack()); 27731aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 27741aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 2775f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // These should be getting filtered out before they reach the AST. 277643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall llvm_unreachable("overloaded function decl survived to here"); 2777f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return TemplateName(); 2778d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 2779d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 2780d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 2781833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc( 2782833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg, 2783833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2784833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation Loc = getDerived().getBaseLocation(); 2785670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor switch (Arg.getKind()) { 2786670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Null: 27879f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("null template argument in TreeTransform"); 2788833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2789833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2790833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 2791833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, 2792a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); 2793c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2794833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2795833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2796788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 2797788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); 2798788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor break; 2799a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2800a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 2801a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc); 2802a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 2803a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2804833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 2805833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); 2806833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2807833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2808833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 2809670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Integral: 2810833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 2811828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); 2812833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2813833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2814833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2815833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2816833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived> 2817833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument( 2818833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc &Input, 2819833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2820833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg = Input.getArgument(); 2821833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 2822833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 2823833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 2824833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = Input; 2825833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 28261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2827670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Type: { 2828a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = Input.getTypeSourceInfo(); 2829833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (DI == NULL) 2830a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 2831833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2832833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DI = getDerived().TransformType(DI); 2833833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!DI) return true; 2834833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2835833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 2836833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2837670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 28381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2839670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Declaration: { 2840833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: we should never have to transform one of these. 2841972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor DeclarationName Name; 2842972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) 2843972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor Name = ND->getDeclName(); 2844788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemporaryBase Rebase(*this, Input.getLocation(), Name); 28457c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); 2846833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!D) return true; 2847833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2848828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Expr *SourceExpr = Input.getSourceDeclExpression(); 2849828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (SourceExpr) { 2850828bff2079b6a91ecd7ed5b842c59527d7682789John McCall EnterExpressionEvaluationContext Unevaluated(getSema(), 2851f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 285260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(SourceExpr); 28539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceExpr = (E.isInvalid() ? 0 : E.take()); 2854828bff2079b6a91ecd7ed5b842c59527d7682789John McCall } 2855828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 2856828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); 2857833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2858670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 28591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2860788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: { 2861c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); 2862788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateName Template 2863788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor = getDerived().TransformTemplateName(Arg.getAsTemplate()); 2864788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor if (Template.isNull()) 2865788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return true; 2866c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2867788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(Template), 2868788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateQualifierRange(), 2869788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateNameLoc()); 2870788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return false; 2871788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 2872a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2873a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 2874a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor llvm_unreachable("Caller should expand pack expansions"); 2875a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2876670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Expression: { 2877670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Template argument expressions are not potentially evaluated. 28781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(getSema(), 2879f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 28801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Expr *InputExpr = Input.getSourceExpression(); 2882833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 2883833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 288460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E 2885833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = getDerived().TransformExpr(InputExpr); 2886833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (E.isInvalid()) return true; 28879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); 2888833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2889670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 28901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2891670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Pack: { 2892670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor llvm::SmallVector<TemplateArgument, 4> TransformedArgs; 2893670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor TransformedArgs.reserve(Arg.pack_size()); 28941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 2895670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor AEnd = Arg.pack_end(); 2896670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor A != AEnd; ++A) { 28971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2898833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: preserve source information here when we start 2899833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // caring about parameter packs. 2900833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2901828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc InputArg; 2902828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc OutputArg; 2903828bff2079b6a91ecd7ed5b842c59527d7682789John McCall getDerived().InventTemplateArgumentLoc(*A, InputArg); 2904828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) 2905833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2906833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2907828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TransformedArgs.push_back(OutputArg.getArgument()); 2908670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2909910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor 2910910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *TransformedArgsPtr 2911910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; 2912910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor std::copy(TransformedArgs.begin(), TransformedArgs.end(), 2913910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgsPtr); 2914910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, 2915910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgs.size()), 2916910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Input.getLocInfo()); 2917833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2918670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2919670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2921670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Work around bogus GCC warning 2922833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2923670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor} 2924670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 29257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information 29267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator. 29277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator> 29287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator { 29297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TreeTransform<Derived> &Self; 29307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter; 29317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic: 29337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 29347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 29357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef typename std::iterator_traits<InputIterator>::difference_type 29367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor difference_type; 29377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 29387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 29407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 2941fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 29427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 29437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 29447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { return &Arg; } 29467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 29477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator() { } 29497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 29517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter) 29527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Self(Self), Iter(Iter) { } 29537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator &operator++() { 29557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Iter; 29567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 2957fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor } 2958fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 29597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator operator++(int) { 29607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator Old(*this); 29617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 29627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 29637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 29647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor reference operator*() const { 29667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Result; 29677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Self.InventTemplateArgumentLoc(*Iter, Result); 29687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Result; 29697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 29707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { return pointer(**this); } 29727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocInventIterator &X, 29747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 29757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter == Y.Iter; 29767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 2977fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 29787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocInventIterator &X, 29797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 29807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter != Y.Iter; 29817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 29827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}; 29837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29847f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived> 29857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator> 29867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, 29877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 29887f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentListInfo &Outputs) { 29897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor for (; First != Last; ++First) { 29907f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentLoc Out; 29917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc In = *First; 29928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 29938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().getKind() == TemplateArgument::Pack) { 29948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Unpack argument packs, which we translate them into separate 29958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // arguments. 29967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // FIXME: We could do much better if we could guarantee that the 29977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // TemplateArgumentLocInfo for the pack expansion would be usable for 29987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // all of the template arguments in the argument pack. 29997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocInventIterator<Derived, 30007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgument::pack_iterator> 30017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator; 30027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (TransformTemplateArguments(PackLocIterator(*this, 30037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_begin()), 30047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator(*this, 30057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_end()), 30067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Outputs)) 30077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return true; 30088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().isPackExpansion()) { 30138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // We have a pack expansion, for which we will be substituting into 30148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // the pattern. 30158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation Ellipsis; 3016cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions; 30178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc Pattern 3018cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, 3019cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor getSema().Context); 30208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 30228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 30238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 30248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Determine whether the set of unexpanded parameter packs can and should 30268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // be expanded. 30278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool Expand = true; 3028d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3029cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 30308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TryExpandParameterPacks(Ellipsis, 30318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Pattern.getSourceRange(), 30328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Unexpanded.data(), 30338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Unexpanded.size(), 3034d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, 3035d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3036d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 30378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (!Expand) { 30408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform a simple 30418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // transformation on the pack expansion, producing another pack 30428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion. 30438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc OutPattern; 30448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 30458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) 30468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3048cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 3049cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 30508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (Out.getArgument().isNull()) 30518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 30548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform an elementwise 30588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion of the pattern. Do so. 3059cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 30608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 30618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 30638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 306577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().containsUnexpandedParameterPack()) { 3066cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3067cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 306877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().isNull()) 306977d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 307077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 307177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 30728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 30738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30753cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 30763cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 30773cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 30783cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 30793cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 30803cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 30813cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 30823cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 3083cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3084cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 30853cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (Out.getArgument().isNull()) 30863cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 30873cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 30883cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor Outputs.addArgument(Out); 30893cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 3090d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 30918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The simple case: 30958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(In, Out)) 30967f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return true; 30977f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 30987f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor Outputs.addArgument(Out); 30997f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor } 31007f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31017f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return false; 31027f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31037f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor} 31047f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 3105577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3106577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation 3107577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3108577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3109577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 311043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) { 3111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T; 31131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3114a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Temporary workaround. All of these transformations should 3115a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // eventually turn into transformations on TypeLocs. 3116c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 3117c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor getDerived().getBaseLocation()); 3118c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 311943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *NewDI = getDerived().TransformType(DI); 31201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3121a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (!NewDI) 3122a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 31231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3124a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return NewDI->getType(); 3125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 312843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 3129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlreadyTransformed(DI->getType())) 3130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return DI; 31311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder TLB; 31331bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 3134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLoc TL = DI->getTypeLoc(); 3135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TLB.reserve(TL.getFullDataSize()); 31361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 313743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, TL); 3138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3139a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return 0; 31401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3141a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3145a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 314643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 3147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall switch (T.getTypeLocClass()) { 3148a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 3149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 3150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall case TypeLoc::CLASS: \ 315143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); 3152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 3153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 31559f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unhandled type loc!"); 3156a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3157577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types 3160a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers 3161a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function 3162a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but 3163a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients. 31641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 31651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 316743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualifiedTypeLoc T) { 3168a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Quals = T.getType().getLocalQualifiers(); 3169a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 317043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 3171a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3172577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 31731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3174a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Silently suppress qualifiers if the result type can't be qualified. 3175a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: this is the right thing for template instantiation, but 3176a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // probably not for other clients. 3177a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result->isFunctionType() || Result->isReferenceType()) 3178a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 31791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31802865474261a608c7873b87ba4af110d17907896dJohn McCall if (!Quals.empty()) { 31812865474261a608c7873b87ba4af110d17907896dJohn McCall Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); 31822865474261a608c7873b87ba4af110d17907896dJohn McCall TLB.push<QualifiedTypeLoc>(Result); 31832865474261a608c7873b87ba4af110d17907896dJohn McCall // No location information to preserve. 31842865474261a608c7873b87ba4af110d17907896dJohn McCall } 3185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3186a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3188a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 318943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// \brief Transforms a type that was written in a scope specifier, 319043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// given an object type, the results of unqualified lookup, and 319143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// an already-instantiated prefix. 319243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// 319343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// The object type is provided iff the scope specifier qualifies the 319443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// member of a dependent member-access expression. The prefix is 319543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// provided iff the the scope specifier in which this appears has a 319643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// prefix. 319743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// 319843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// This is private to TreeTransform. 319943fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 320043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType 320143fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(QualType T, 320243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 320343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 320443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix) { 320543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 320643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return T; 320743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 320843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TSI = 3209c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation()); 321043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 321143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType, 321243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnqualLookup, Prefix); 321343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!TSI) return QualType(); 321443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TSI->getType(); 321543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 321643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 321743fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 321843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo * 321943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI, 322043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 322143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 322243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix) { 3223c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // TODO: in some cases, we might have some verification to do here. 322443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (ObjectType.isNull()) 322543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformType(TSI); 322643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 322743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType T = TSI->getType(); 322843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 322943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TSI; 323043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 323143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder TLB; 323243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result; 323343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 323443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (isa<TemplateSpecializationType>(T)) { 323543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL 323643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc()); 323743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 323843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template = 323943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(), 324043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, UnqualLookup); 324143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) return 0; 324243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 324343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall Result = getDerived() 324443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall .TransformTemplateSpecializationType(TLB, TL, Template); 324543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else if (isa<DependentTemplateSpecializationType>(T)) { 324643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL 324743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc()); 324843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 3249a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template 3250a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = SemaRef.Context.getDependentTemplateName( 3251a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getQualifier(), 3252a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getIdentifier()); 3253a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3254a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor Template = getDerived().TransformTemplateName(Template, ObjectType, 3255a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor UnqualLookup); 3256a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3257a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return 0; 3258a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3259a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL, 3260a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor Template); 326143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else { 326243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // Nothing special needs to be done for these. 326343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall Result = getDerived().TransformType(TLB, TSI->getTypeLoc()); 326443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 326543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 326643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Result.isNull()) return 0; 326743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 326843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 326943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 3270c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 3271c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTypeLoc 3272c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 3273c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 3274c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *UnqualLookup, 3275c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS) { 3276c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // FIXME: Painfully copy-paste from the above! 3277c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3278c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType T = TL.getType(); 3279c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3280c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return TL; 3281c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3282c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLocBuilder TLB; 3283c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType Result; 3284c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3285c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (isa<TemplateSpecializationType>(T)) { 3286c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TemplateSpecializationTypeLoc SpecTL 3287c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3288c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3289c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TemplateName Template = 3290c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(), 3291c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, UnqualLookup); 3292c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Template.isNull()) 3293c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return TypeLoc(); 3294c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3295c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3296c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Template); 3297c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else if (isa<DependentTemplateSpecializationType>(T)) { 3298c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3299c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3300c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3301a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template 33027c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor = getDerived().RebuildTemplateName(SS.getScopeRep(), SS.getRange(), 33037c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 33047c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, UnqualLookup); 3305a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3306a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return TypeLoc(); 3307a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3308c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3309a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor SpecTL, 3310a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor Template); 3311c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else { 3312c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Nothing special needs to be done for these. 3313c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformType(TLB, TL); 3314c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 3315c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3316c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Result.isNull()) 3317c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return TypeLoc(); 3318c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3319c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); 3320c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 3321c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3322a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline 3323a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 3324a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TyLoc NewT = TLB.push<TyLoc>(T.getType()); 3325a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewT.setNameLoc(T.getNameLoc()); 3326a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return T.getType(); 3327a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3328a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3330a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 333143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BuiltinTypeLoc T) { 3332ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 3333ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.setBuiltinLoc(T.getBuiltinLoc()); 3334ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (T.needsExtraLocalData()) 3335ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 3336ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return T.getType(); 3337577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3338577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 33391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3340a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 334143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ComplexTypeLoc T) { 3342a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: recurse? 3343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, T); 3344a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 33451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3346a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 334843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall PointerTypeLoc TL) { 3349c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType PointeeType 3350c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 335192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (PointeeType.isNull()) 335292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 335392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 335492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor QualType Result = TL.getType(); 3355c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (PointeeType->getAs<ObjCObjectType>()) { 335692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // A dependent pointer type 'T *' has is being transformed such 335792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // that an Objective-C class type is being replaced for 'T'. The 335892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // resulting pointer type is an ObjCObjectPointerType, not a 335992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // PointerType. 3360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 3361c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 3363c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NewT.setStarLoc(TL.getStarLoc()); 336492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return Result; 336592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 336643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 336792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (getDerived().AlwaysRebuild() || 336892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointeeType != TL.getPointeeLoc().getType()) { 336992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 337092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Result.isNull()) 337192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 337292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 3373c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 337492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 337592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3376c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Result; 3377577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 33791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 33801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3381a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 338243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BlockPointerTypeLoc TL) { 3383db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor QualType PointeeType 3384c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3385c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (PointeeType.isNull()) 3386c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return QualType(); 3387c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3388c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType Result = TL.getType(); 3389c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getDerived().AlwaysRebuild() || 3390c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt PointeeType != TL.getPointeeLoc().getType()) { 3391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Result = getDerived().RebuildBlockPointerType(PointeeType, 3392db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor TL.getSigilLoc()); 3393db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor if (Result.isNull()) 3394db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return QualType(); 3395db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor } 3396db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor 339739968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 3398db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3399db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return Result; 3400a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 340285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type. Note that somewhat paradoxically we 340385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value 340485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type; we only care if the type was *written* as an l-value type 340585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type. 340685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived> 340785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType 340885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 340943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ReferenceTypeLoc TL) { 341085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall const ReferenceType *T = TL.getTypePtr(); 341185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 341285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // Note that this works with the pointee-as-written. 341385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 341485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (PointeeType.isNull()) 341585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 341685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 341785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType Result = TL.getType(); 341885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (getDerived().AlwaysRebuild() || 341985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall PointeeType != T->getPointeeTypeAsWritten()) { 342085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildReferenceType(PointeeType, 342185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->isSpelledAsLValue(), 342285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getSigilLoc()); 342385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (Result.isNull()) 342485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 342585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 342685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 342785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // r-value references can be rebuilt as l-value references. 342885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall ReferenceTypeLoc NewTL; 342985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (isa<LValueReferenceType>(Result)) 343085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 343185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall else 343285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 343385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 343485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 343585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return Result; 343685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall} 343785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3438a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3439a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3440a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 344143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall LValueReferenceTypeLoc TL) { 344243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3443a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3445a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3446a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3447a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 344843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RValueReferenceTypeLoc TL) { 344943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3450577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 34511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3452577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 34531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3454a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 345543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall MemberPointerTypeLoc TL) { 3456f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const MemberPointerType *T = TL.getTypePtr(); 3457a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3458a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3459577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (PointeeType.isNull()) 3460577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 34611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3462a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // TODO: preserve source information for this. 3463a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ClassType 3464a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformType(QualType(T->getClass(), 0)); 3465577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ClassType.isNull()) 3466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 34671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3469a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall PointeeType != T->getPointeeType() || 3471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ClassType != QualType(T->getClass(), 0)) { 347285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, 347385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getStarLoc()); 3474a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3475a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3476a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3477577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3478a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 3479a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 3480a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3481a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3482577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3483577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 34841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 34851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3486a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 348743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ConstantArrayTypeLoc TL) { 3488f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ConstantArrayType *T = TL.getTypePtr(); 3489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3490577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3491577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 34921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3493a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3494a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3496a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildConstantArrayType(ElementType, 3497a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 3498a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSize(), 349985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 350085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3502a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3503a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3504c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3505a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); 3506a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3507a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 35081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3509a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = TL.getSizeExpr(); 3510a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Size) { 3511f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); 3513a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3514a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3516a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3517577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3519577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3520577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType( 3521a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 352243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall IncompleteArrayTypeLoc TL) { 3523f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const IncompleteArrayType *T = TL.getTypePtr(); 3524a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3525577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3526577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3528a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3529a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3530a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3531a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildIncompleteArrayType(ElementType, 3532a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 353385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 353485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3536a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3537a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3538c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3539a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 3540a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3541a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3542a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(0); 3543577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3544a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3545577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3548a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3549a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 355043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VariableArrayTypeLoc TL) { 3551f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VariableArrayType *T = TL.getTypePtr(); 3552a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3556670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Array bounds are not potentially evaluated contexts 3557f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3558670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 355960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3560a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3561a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3562577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Size = SizeResult.take(); 3565a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3566a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3568a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3569a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3570a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildVariableArrayType(ElementType, 3571a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 35729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3573a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 357485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3575a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3576a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3578c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3579a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); 3580a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3581a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3582a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 35831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3584a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3588a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3589a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 359043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedArrayTypeLoc TL) { 3591f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedArrayType *T = TL.getTypePtr(); 3592a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3596670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Array bounds are not potentially evaluated contexts 3597f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 35981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Prefer the expression from the TypeLoc; the other may have been uniqued. 36003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *origSize = TL.getSizeExpr(); 36013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!origSize) origSize = T->getSizeExpr(); 36023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 36033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExprResult sizeResult 36043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = getDerived().TransformExpr(origSize); 36053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (sizeResult.isInvalid()) 3606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *size = sizeResult.get(); 3609a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3610a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3611a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3612a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 36133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size != origSize) { 3614a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedArrayType(ElementType, 3615a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 36163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size, 3617a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 361885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3619a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3620a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 36221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3623a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // We might have any sort of array type now, but fortunately they 3624a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // all have the same location layout. 3625a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3626a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3627a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 36283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall NewTL.setSizeExpr(size); 3629a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3630a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 3635a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 363643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedExtVectorTypeLoc TL) { 3637f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedExtVectorType *T = TL.getTypePtr(); 3638a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3639a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: ext vector locs should be nested 3640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3641577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3642577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3644670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Vector sizes are not potentially evaluated contexts 3645f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3646670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 364760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 3648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size.isInvalid()) 3649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3651a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3652a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3653eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall ElementType != T->getElementType() || 3654eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall Size.get() != T->getSizeExpr()) { 3655a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 36569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size.take(), 3657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor T->getAttributeLoc()); 3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3659a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3660a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3661a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3662a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Result might be dependent or not. 3663a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (isa<DependentSizedExtVectorType>(Result)) { 3664a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorTypeLoc NewTL 3665a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3668a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3669a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3670a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3671a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3673577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3676a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 367743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VectorTypeLoc TL) { 3678f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3683a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3684a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3685a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 368682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 3687e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson T->getVectorKind()); 3688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3691c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3692a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 3693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 36941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3699a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 370043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ExtVectorTypeLoc TL) { 3701f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3709a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildExtVectorType(ElementType, 3710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getNumElements(), 3711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /*FIXME*/ SourceLocation()); 3712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3714a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3715c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3717a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 37181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3719a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3720577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3721577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 37221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 372321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl * 37246a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, 37256a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 372621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 37276a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeSourceInfo *NewDI = 0; 37286a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37296a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 37306a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor // If we're substituting into a pack expansion type and we know the 37316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc OldTL = OldDI->getTypeLoc(); 37326a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); 37336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLocBuilder TLB; 37356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc NewTL = OldDI->getTypeLoc(); 37366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TLB.reserve(NewTL.getFullDataSize()); 37376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor QualType Result = getDerived().TransformType(TLB, 37396a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc()); 37406a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 37416a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 37426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor Result = RebuildPackExpansionType(Result, 37446a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc().getSourceRange(), 37456a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getEllipsisLoc(), 37466a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions); 37476a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 37486a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 37496a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 37506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc NewExpansionTL 37516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = TLB.push<PackExpansionTypeLoc>(Result); 37526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 37536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 37546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor } else 37556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = getDerived().TransformType(OldDI); 375621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewDI) 375721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return 0; 375821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 375921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (NewDI == OldDI) 376021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return OldParm; 376121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall else 376221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return ParmVarDecl::Create(SemaRef.Context, 376321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall OldParm->getDeclContext(), 376421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall OldParm->getLocation(), 376521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall OldParm->getIdentifier(), 376621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall NewDI->getType(), 376721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall NewDI, 376821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall OldParm->getStorageClass(), 376916573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor OldParm->getStorageClassAsWritten(), 377021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /* DefArg */ NULL); 377121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 377221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 377321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 377421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>:: 3775a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TransformFunctionTypeParams(SourceLocation Loc, 3776a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 3777a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 3778a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor llvm::SmallVectorImpl<QualType> &OutParamTypes, 3779a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor llvm::SmallVectorImpl<ParmVarDecl*> *PVars) { 3780a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor for (unsigned i = 0; i != NumParams; ++i) { 3781a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (ParmVarDecl *OldParm = Params[i]) { 37826a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3783603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (OldParm->isParameterPack()) { 3784603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3785603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3786603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3787603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Find the parameter packs that could be expanded. 3788c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 3789c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); 3790c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc Pattern = ExpansionTL.getPatternLoc(); 3791c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 3792603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3793603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3794603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3795d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 37966a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions 37976a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 37986a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions = OrigNumExpansions; 3799c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 3800c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor Pattern.getSourceRange(), 3801603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Unexpanded.data(), 3802603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Unexpanded.size(), 3803d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 3804d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3805d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 3806603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3807603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3808603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3809603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 3810603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 3811603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 381212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor getDerived().ExpandingFunctionParameterPack(OldParm); 3813cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 3814603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 3815603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor ParmVarDecl *NewParm 38166a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 38176a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OrigNumExpansions); 3818603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (!NewParm) 3819603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3820603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3821a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3822a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3823a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3824603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3825d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3826d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 3827d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // forgetting the partially-substituted parameter pack. 3828d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (RetainExpansion) { 3829d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 3830d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ParmVarDecl *NewParm 38316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 38326a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OrigNumExpansions); 3833d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!NewParm) 3834d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return true; 3835d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3836d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor OutParamTypes.push_back(NewParm->getType()); 3837d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (PVars) 3838d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor PVars->push_back(NewParm); 3839d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 3840d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3841603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 3842603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3843603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3844603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3845603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 3846603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 3847603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3848603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3849603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 38506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm, 38516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions); 385221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewParm) 385321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3854603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3855a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3856a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3857a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3858603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3859603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3860a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3861a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Deal with the possibility that we don't have a parameter 3862a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // declaration for this parameter. 3863a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor QualType OldType = ParamTypes[i]; 3864603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool IsPackExpansion = false; 3865cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3866603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (const PackExpansionType *Expansion 3867603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor = dyn_cast<PackExpansionType>(OldType)) { 3868603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3869603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType Pattern = Expansion->getPattern(); 3870603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3871603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 3872603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3873603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3874603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3875d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3876a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 3877603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Unexpanded.data(), 3878603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Unexpanded.size(), 3879d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 3880d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3881d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 388221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3883603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3884603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3885603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 3886603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 3887603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 3888cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 3889603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 3890603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType NewType = getDerived().TransformType(Pattern); 3891603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 3892603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3893603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3894a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 3895a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3896a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 3897603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3898603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3899603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 3900603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3901603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3902603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 39033cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 39043cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 39053cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 39063cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 39073cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor QualType NewType = getDerived().TransformType(Pattern); 39083cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (NewType.isNull()) 39093cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 39103cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 39113cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor OutParamTypes.push_back(NewType); 39123cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (PVars) 39133cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor PVars->push_back(0); 39143cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 3915d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3916603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 3917603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 3918603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor OldType = Expansion->getPattern(); 3919603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor IsPackExpansion = true; 3920a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3921603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3922603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 3923603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType NewType = getDerived().TransformType(OldType); 3924603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 3925603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 39261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3927603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (IsPackExpansion) 3928cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NewType = getSema().Context.getPackExpansionType(NewType, 3929cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 3930603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3931a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 3932a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3933a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 3934577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 39351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 393621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return false; 3937603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 393821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 393921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 394021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType 394121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 394243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionProtoTypeLoc TL) { 39437e010a04fef171049291d8cb3047f118566da090Douglas Gregor // Transform the parameters and return type. 39447e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 39457e010a04fef171049291d8cb3047f118566da090Douglas Gregor // We instantiate in source order, with the return type first followed by 39467e010a04fef171049291d8cb3047f118566da090Douglas Gregor // the parameters, because users tend to expect this (even if they shouldn't 39477e010a04fef171049291d8cb3047f118566da090Douglas Gregor // rely on it!). 39487e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 3949dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // When the function has a trailing return type, we instantiate the 3950dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // parameters before the return type, since the return type can then refer 3951dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // to the parameters themselves (via decltype, sizeof, etc.). 3952dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 395321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVector<QualType, 4> ParamTypes; 395421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; 3955f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionProtoType *T = TL.getTypePtr(); 39567e010a04fef171049291d8cb3047f118566da090Douglas Gregor 3957dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor QualType ResultType; 3958dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 3959dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (TL.getTrailingReturn()) { 3960a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 3961a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 3962a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 3963a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 3964a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 3965dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 3966dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 3967dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 3968dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 3969dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 3970dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 3971dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor else { 3972dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 3973dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 3974dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 3975dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 3976a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 3977a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 3978a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 3979a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 3980a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 3981dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 3982dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 3983dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 3984a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3985a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3986a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType() || 3987bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor T->getNumArgs() != ParamTypes.size() || 3988a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { 3989a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionProtoType(ResultType, 3990a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.data(), 3991a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.size(), 3992a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->isVariadic(), 3993fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getTypeQuals(), 3994c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor T->getRefQualifier(), 3995fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getExtInfo()); 3996a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3997a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3998a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 39991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4000a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 4001a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4002a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4003dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(TL.getTrailingReturn()); 4004a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) 4005a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setArg(i, ParamDecls[i]); 4006a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4007a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4008577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 40091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4010577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4011577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType( 4012a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 401343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionNoProtoTypeLoc TL) { 4014f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionNoProtoType *T = TL.getTypePtr(); 4015a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4016a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (ResultType.isNull()) 4017a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4018a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4019a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4020a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4021a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType()) 4022a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionNoProtoType(ResultType); 4023a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4024a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 4025a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4026a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4027dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(false); 4028a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4029a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4030577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 40311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4032ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType 4033ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 403443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnresolvedUsingTypeLoc TL) { 4035f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const UnresolvedUsingType *T = TL.getTypePtr(); 40367c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 4037ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (!D) 4038ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4039ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4040ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType Result = TL.getType(); 4041ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 4042ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Result = getDerived().RebuildUnresolvedUsingType(D); 4043ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Result.isNull()) 4044ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4045ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 4046ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4047ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // We might get an arbitrary type spec type back. We should at 4048ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // least always get a type spec type, though. 4049ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 4050ed97649e9574b9d854fa4d6109c9333ae0993554John McCall NewTL.setNameLoc(TL.getNameLoc()); 4051ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4052ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Result; 4053ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 4054ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4055577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4056a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 405743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypedefTypeLoc TL) { 4058f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypedefType *T = TL.getTypePtr(); 4059577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor TypedefDecl *Typedef 40607c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), 40617c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4062577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Typedef) 4063577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 40641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4065a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4066a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4067a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Typedef != T->getDecl()) { 4068a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildTypedefType(Typedef); 4069a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4070a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4071a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4072a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4073a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 4074a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 40751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4076a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4077577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 40781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4079577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4080a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 408143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfExprTypeLoc TL) { 4082670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // typeof expressions are not potentially evaluated contexts 4083f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 40841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 408560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 4086577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4087577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 4088577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4089a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4090a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4091cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall E.get() != TL.getUnderlyingExpr()) { 40922a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 4093a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4094a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4095577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4096a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 40971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4098a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 4099cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4100cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4101cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4102a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4103a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4104577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4107a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 410843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfTypeLoc TL) { 4109cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 4110cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 4111cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (!New_Under_TI) 4112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 41131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4114a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4115cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 4116cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 4117a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4118a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4119a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 41201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4121a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 4122cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4123cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4124cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4125cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setUnderlyingTInfo(New_Under_TI); 4126a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 413243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DecltypeTypeLoc TL) { 4133f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DecltypeType *T = TL.getTypePtr(); 4134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4135670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // decltype expressions are not potentially evaluated contexts 4136f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 41371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 413860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 4139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 41411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4144a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall E.get() != T->getUnderlyingExpr()) { 41452a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 4146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 4150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 4152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 41531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4155577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4156577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4157577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 415834b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 415934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc TL) { 416034b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *T = TL.getTypePtr(); 416134b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType OldDeduced = T->getDeducedType(); 416234b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType NewDeduced; 416334b41d939a1328f484511c6002ba2456db879a29Richard Smith if (!OldDeduced.isNull()) { 416434b41d939a1328f484511c6002ba2456db879a29Richard Smith NewDeduced = getDerived().TransformType(OldDeduced); 416534b41d939a1328f484511c6002ba2456db879a29Richard Smith if (NewDeduced.isNull()) 416634b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 416734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 416834b41d939a1328f484511c6002ba2456db879a29Richard Smith 416934b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Result = TL.getType(); 417034b41d939a1328f484511c6002ba2456db879a29Richard Smith if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { 417134b41d939a1328f484511c6002ba2456db879a29Richard Smith Result = getDerived().RebuildAutoType(NewDeduced); 417234b41d939a1328f484511c6002ba2456db879a29Richard Smith if (Result.isNull()) 417334b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 417434b41d939a1328f484511c6002ba2456db879a29Richard Smith } 417534b41d939a1328f484511c6002ba2456db879a29Richard Smith 417634b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 417734b41d939a1328f484511c6002ba2456db879a29Richard Smith NewTL.setNameLoc(TL.getNameLoc()); 417834b41d939a1328f484511c6002ba2456db879a29Richard Smith 417934b41d939a1328f484511c6002ba2456db879a29Richard Smith return Result; 418034b41d939a1328f484511c6002ba2456db879a29Richard Smith} 418134b41d939a1328f484511c6002ba2456db879a29Richard Smith 418234b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived> 4183a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 418443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RecordTypeLoc TL) { 4185f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const RecordType *T = TL.getTypePtr(); 4186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor RecordDecl *Record 41877c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 41887c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4189577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Record) 4190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 41911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4192a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4193a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Record != T->getDecl()) { 4195a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildRecordType(Record); 4196a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4197a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4198a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 41991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4200a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 4201a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 4202a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4204577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 420843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall EnumTypeLoc TL) { 4209f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const EnumType *T = TL.getTypePtr(); 4210577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor EnumDecl *Enum 42117c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 42127c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4213577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Enum) 4214577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4218a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Enum != T->getDecl()) { 4219a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildEnumType(Enum); 4220a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4221a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4222a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4223a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4224a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 4225a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 42261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4228577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42297da2431c23ef1ee8acb114e39692246e1801afc2John McCall 42303cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived> 42313cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType( 42323cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeLocBuilder &TLB, 423343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall InjectedClassNameTypeLoc TL) { 42343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 42353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.getTypePtr()->getDecl()); 42363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!D) return QualType(); 42373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 42383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 42393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 42403cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T; 42413cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 42423cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 4243577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4244577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType( 4245a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 424643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateTypeParmTypeLoc TL) { 4247a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 4248577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4249577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 42501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 425149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 4252a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 425343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SubstTemplateTypeParmTypeLoc TL) { 4254a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 425549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 425649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 425749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived> 4258c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 4259c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TypeLocBuilder &TLB, 4260c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 4261c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TransformTypeSpecType(TLB, TL); 4262c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 4263c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 4264c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived> 4265833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 426643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder &TLB, 426743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL) { 426843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall const TemplateSpecializationType *T = TL.getTypePtr(); 4269828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 427043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template 427143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTemplateName(T->getTemplateName()); 427243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) 427343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4274833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 427543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 4276dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor} 427743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 42787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace { 42797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \brief Simple iterator that traverses the template arguments in a 42807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// container that provides a \c getArgLoc() member function. 42817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 42827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// This iterator is intended to be used with the iterator form of 42837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \c TreeTransform<Derived>::TransformTemplateArguments(). 42847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename ArgLocContainer> 42857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class TemplateArgumentLocContainerIterator { 42867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgLocContainer *Container; 42877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index; 42887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 42897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 42907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 42917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 42927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef int difference_type; 42937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 42947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 42957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 42967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 42977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 42987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 42997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 43007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { 43027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return &Arg; 43037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 43047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 43057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator() {} 43087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 43107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index) 43117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Container(&Container), Index(Index) { } 43127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator &operator++() { 43147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Index; 43157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 43167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 43177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator operator++(int) { 43197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator Old(*this); 43207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 43217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 43227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 43237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc operator*() const { 43257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Container->getArgLoc(Index); 43267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 43277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { 43297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return pointer(Container->getArgLoc(Index)); 43307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 43317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocContainerIterator &X, 4333f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 43347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Container == Y.Container && X.Index == Y.Index; 43357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 43367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 4338f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 43397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return !(X == Y); 43407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 43417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 43427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor} 43437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 43447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 434543fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived> 4346577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 4347833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TypeLocBuilder &TLB, 4348833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc TL, 434943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template) { 4350d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo NewTemplateArgs; 4351d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4352d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 43537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 43547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator; 43557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 43567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 43577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 43587f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 43591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4360833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: maybe don't rebuild if all the template arguments are the same. 4361833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 4362833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType Result = 4363833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().RebuildTemplateSpecializationType(Template, 4364833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TL.getTemplateNameLoc(), 4365d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs); 43661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4367833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!Result.isNull()) { 4368833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc NewTL 4369833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = TLB.push<TemplateSpecializationTypeLoc>(Result); 4370833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4371833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setLAngleLoc(TL.getLAngleLoc()); 4372833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setRAngleLoc(TL.getRAngleLoc()); 4373833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4374833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4375833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 43761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4377833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Result; 4378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4380a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived> 4381a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 4382a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TypeLocBuilder &TLB, 4383a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 4384a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template) { 4385a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 4386a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4387a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 4388a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor typedef TemplateArgumentLocContainerIterator< 4389a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 4390a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 4391a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 4392a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs)) 4393a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4394a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4395a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor // FIXME: maybe don't rebuild if all the template arguments are the same. 4396a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4397a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 4398a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4399a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getSema().Context.getDependentTemplateSpecializationType( 4400a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getKeyword(), 4401a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getQualifier(), 4402a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getIdentifier(), 4403a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4404a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4405a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc NewTL 4406a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4407a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 4408a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setQualifierRange(TL.getQualifierRange()); 4409a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 4410a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4411a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4412a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4413a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4414a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4415a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4416a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4417a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4418a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getDerived().RebuildTemplateSpecializationType(Template, 4419a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getNameLoc(), 4420a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4421a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4422a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (!Result.isNull()) { 4423a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor /// FIXME: Wrap this in an elaborated-type-specifier? 4424a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateSpecializationTypeLoc NewTL 4425a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4426a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setTemplateNameLoc(TL.getNameLoc()); 4427a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4428a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4429a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4430a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4431a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4432a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4433a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4434a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor} 4435a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 44361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4437a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4438465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 443943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ElaboratedTypeLoc TL) { 4440f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ElaboratedType *T = TL.getTypePtr(); 4441465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 44429e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 4443465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // NOTE: the qualifier in an ElaboratedType is optional. 44449e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (TL.getQualifierLoc()) { 44459e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc 44469e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 44479e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (!QualifierLoc) 4448465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return QualType(); 4449465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 44501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 445143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 445243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NamedT.isNull()) 445343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4454a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar 4455a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4456a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 44579e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc != TL.getQualifierLoc() || 4458e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NamedT != T->getNamedType()) { 445921e413fe6305a198564d436ac515497716c47844John McCall Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), 44609e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor T->getKeyword(), 44619e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc, NamedT); 4462a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4463a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4464a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4465577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4466465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4467e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 44689e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4469a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4470577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 44711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 44739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType( 44749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall TypeLocBuilder &TLB, 44759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc TL) { 44769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall const AttributedType *oldType = TL.getTypePtr(); 44779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 44789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (modifiedType.isNull()) 44799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 44809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 44819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType result = TL.getType(); 44829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 44839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // FIXME: dependent operand expressions? 44849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (getDerived().AlwaysRebuild() || 44859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType != oldType->getModifiedType()) { 44869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // TODO: this is really lame; we should really be rebuilding the 44879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // equivalent type from first principles. 44889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType 44899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall = getDerived().TransformType(oldType->getEquivalentType()); 44909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (equivalentType.isNull()) 44919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 44929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), 44939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType, 44949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall equivalentType); 44959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 44969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 44979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 44989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrNameLoc(TL.getAttrNameLoc()); 44999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) 45009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 45019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) 45029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrExprOperand(TL.getAttrExprOperand()); 45039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall else if (TL.hasAttrEnumOperand()) 45049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); 45059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 45069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return result; 45079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 45089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 45099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived> 4510075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 4511075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 4512075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc TL) { 4513075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 4514075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Inner.isNull()) 4515075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4516075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4517075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Result = TL.getType(); 4518075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (getDerived().AlwaysRebuild() || 4519075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner != TL.getInnerLoc().getType()) { 4520075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Result = getDerived().RebuildParenType(Inner); 4521075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Result.isNull()) 4522075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4523075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 4524075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4525075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 4526075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setLParenLoc(TL.getLParenLoc()); 4527075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setRParenLoc(TL.getRParenLoc()); 4528075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Result; 4529075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 4530075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4531075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived> 45324714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, 453343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentNameTypeLoc TL) { 4534f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentNameType *T = TL.getTypePtr(); 4535833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 45362494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc 45372494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 45382494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (!QualifierLoc) 4539577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 45401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 454133500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Result 45422494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().RebuildDependentNameType(T->getKeyword(), 454333500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getKeywordLoc(), 45442494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc, 45452494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T->getIdentifier(), 454633500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getNameLoc()); 4547a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4548a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4549a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4550e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 4551e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType NamedT = ElabT->getNamedType(); 455233500955d731c73717af52088b7fc0e7a85681e7John McCall TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 455333500955d731c73717af52088b7fc0e7a85681e7John McCall 4554e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4555e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 45569e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 455733500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 4558e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 4559e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 45602494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4561e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setNameLoc(TL.getNameLoc()); 4562e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 4563a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 45651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4566577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 456733500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>:: 456833500955d731c73717af52088b7fc0e7a85681e7John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 456943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL) { 4570f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentTemplateSpecializationType *T = TL.getTypePtr(); 457133500955d731c73717af52088b7fc0e7a85681e7John McCall 4572a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NestedNameSpecifier *NNS = 0; 4573a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (T->getQualifier()) { 4574a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), 4575a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getQualifierRange()); 4576a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (!NNS) 4577a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4578a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4579a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 458043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived() 458143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall .TransformDependentTemplateSpecializationType(TLB, TL, NNS); 458243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 458343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 458443fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 458543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>:: 458643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 458743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL, 458843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *NNS) { 4589f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentTemplateSpecializationType *T = TL.getTypePtr(); 459043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 459133500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgumentListInfo NewTemplateArgs; 459233500955d731c73717af52088b7fc0e7a85681e7John McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 459333500955d731c73717af52088b7fc0e7a85681e7John McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 4594c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 4595c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // FIXME: Nested-name-specifier source location info! 45967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator< 45977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 45987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 45997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 46007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 46017f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 460233500955d731c73717af52088b7fc0e7a85681e7John McCall 46031efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor QualType Result 46041efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), 46051efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor NNS, 46061efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor TL.getQualifierRange(), 46071efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor T->getIdentifier(), 46081efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor TL.getNameLoc(), 46091efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor NewTemplateArgs); 461033500955d731c73717af52088b7fc0e7a85681e7John McCall if (Result.isNull()) 461133500955d731c73717af52088b7fc0e7a85681e7John McCall return QualType(); 461233500955d731c73717af52088b7fc0e7a85681e7John McCall 461333500955d731c73717af52088b7fc0e7a85681e7John McCall if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 461433500955d731c73717af52088b7fc0e7a85681e7John McCall QualType NamedT = ElabT->getNamedType(); 461533500955d731c73717af52088b7fc0e7a85681e7John McCall 461633500955d731c73717af52088b7fc0e7a85681e7John McCall // Copy information relevant to the template specialization. 461733500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateSpecializationTypeLoc NamedTL 461833500955d731c73717af52088b7fc0e7a85681e7John McCall = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 461933500955d731c73717af52088b7fc0e7a85681e7John McCall NamedTL.setLAngleLoc(TL.getLAngleLoc()); 462033500955d731c73717af52088b7fc0e7a85681e7John McCall NamedTL.setRAngleLoc(TL.getRAngleLoc()); 462133500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) 462233500955d731c73717af52088b7fc0e7a85681e7John McCall NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); 462333500955d731c73717af52088b7fc0e7a85681e7John McCall 462433500955d731c73717af52088b7fc0e7a85681e7John McCall // Copy information relevant to the elaborated type. 462533500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 462633500955d731c73717af52088b7fc0e7a85681e7John McCall NewTL.setKeywordLoc(TL.getKeywordLoc()); 46279e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor 46289e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor // FIXME: DependentTemplateSpecializationType needs better source-location 46299e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor // info. 46309e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLocBuilder Builder; 46319e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Builder.MakeTrivial(SemaRef.Context, NNS, TL.getQualifierRange()); 46329e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(Builder.getWithLocInContext(SemaRef.Context)); 463333500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 4634e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor TypeLoc NewTL(Result, TL.getOpaqueData()); 4635e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor TLB.pushFullCopy(NewTL); 463633500955d731c73717af52088b7fc0e7a85681e7John McCall } 463733500955d731c73717af52088b7fc0e7a85681e7John McCall return Result; 463833500955d731c73717af52088b7fc0e7a85681e7John McCall} 463933500955d731c73717af52088b7fc0e7a85681e7John McCall 464033500955d731c73717af52088b7fc0e7a85681e7John McCalltemplate<typename Derived> 46417536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 46427536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypeLoc TL) { 46432fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Pattern 46442fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor = getDerived().TransformType(TLB, TL.getPatternLoc()); 46452fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Pattern.isNull()) 46462fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 46472fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 46482fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Result = TL.getType(); 46492fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (getDerived().AlwaysRebuild() || 46502fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Pattern != TL.getPatternLoc().getType()) { 46512fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Result = getDerived().RebuildPackExpansionType(Pattern, 46522fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor TL.getPatternLoc().getSourceRange(), 4653cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getEllipsisLoc(), 4654cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getTypePtr()->getNumExpansions()); 46552fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Result.isNull()) 46562fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 46572fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 46582fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 46592fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 46602fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor NewT.setEllipsisLoc(TL.getEllipsisLoc()); 46612fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return Result; 46627536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 46637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 46647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived> 4665a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 466743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCInterfaceTypeLoc TL) { 4668ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCInterfaceType is never dependent. 4669c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4670c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return TL.getType(); 4671c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 4672c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4673c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived> 4674c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType 4675c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 467643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectTypeLoc TL) { 4677c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCObjectType is never dependent. 4678c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4679ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 4680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 46811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 46821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4683a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4684a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 468543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectPointerTypeLoc TL) { 4686ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCObjectPointerType is never dependent. 4687c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4688ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 468924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 469024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 4691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 469243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation 469343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 469443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 469560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 46961eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 46973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 469843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 469943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 470043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 470160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 470243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 470343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().TransformCompoundStmt(S, false); 470443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 470543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 470643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 470760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 47081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 470943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 47107114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bool SubStmtInvalid = false; 471143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool SubStmtChanged = false; 4712ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Statements(getSema()); 471343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); 471443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor B != BEnd; ++B) { 471560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Result = getDerived().TransformStmt(*B); 47167114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (Result.isInvalid()) { 47177114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Immediately fail if this was a DeclStmt, since it's very 47187114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // likely that this will cause problems for future statements. 47197114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (isa<DeclStmt>(*B)) 47207114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 47217114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 47227114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Otherwise, just keep processing substatements and fail later. 47237114cbab7eb6e8b714eb22f014327daf2c741c08John McCall SubStmtInvalid = true; 47247114cbab7eb6e8b714eb22f014327daf2c741c08John McCall continue; 47257114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 47261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 472743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SubStmtChanged = SubStmtChanged || Result.get() != *B; 472843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Statements.push_back(Result.takeAs<Stmt>()); 472943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 47301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47317114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (SubStmtInvalid) 47327114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 47337114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 473443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 473543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !SubStmtChanged) 47363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 473743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 473843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 473943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor move_arg(Statements), 474043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRBracLoc(), 474143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 474243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 47431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 474443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 474560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 47461eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 474760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS, RHS; 4748264c1f8ec895952466eab59b84b8b06801e721faEli Friedman { 4749264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // The case value expressions are not potentially evaluated. 4750f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 47511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4752264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the left-hand case value. 4753264c1f8ec895952466eab59b84b8b06801e721faEli Friedman LHS = getDerived().TransformExpr(S->getLHS()); 4754264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (LHS.isInvalid()) 4755f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 47561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4757264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the right-hand case value (for the GNU case-range extension). 4758264c1f8ec895952466eab59b84b8b06801e721faEli Friedman RHS = getDerived().TransformExpr(S->getRHS()); 4759264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (RHS.isInvalid()) 4760f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4761264c1f8ec895952466eab59b84b8b06801e721faEli Friedman } 47621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 476343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Build the case statement. 476443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Case statements are always rebuilt so that they will attached to their 476543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transformed switch statement. 476660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 47679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 476843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getEllipsisLoc(), 47699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 477043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getColonLoc()); 477143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Case.isInvalid()) 4772f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 47731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 477443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the case 477560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 477643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4777f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 47781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 477943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Attach the body to the case statement 47809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 478143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 478243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 478343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 478460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 47851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 478643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the default case 478760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 478843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4789f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 47901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 479143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Default statements are always rebuilt 479243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 47939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get()); 479443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 47951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 479643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 479760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 47981eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { 479960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 480043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4801f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 48021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 480357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 480457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getDecl()); 480557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 480657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 480757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 480857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 480943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // FIXME: Pass the real colon location in. 4810ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner return getDerived().RebuildLabelStmt(S->getIdentLoc(), 481157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD), SourceLocation(), 481257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SubStmt.get()); 481343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 48141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 481543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 481660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 48171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 481843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 481960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 48208cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor VarDecl *ConditionVar = 0; 48218cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (S->getConditionVariable()) { 4822c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 48238cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor = cast_or_null<VarDecl>( 4824aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4825aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4826aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 48278cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (!ConditionVar) 4828f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 482999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 48308cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 4831c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 483299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 4833f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4834eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 4835eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Convert the condition to a boolean value. 4836afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 48378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), 48388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 4839afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 4840f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4841eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 48429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 4843afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 484499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 4845c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 48469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 48479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 4848f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4849eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 485043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "then" branch. 485160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Then = getDerived().TransformStmt(S->getThen()); 485243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Then.isInvalid()) 4853f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 48541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 485543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "else" branch. 485660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Else = getDerived().TransformStmt(S->getElse()); 485743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Else.isInvalid()) 4858f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 48591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 486043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 48619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 486299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 486343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Then.get() == S->getThen() && 486443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Else.get() == S->getElse()) 48653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 48661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4867eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, 486844aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Then.get(), 48699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall S->getElseLoc(), Else.get()); 487043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 487143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 487243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 487360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 48741eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 487543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition. 487660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 4877d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor VarDecl *ConditionVar = 0; 4878d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (S->getConditionVariable()) { 4879c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 4880d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor = cast_or_null<VarDecl>( 4881aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4882aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4883aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 4884d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (!ConditionVar) 4885f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 488699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 4887d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 4888c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 488999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 4890f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 489199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 48921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 489343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Rebuild the switch statement. 489460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Switch 48959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), 4896586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor ConditionVar); 489743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Switch.isInvalid()) 4898f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 48991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 490043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body of the switch statement. 490160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 490243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 4903f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 490543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Complete the switch statement. 49069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 49079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 490843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 49091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 491043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 491160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 491343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 491460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 49155656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor VarDecl *ConditionVar = 0; 49165656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (S->getConditionVariable()) { 4917c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 49185656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor = cast_or_null<VarDecl>( 4919aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4920aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4921aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 49225656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (!ConditionVar) 4923f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 492499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 49255656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 4926c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 492799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 4928f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4929afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 4930afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 4931afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 49328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), 49338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 4934afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 4935f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE; 4937afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 493899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 49391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 49419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 4942f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4943eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 494443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 494560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 494643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 4947f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 494943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 49509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 495199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 495243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 49539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(S); 49541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4955eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, 49569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ConditionVar, Body.get()); 495743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 49581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 495943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 496060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 496143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 496243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 496360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 496443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 4965f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4967eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Transform the condition 496860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(S->getCond()); 4969eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor if (Cond.isInvalid()) 4970f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4971eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 497243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 497343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Cond.get() == S->getCond() && 497443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 49753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 49761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 49789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall /*FIXME:*/S->getWhileLoc(), Cond.get(), 497943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRParenLoc()); 498043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 49811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 498243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 498360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) { 498543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the initialization statement 498660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Init = getDerived().TransformStmt(S->getInit()); 498743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Init.isInvalid()) 4988f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 499043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 499160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 499299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *ConditionVar = 0; 499399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (S->getConditionVariable()) { 4994c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 499599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor = cast_or_null<VarDecl>( 4996aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4997aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4998aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 499999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!ConditionVar) 5000f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 500199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 500299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5003c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 500499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5005f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5006afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5007afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5008afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 50098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), 50108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5011afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5012f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5013afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 50149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5015afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 501699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 50171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 50199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5020f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5021eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 502243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the increment 502360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Inc = getDerived().TransformExpr(S->getInc()); 502443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Inc.isInvalid()) 5025f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); 50289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (S->getInc() && !FullInc.get()) 5029f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5030eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 503143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 503260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 503343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5034f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 503643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 503743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Init.get() == S->getInit() && 50389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 503943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Inc.get() == S->getInc() && 504043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 50413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 50421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 504343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 50449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get(), FullCond, ConditionVar, 50459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullInc, S->getRParenLoc(), Body.get()); 504643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 504743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 504843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 504960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 505157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 505257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getLabel()); 505357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 505457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 505557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 505643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Goto statements must always be rebuilt, to resolve the label. 50571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 505857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 505943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 506043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 506143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 506260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 506460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Target = getDerived().TransformExpr(S->getTarget()); 506543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Target.isInvalid()) 5066f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 506843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 506943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Target.get() == S->getTarget()) 50703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 507143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 507243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 50739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Target.get()); 507443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 507543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 507643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 507760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50781eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 50793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 508043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 508243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 508360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 50853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 508643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 508843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 508960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 509160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(S->getRetValue()); 509243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Result.isInvalid()) 5093f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 509443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 50951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: We always rebuild the return statement because there is no way 509643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // to tell whether the return type of the function has changed. 50979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 509843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 510043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 510160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51021eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 510343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool DeclChanged = false; 510443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor llvm::SmallVector<Decl *, 4> Decls; 510543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); 510643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor D != DEnd; ++D) { 5107aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), 5108aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor *D); 510943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!Transformed) 5110f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Transformed != *D) 511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclChanged = true; 51141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls.push_back(Transformed); 511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 51171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && !DeclChanged) 51193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 51201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), 512243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getStartLoc(), S->getEndLoc()); 512343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 512543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 512660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 512743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { 5128c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5129ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Constraints(getSema()); 5130ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Exprs(getSema()); 5131ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVector<IdentifierInfo *, 4> Names; 5132a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson 513360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmString; 5134ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Clobbers(getSema()); 5135703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5136703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool ExprsChanged = false; 5137c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5138703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the outputs. 5139703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 5140ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getOutputIdentifier(I)); 5141c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5142703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 51433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getOutputConstraintLiteral(I)); 5144c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5145703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the output expr. 5146703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *OutputExpr = S->getOutputExpr(I); 514760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(OutputExpr); 5148703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5149f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5150c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5151703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != OutputExpr; 5152c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 51539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5154703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5155c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5156703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the inputs. 5157703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 5158ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getInputIdentifier(I)); 5159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5160703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 51613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getInputConstraintLiteral(I)); 5162c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5163703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the input expr. 5164703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *InputExpr = S->getInputExpr(I); 516560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(InputExpr); 5166703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5167f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5168c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5169703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != InputExpr; 5170c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 51719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5172703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5173c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5174703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (!getDerived().AlwaysRebuild() && !ExprsChanged) 51753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5176703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5177703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the clobbers. 5178703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 51793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Clobbers.push_back(S->getClobber(I)); 5180703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5181703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the asm string literal. 5182703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson AsmString = SemaRef.Owned(S->getAsmString()); 5183703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5184703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson return getDerived().RebuildAsmStmt(S->getAsmLoc(), 5185703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isSimple(), 5186703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isVolatile(), 5187703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumOutputs(), 5188703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumInputs(), 5189a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson Names.data(), 5190703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Constraints), 5191703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Exprs), 51929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AsmString.get(), 5193703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Clobbers), 5194703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getRParenLoc(), 5195703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isMSAsm()); 519643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 519743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 519843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 519943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 520060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 52024dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body of the @try. 520360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 52044dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (TryBody.isInvalid()) 5205f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5206c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 52078f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor // Transform the @catch statements (if present). 52088f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor bool AnyCatchChanged = false; 5209ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> CatchStmts(SemaRef); 52108f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 521160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 52124dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Catch.isInvalid()) 5213f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52148f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (Catch.get() != S->getCatchStmt(I)) 52158f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor AnyCatchChanged = true; 52168f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 52174dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 5218c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 52194dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the @finally statement (if present). 522060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Finally; 52214dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (S->getFinallyStmt()) { 52224dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally = getDerived().TransformStmt(S->getFinallyStmt()); 52234dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Finally.isInvalid()) 5224f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52254dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 52264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 52274dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 52284dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 52294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor TryBody.get() == S->getTryBody() && 52308f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor !AnyCatchChanged && 52314dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally.get() == S->getFinallyStmt()) 52323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5233c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 52344dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 52359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 52369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall move_arg(CatchStmts), Finally.get()); 523743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 523943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 524060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 5242be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor // Transform the @catch parameter, if there is one. 5243be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var = 0; 5244be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (VarDecl *FromVar = S->getCatchParamDecl()) { 5245be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TSInfo = 0; 5246be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (FromVar->getTypeSourceInfo()) { 5247be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 5248be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!TSInfo) 5249f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5250be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5251c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5252be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor QualType T; 5253be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (TSInfo) 5254be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = TSInfo->getType(); 5255be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor else { 5256be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = getDerived().TransformType(FromVar->getType()); 5257be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (T.isNull()) 5258f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5259be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5261be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 5262be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!Var) 5263f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5264be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5265c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 526660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 5267be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (Body.isInvalid()) 5268f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5269c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5270c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 5271be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor S->getRParenLoc(), 52729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body.get()); 527343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 527543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 527660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 52784dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body. 527960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 52804dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Body.isInvalid()) 5281f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5282c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 52834dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 52844dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 52854dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Body.get() == S->getFinallyBody()) 52863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52874dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 52884dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 52894dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 52909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 529143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 529343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 529460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 529660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand; 5297d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (S->getThrowExpr()) { 5298d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand = getDerived().TransformExpr(S->getThrowExpr()); 5299d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (Operand.isInvalid()) 5300f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5301d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 5302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5303d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (!getDerived().AlwaysRebuild() && 5304d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand.get() == S->getThrowExpr()) 53053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return getSema().Owned(S); 5306c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 530843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 531160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 531243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 53131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCAtSynchronizedStmt *S) { 53148fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the object we are locking. 531560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 53168fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Object.isInvalid()) 5317f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5318c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53198fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the body. 532060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 53218fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Body.isInvalid()) 5322f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5323c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53248fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // If nothing change, just retain the current statement. 53258fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (!getDerived().AlwaysRebuild() && 53268fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Object.get() == S->getSynchExpr() && 53278fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Body.get() == S->getSynchBody()) 53283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 53298fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor 53308fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Build a new statement. 53318fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 53329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Object.get(), Body.get()); 533343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 533443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 533543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 533660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 533743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt( 53381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCForCollectionStmt *S) { 5339c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the element statement. 534060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Element = getDerived().TransformStmt(S->getElement()); 5341c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Element.isInvalid()) 5342f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5343c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5344c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the collection expression. 534560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 5346c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Collection.isInvalid()) 5347f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5348c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5349c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the body. 535060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 5351c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Body.isInvalid()) 5352f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5353c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5354c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // If nothing changed, just retain this statement. 5355c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (!getDerived().AlwaysRebuild() && 5356c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Element.get() == S->getElement() && 5357c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Collection.get() == S->getCollection() && 5358c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Body.get() == S->getBody()) 53593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5361c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Build a new statement. 5362c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 5363c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /*FIXME:*/S->getForLoc(), 53649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element.get(), 53659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection.get(), 5366c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor S->getRParenLoc(), 53679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 536843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 536943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 537043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 537143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 537260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 537343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 537443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the exception declaration, if any. 537543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *Var = 0; 537643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (S->getExceptionDecl()) { 537743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *ExceptionDecl = S->getExceptionDecl(); 537883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor TypeSourceInfo *T = getDerived().TransformType( 537983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getTypeSourceInfo()); 538083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor if (!T) 5381f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 538383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, 538443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ExceptionDecl->getIdentifier(), 538583cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getLocation()); 5386ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (!Var || Var->isInvalidDecl()) 5387f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 538843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 53891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 539043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the actual exception handler. 539160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 5392ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (Handler.isInvalid()) 5393f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 539543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 539643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !Var && 539743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handler.get() == S->getHandlerBlock()) 53983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 539943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 540043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), 540143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Var, 54029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler.get()); 540343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 540543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 540660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 540743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 540843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the try block itself. 540960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBlock 541043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCompoundStmt(S->getTryBlock()); 541143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (TryBlock.isInvalid()) 5412f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 541443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the handlers. 541543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool HandlerChanged = false; 5416ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Handlers(SemaRef); 541743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 541860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler 541943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 542043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Handler.isInvalid()) 5421f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 542343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 542443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handlers.push_back(Handler.takeAs<Stmt>()); 542543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 54261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 542743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 542843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor TryBlock.get() == S->getTryBlock() && 542943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !HandlerChanged) 54303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 543143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 54329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 54331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump move_arg(Handlers)); 543443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 543643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 5437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation 5438577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 54391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 544060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5441454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 54423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 54431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 54441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 544660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5447454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 544840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 544940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (E->getQualifierLoc()) { 545040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 545140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 545240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 5453f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5454a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5455dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5456dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *ND 54577c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 54587c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getDecl())); 5459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!ND) 5460f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 54611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5462ec8045d3f0375302eadaa63deb373bacaf25a569John McCall DeclarationNameInfo NameInfo = E->getNameInfo(); 5463ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (NameInfo.getName()) { 5464ec8045d3f0375302eadaa63deb373bacaf25a569John McCall NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5465ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (!NameInfo.getName()) 5466f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5467ec8045d3f0375302eadaa63deb373bacaf25a569John McCall } 54682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 54692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!getDerived().AlwaysRebuild() && 547040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 5471a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ND == E->getDecl() && 54722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDecl()->getDeclName() && 5473096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 54741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5475dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // Mark it referenced in the new context regardless. 5476dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: this is a bit instantiation-specific. 5477dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 5478a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 54793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5480a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5481dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5482dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; 5483096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 5484dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgs = &TransArgs; 5485dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 5486dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 5487fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 5488fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 5489fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 5490fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 5491dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall } 5492dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 549340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 549440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor TemplateArgs); 5495577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 54961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 549860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5499454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 55003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5501577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 55021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 550460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5505454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 55063fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 551060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5511454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 55123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 55151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 551660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5517454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 55183fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 552260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5523454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 55243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 552860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5529454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 553060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 5531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5532f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 55331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 55353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 55361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 55379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 5538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParen()); 5539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 5540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 55411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 554260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5543454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 554460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 5545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5546f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 55471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 55493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 55501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 5552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOpcode(), 55539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 5554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 555760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 55588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 55598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform the type. 55608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 55618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!Type) 5562f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5563c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform all of the components into components similar to what the 55658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // parser uses. 5566c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // FIXME: It would be slightly more efficient in the non-dependent case to 5567c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // just map FieldDecls, rather than requiring the rebuilder to look for 5568c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // the fields again. However, __builtin_offsetof is rare enough in 55698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // template code that we don't care. 55708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor bool ExprChanged = false; 5571f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::OffsetOfComponent Component; 55728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor typedef OffsetOfExpr::OffsetOfNode Node; 55738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor llvm::SmallVector<Component, 4> Components; 55748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 55758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const Node &ON = E->getComponent(I); 55768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Component Comp; 557772be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor Comp.isBrackets = true; 55788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.LocStart = ON.getRange().getBegin(); 55798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.LocEnd = ON.getRange().getEnd(); 55808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor switch (ON.getKind()) { 55818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Array: { 55828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 558360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(FromIndex); 55848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (Index.isInvalid()) 5585f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5586c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor ExprChanged = ExprChanged || Index.get() != FromIndex; 55888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = true; 55899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Comp.U.E = Index.get(); 55908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 55918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 5592c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Field: 55948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Identifier: 55958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = false; 55968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.U.IdentInfo = ON.getFieldName(); 559729d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor if (!Comp.U.IdentInfo) 559829d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor continue; 5599c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 56008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 5601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5602cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor case Node::Base: 5603cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor // Will be recomputed during the rebuild. 5604cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor continue; 56058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 5606c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 56078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.push_back(Comp); 56088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 5609c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 56108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // If nothing changed, retain the existing expression. 56118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!getDerived().AlwaysRebuild() && 56128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Type == E->getTypeSourceInfo() && 56138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor !ExprChanged) 56143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5615c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 56168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Build a new offsetof expression. 56178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 56188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.data(), Components.size(), 56198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor E->getRParenLoc()); 56207cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall} 56217cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 56227cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived> 56237cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult 56247cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 56257cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall assert(getDerived().AlreadyTransformed(E->getType()) && 56267cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall "opaque value expression requires transformation"); 56277cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return SemaRef.Owned(E); 56288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 56298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 56308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived> 563160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5632454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { 5633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isArgumentType()) { 5634a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 56355557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor 5636a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 56375ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!NewT) 5638f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 56391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56405ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!getDerived().AlwaysRebuild() && OldT == NewT) 56413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 56421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56435ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), 56441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->isSizeOf(), 5645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSourceRange()); 5646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 56471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 564860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr; 56491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump { 5650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // C++0x [expr.sizeof]p1: 5651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The operand is either an expression, which is an unevaluated operand 5652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // [...] 5653f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 56541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 5656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5657f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 56581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 56603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 56621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(), 5664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isSizeOf(), 5665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSourceRange()); 5666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 56671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 566960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5670454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 567160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 5672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 5673f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 56741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 567560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 5676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 5677f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 56781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 5682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 56833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 56841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildArraySubscriptExpr(LHS.get(), 5686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLHS()->getLocStart(), 56879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 5688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRBracketLoc()); 5689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 56901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 569260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5693454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 5694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the callee. 569560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 5696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 5697f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform arguments. 5700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgChanged = false; 5701ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 5702aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 5703aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 5704aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 5705aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 5706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 5708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgChanged) 57093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 57101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Wrong source location information for the '('. 57121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLParenLoc 5713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = ((Expr *)Callee.get())->getSourceRange().getBegin(); 57149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 5715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 5716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 5717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 572060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5721454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 572260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 5723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 5724f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 572640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 572783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (E->hasQualifier()) { 572840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 572940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 573040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 573140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 5732f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 573383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 57341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5735f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *Member 57367c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 57377c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getMemberDecl())); 5738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Member) 5739f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57416bb8017bb9e828d118e15e59d71c66bba323c364John McCall NamedDecl *FoundDecl = E->getFoundDecl(); 57426bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (FoundDecl == E->getMemberDecl()) { 57436bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = Member; 57446bb8017bb9e828d118e15e59d71c66bba323c364John McCall } else { 57456bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = cast_or_null<NamedDecl>( 57466bb8017bb9e828d118e15e59d71c66bba323c364John McCall getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 57476bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!FoundDecl) 5748f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57496bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 57506bb8017bb9e828d118e15e59d71c66bba323c364John McCall 5751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase() && 575340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 57548a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member == E->getMemberDecl() && 57556bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl == E->getFoundDecl() && 5756096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 5757c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 57581f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // Mark it referenced in the new context regardless. 57591f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // FIXME: this is a bit instantiation-specific. 57601f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); 57613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 57621f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson } 5763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5764d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs; 5765096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 5766d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 5767d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 5768fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 5769fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 5770fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 5771fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 57728a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor } 5773c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bogus source location for the operator 5775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeOperatorLoc 5776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 5777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5778c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 5779c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 5780c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 5781c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 5782c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 5783c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 57849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 5785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 578640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc, 57872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara E->getMemberNameInfo(), 57888a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member, 57896bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, 5790096832c5ed5b9106fa177ebc148489760c3bc496John McCall (E->hasExplicitTemplateArgs() 5791d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall ? &TransArgs : 0), 5792c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope); 5793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 579660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5797454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 579860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 5799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 5800f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 580260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 5803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 5804f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 5808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 58093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 58101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 58129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), RHS.get()); 5813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 5814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 58151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 581660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator( 5818454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CompoundAssignOperator *E) { 5819454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformBinaryOperator(E); 5820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 58211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 582356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>:: 582456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 582556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Just rebuild the common and RHS expressions and see whether we 582656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // get any changes. 582756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 582856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 582956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (commonExpr.isInvalid()) 583056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 583156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 583256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 583356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (rhs.isInvalid()) 583456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 583556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 583656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (!getDerived().AlwaysRebuild() && 583756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall commonExpr.get() == e->getCommon() && 583856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get() == e->getFalseExpr()) 583956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SemaRef.Owned(e); 584056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 584156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return getDerived().RebuildConditionalOperator(commonExpr.take(), 584256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getQuestionLoc(), 584356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 0, 584456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getColonLoc(), 584556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get()); 584656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 584756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 584856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived> 584960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5850454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 585160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 5852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 5853f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 585560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 5856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 5857f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 585960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 5860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 5861f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 5865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 5866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 58673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 58681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildConditionalOperator(Cond.get(), 587047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getQuestionLoc(), 58719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 587247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getColonLoc(), 58739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get()); 5874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 58751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 587760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5878454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 5879a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // Implicit casts are eliminated during transformation, since they 5880a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // will be recomputed by semantic analysis after transformation. 58816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return getDerived().TransformExpr(E->getSubExprAsWritten()); 5882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 58831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 588560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5886454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 5887ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 5888ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 5889ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 5890ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 589160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 58926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 5893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5894f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5897ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 5898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 58993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 59001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59019d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 5902ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 5903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc(), 59049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 5905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 590860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5909454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 591042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *OldT = E->getTypeSourceInfo(); 591142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 591242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall if (!NewT) 5913f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 591560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 5916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 5917f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5919b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 592042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall OldT == NewT && 5921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInitializer()) 59223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 59241d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // Note: the expression type doesn't necessarily match the 59251d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // type-as-written, but that's okay, because it should always be 59261d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // derivable from the initializer. 59271d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 592842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, 5929b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getInitializer()->getLocEnd(), 59309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get()); 5931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 593460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5935454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 593660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 5937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 5938f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase()) 59423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 59431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5944b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bad source location 59451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeOperatorLoc 5946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); 59479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 5948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessorLoc(), 5949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessor()); 5950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 595360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5954454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 5955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool InitChanged = false; 59561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5957ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 5958aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 5959aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Inits, &InitChanged)) 5960aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 5961aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 5962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && !InitChanged) 59633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 59641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), 5966e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor E->getRBraceLoc(), E->getType()); 5967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 597060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5971454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 5972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Designation Desig; 59731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 597443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the initializer value 597560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInit()); 5976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 5977f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 597943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the designators. 5980ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); 5981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ExprChanged = false; 5982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 5983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DEnd = E->designators_end(); 5984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D != DEnd; ++D) { 5985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isFieldDesignator()) { 5986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Desig.AddDesignator(Designator::getField(D->getFieldName(), 5987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getDotLoc(), 5988b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getFieldLoc())); 5989b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 5990b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 59911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isArrayDesignator()) { 599360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); 5994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Index.isInvalid()) 5995f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArray(Index.get(), 5998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc())); 59991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); 6001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Index.release()); 6002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6003b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 60041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(D->isArrayRangeDesignator() && "New kind of designator?"); 600660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Start 6007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformExpr(E->getArrayRangeStart(*D)); 6008b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Start.isInvalid()) 6009f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 601160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); 6012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (End.isInvalid()) 6013f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArrayRange(Start.get(), 6016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get(), 6017b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc(), 6018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getEllipsisLoc())); 60191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || 6021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get() != E->getArrayRangeEnd(*D); 60221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Start.release()); 6024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(End.release()); 6025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 60261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInit() && 6029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ExprChanged) 60303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), 6033b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getEqualOrColonLoc(), 60349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall E->usesGNUSyntax(), Init.get()); 6035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 603860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr( 6040454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall ImplicitValueInitExpr *E) { 60415557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); 6042c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60435557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // FIXME: Will we ever have proper type location here? Will we actually 60445557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // need to transform the type? 6045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6046b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6047f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType()) 60513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6053b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildImplicitValueInitExpr(T); 6054b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 605760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6058454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 60599bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 60609bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor if (!TInfo) 6061f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 606360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6065f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 60682cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo == E->getWrittenTypeInfo() && 6069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 60703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 60732cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo, E->getRParenLoc()); 6074b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6075b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 607760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6078454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 6079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6080ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6081aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 6082aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6083aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6084aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6085b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildParenListExpr(E->getLParenLoc(), 6086b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Inits), 6087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression. 6091b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 6092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always 6093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to 6094b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis. 6095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 609660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6097454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 609857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 609957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner E->getLabel()); 610057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 610157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return ExprError(); 610257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 6103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 610457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 6105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 610860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6109454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 611060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt 6111b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 6112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubStmt.isInvalid()) 6113f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6115b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6116b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubStmt.get() == E->getSubStmt()) 61173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildStmtExpr(E->getLParenLoc(), 61209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get(), 6121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6122b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 612560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6126454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 612760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6129f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 613160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6133f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 613560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6137f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 61433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 61469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond.get(), LHS.get(), RHS.get(), 6147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 615160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6152454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 61533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 615760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6158454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 6159668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor switch (E->getOperator()) { 6160668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_New: 6161668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Delete: 6162668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_New: 6163668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_Delete: 6164668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 6165f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6166c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6167668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Call: { 6168668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // This is a call to an object's operator(). 6169668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 6170668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6171668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the object itself. 617260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 6173668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor if (Object.isInvalid()) 6174f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6175668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6176668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // FIXME: Poor location information 6177668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor SourceLocation FakeLParenLoc 6178668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6179668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor static_cast<Expr *>(Object.get())->getLocEnd()); 6180668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6181668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the call arguments. 6182ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6183aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 6184aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args)) 6185aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6186668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 61879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, 6188668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor move_arg(Args), 6189668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor E->getLocEnd()); 6190668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6191668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6192668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 6193668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_##Name: 6194668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 6195668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def" 6196668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Subscript: 6197668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Handled below. 6198668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor break; 6199668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6200668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Conditional: 6201668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("conditional operator is not actually overloadable"); 6202f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6203668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6204668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_None: 6205668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case NUM_OVERLOADED_OPERATORS: 6206668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("not an overloaded operator?"); 6207f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6208668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6209668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 621060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 621460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult First = getDerived().TransformExpr(E->getArg(0)); 6215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (First.isInvalid()) 6216f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 621860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Second; 6219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->getNumArgs() == 2) { 6220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Second = getDerived().TransformExpr(E->getArg(1)); 6221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Second.isInvalid()) 6222f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 62241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6226b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor First.get() == E->getArg(0) && 62281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 62293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6231b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 6232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 62339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee.get(), 62349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First.get(), 62359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second.get()); 6236b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6238b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 623960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6240454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 6241454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCallExpr(E); 6242b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6244b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 6245e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult 6246e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 6247e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform the callee. 6248e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6249e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (Callee.isInvalid()) 6250e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6251e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6252e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform exec config. 6253e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 6254e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (EC.isInvalid()) 6255e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6256e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6257e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform arguments. 6258e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne bool ArgChanged = false; 6259e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ASTOwningVector<Expr*> Args(SemaRef); 6260e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6261e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne &ArgChanged)) 6262e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6263e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6264e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (!getDerived().AlwaysRebuild() && 6265e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Callee.get() == E->getCallee() && 6266e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne !ArgChanged) 6267e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return SemaRef.Owned(E); 6268e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6269e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // FIXME: Wrong source location information for the '('. 6270e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation FakeLParenLoc 6271e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne = ((Expr *)Callee.get())->getSourceRange().getBegin(); 6272e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6273e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move_arg(Args), 6274e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne E->getRParenLoc(), EC.get()); 6275e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne} 6276e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6277e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived> 627860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6279454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 6280ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6281ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6282ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6283ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 628460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 62856eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6287f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6290ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 62923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Poor source location information here. 62951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLAngleLoc 6296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); 6297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); 6298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRParenLoc 6299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSubExpr()->getSourceRange().getEnd()); 6301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), 63021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getStmtClass(), 6303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeLAngleLoc, 6304ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 6306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 63079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRParenLoc); 6309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 631260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6313454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 6314454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 631860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6319454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 6320454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 632460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr( 6326454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXReinterpretCastExpr *E) { 6327454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 633160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6332454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 6333454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 633760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr( 6339454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXFunctionalCastExpr *E) { 6340ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6341ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6342ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 63431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 634460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 63456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6346b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6347f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6350ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 63523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6354ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return getDerived().RebuildCXXFunctionalCastExpr(Type, 6355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getSubExpr()->getLocStart(), 63569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 636160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6362454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 6363b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isTypeOperand()) { 636457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *TInfo 636557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor = getDerived().TransformType(E->getTypeOperandSourceInfo()); 636657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor if (!TInfo) 6367f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 637057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo == E->getTypeOperandSourceInfo()) 63713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 637357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 637457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 637557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo, 6376b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 63781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // We don't know whether the expression is potentially evaluated until 6380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // after we perform semantic analysis, so the expression is potentially 6381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // potentially evaluated. 63821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(SemaRef, 6383f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::PotentiallyPotentiallyEvaluated); 63841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 638560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 6386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6387f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6389b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getExprOperand()) 63913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 639357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 639457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 63959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6398b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 640060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 640101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 640201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (E->isTypeOperand()) { 640301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *TInfo 640401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet = getDerived().TransformType(E->getTypeOperandSourceInfo()); 640501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!TInfo) 640601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 640701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 640801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 640901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo == E->getTypeOperandSourceInfo()) 64103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 641101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 641201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXTypeidExpr(E->getType(), 641301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 641401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo, 641501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 641601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 641701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 641801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // We don't know whether the expression is potentially evaluated until 641901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // after we perform semantic analysis, so the expression is potentially 642001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // potentially evaluated. 642101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 642201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 642301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 642401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (SubExpr.isInvalid()) 642501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 642601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 642701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 642801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get() == E->getExprOperand()) 64293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 643001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 643101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXUuidofExpr(E->getType(), 643201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 643301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get(), 643401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 643501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 643601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 643701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived> 643801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult 6439454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 64403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6443b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 644460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 6446454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXNullPtrLiteralExpr *E) { 64473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 645160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6452454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 6453ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor DeclContext *DC = getSema().getFunctionLevelDeclContext(); 6454ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); 6455ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType T = MD->getThisType(getSema().Context); 64561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6457ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!getDerived().AlwaysRebuild() && T == E->getType()) 64583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6460828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); 6461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 646460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6465454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 646660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6467b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6468f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 64723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 64749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); 6475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 647860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6479454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 64801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParmVarDecl *Param 64817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), 64827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getParam())); 6483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Param) 6484f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 648653cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth if (!getDerived().AlwaysRebuild() && 6487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Param == E->getParam()) 64883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6490036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 6491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 649460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6495ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr( 6496ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr *E) { 6497ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 6498ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 6499f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6500ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 6501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6502ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo()) 65033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6505ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXScalarValueInitExpr(T, 6506ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 6507ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor E->getRParenLoc()); 6508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 651160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6512454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 6513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the type that we're allocating 65141bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocTypeInfo 65151bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); 65161bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor if (!AllocTypeInfo) 6517f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the size of the array we're allocating (if any). 652060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); 6521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (ArraySize.isInvalid()) 6522f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the placement arguments (if any). 6525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6526ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> PlacementArgs(SemaRef); 6527aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getPlacementArgs(), 6528aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor E->getNumPlacementArgs(), true, 6529aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor PlacementArgs, &ArgumentChanged)) 6530aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 65311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 653243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the constructor arguments (if any). 6533ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConstructorArgs(SemaRef); 6534aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, 6535aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ConstructorArgs, &ArgumentChanged)) 6536aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 65371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65381af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform constructor, new operator, and delete operator. 65391af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor CXXConstructorDecl *Constructor = 0; 65401af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getConstructor()) { 65411af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor = cast_or_null<CXXConstructorDecl>( 65427c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 65437c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 65441af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!Constructor) 6545f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65461af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 65471af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 65481af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorNew = 0; 65491af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorNew()) { 65501af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew = cast_or_null<FunctionDecl>( 65517c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 65527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorNew())); 65531af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorNew) 6554f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 65561af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 65571af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 65581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 65591af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 65607c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 65617c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 65621af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 6563f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 6565c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 65671bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 6568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArraySize.get() == E->getArraySize() && 65691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor == E->getConstructor() && 65701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew == E->getOperatorNew() && 65711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete() && 65721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor !ArgumentChanged) { 65731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 65741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 65751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (Constructor) 65761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 65771af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorNew) 65781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); 65791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 65801af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 65813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65821af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 65831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65841bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocType = AllocTypeInfo->getType(); 65855b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArraySize.get()) { 65865b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // If no array size was specified, but the new expression was 65875b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with an array type (e.g., "new T" where T is 65885b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with "int[4]"), extract the outer bound from the 65895b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // array type as our array size. We do this with constant and 65905b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // dependently-sized array types. 65915b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 65925b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArrayT) { 65935b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // Do nothing 65945b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const ConstantArrayType *ConsArrayT 65955b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<ConstantArrayType>(ArrayT)) { 6596c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ArraySize 65979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, 65989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis ConsArrayT->getSize(), 65999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis SemaRef.Context.getSizeType(), 66009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME:*/E->getLocStart())); 66015b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = ConsArrayT->getElementType(); 66025b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const DependentSizedArrayType *DepArrayT 66035b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<DependentSizedArrayType>(ArrayT)) { 66045b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (DepArrayT->getSizeExpr()) { 66053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); 66065b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = DepArrayT->getElementType(); 66075b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 66085b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 66095b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 66101bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor 6611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNewExpr(E->getLocStart(), 6612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalNew(), 6613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 6614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(PlacementArgs), 6615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 66164bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor E->getTypeIdParens(), 6617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor AllocType, 66181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo, 66199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize.get(), 6620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 6621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(ConstructorArgs), 66221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getLocEnd()); 6623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 662660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6627454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 662860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 6629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Operand.isInvalid()) 6630f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66321af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform the delete operator, if known. 66331af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 66341af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 66351af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 66367c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 66377c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 66381af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 6639f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66401af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 6641c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 66431af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Operand.get() == E->getArgument() && 66441af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete()) { 66451af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 66461af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 66471af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 66481af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 66495833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 66505833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (!E->getArgument()->isTypeDependent()) { 66515833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType Destroyed = SemaRef.Context.getBaseElementType( 66525833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor E->getDestroyedType()); 66535833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 66545833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 66555833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), 66565833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.LookupDestructor(Record)); 66575833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 66585833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 66595833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 66603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 66621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), 6664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalDelete(), 6665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrayForm(), 66669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand.get()); 6667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 667060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6671a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 6672454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXPseudoDestructorExpr *E) { 667360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6674a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor if (Base.isInvalid()) 6675f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6677b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTypePtr; 6678a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor bool MayBePseudoDestructor = false; 66799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 6680a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getOperatorLoc(), 6681a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->isArrow()? tok::arrow : tok::period, 6682a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor ObjectTypePtr, 6683a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor MayBePseudoDestructor); 6684a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Base.isInvalid()) 6685f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6686c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6687b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType ObjectType = ObjectTypePtr.get(); 6688f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 6689f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (QualifierLoc) { 6690f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor QualifierLoc 6691f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 6692f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (!QualifierLoc) 669343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return ExprError(); 669443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 6695f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec SS; 6696f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS.Adopt(QualifierLoc); 66971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6698a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed; 6699a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (E->getDestroyedTypeInfo()) { 6700a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedTypeInfo 670143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 6702f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor ObjectType, 0, 6703f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor QualifierLoc.getNestedNameSpecifier()); 6704a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!DestroyedTypeInfo) 6705f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6706a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = DestroyedTypeInfo; 6707a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else if (ObjectType->isDependentType()) { 6708a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // We aren't likely to be able to resolve the identifier down to a type 6709a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // now anyway, so just retain the identifier. 6710a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 6711a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 6712a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else { 6713a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // Look for a destructor known with the given name. 6714b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 6715a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor *E->getDestroyedTypeIdentifier(), 6716a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc(), 6717a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /*Scope=*/0, 6718a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS, ObjectTypePtr, 6719a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor false); 6720a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!T) 6721f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6722c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6723a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed 6724a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 6725a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 6726a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 672726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 672826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeTypeInfo = 0; 672926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (E->getScopeTypeInfo()) { 673043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); 673126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (!ScopeTypeInfo) 6732f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6733a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 6734c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 67359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 6736a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->getOperatorLoc(), 6737a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->isArrow(), 6738f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS, 673926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor ScopeTypeInfo, 674026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getColonColonLoc(), 6741fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor E->getTildeLoc(), 6742a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed); 6743a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor} 67441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6745a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived> 674660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6747ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr( 6748454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall UnresolvedLookupExpr *Old) { 6749f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); 6750f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6751f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 6752f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Sema::LookupOrdinaryName); 6753f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6754f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Transform all the decls. 6755f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), 6756f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = Old->decls_end(); I != E; ++I) { 67577c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 67587c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getNameLoc(), 67597c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 67609f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 67619f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 67629f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 67639f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 67649f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 67659f54ad4381370c6b771424b53d219e661d6d6706John McCall else 6766f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67679f54ad4381370c6b771424b53d219e661d6d6706John McCall } 6768f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6769f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Expand using declarations. 6770f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (isa<UsingDecl>(InstD)) { 6771f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 6772f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 6773f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = UD->shadow_end(); I != E; ++I) 6774f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(*I); 6775f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall continue; 6776f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 6777f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6778f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(InstD); 6779f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 6780f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6781f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Resolve a kind, but don't do any further analysis. If it's 6782f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // ambiguous, the callee needs to deal with it. 6783f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.resolveKind(); 6784f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6785f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Rebuild the nested-name qualifier, if present. 6786f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall CXXScopeSpec SS; 67874c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 67884c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc 67894c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 67904c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 6791f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6792c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 67934c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 6794c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } 6795c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6796c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (Old->getNamingClass()) { 679766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor CXXRecordDecl *NamingClass 679866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 679966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNameLoc(), 680066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 680166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 6802f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6803c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 680466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 6805f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 6806f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6807f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have no template arguments, it's a normal declaration name. 6808f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!Old->hasExplicitTemplateArgs()) 6809f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 6810f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6811f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have template arguments, rebuild them, then rebuild the 6812f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // templateid expression. 6813f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 6814fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 6815fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 6816fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6817fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 6818f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6819f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), 6820f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TransArgs); 6821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 682460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6825454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 68263d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 68273d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor if (!T) 6828f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 68313d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor T == E->getQueriedTypeSourceInfo()) 68323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildUnaryTypeTrait(E->getTrait(), 6835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocStart(), 6836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T, 6837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 684160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 68426ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 68436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); 68446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!LhsT) 68456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 68466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 68476ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); 68486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!RhsT) 68496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 68506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 68516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!getDerived().AlwaysRebuild() && 68526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) 68536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SemaRef.Owned(E); 68546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 68556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getDerived().RebuildBinaryTypeTrait(E->getTrait(), 68566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocStart(), 68576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT, RhsT, 68586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocEnd()); 68596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 68606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 68616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived> 68626ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult 6863865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 68642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DependentScopeDeclRefExpr *E) { 686500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc 686600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 686700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor if (!QualifierLoc) 6868f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 687043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 687143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 687243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 687343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 68742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 68752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 68762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 6877f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6879f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!E->hasExplicitTemplateArgs()) { 6880f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!getDerived().AlwaysRebuild() && 688100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor QualifierLoc == E->getQualifierLoc() && 68822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Note: it is sufficient to compare the Name component of NameInfo: 68832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // if name has not changed, DNLoc has not changed either. 68842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDeclName()) 68853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 688700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 68882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 6889f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /*TemplateArgs*/ 0); 6890f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor } 6891d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 6892d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 6893fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6894fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6895fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6896fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 6897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 689800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 68992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 6900f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall &TransArgs); 6901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 690460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6905454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 6906321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // CXXConstructExprs are always implicit, so when we have a 6907321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // 1-argument construction we just transform that argument. 6908321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor if (E->getNumArgs() == 1 || 6909321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) 6910321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor return getDerived().TransformExpr(E->getArg(0)); 6911321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor 6912b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); 6913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6915b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6916f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6917b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6918b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 6919b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 69207c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 69217c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 6922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 6923f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6926ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6927aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6928aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6929aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6930aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType() && 6933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 6934c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor !ArgumentChanged) { 69351af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark the constructor as referenced. 69361af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: Instantiation-specific 6937c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 69383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6939c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor } 69401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69414411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), 69424411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor Constructor, E->isElidable(), 69438c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(Args), 69448c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor E->requiresZeroInitialization(), 6945428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getConstructionKind(), 6946428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getParenRange()); 6947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression. 6950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 69515132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 69525132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that. 6953b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 695460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6955454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 69565132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 6957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69594765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should 69604765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated. 6961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 69624765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we 69635132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that. 6964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 696560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 69664765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 69675132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 6968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 697160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 6973ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXTemporaryObjectExpr *E) { 6974ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 6975ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 6976f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 6979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 6980c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getDerived().TransformDecl(E->getLocStart(), 69817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 6982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 6983f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6986ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Args.reserve(E->getNumArgs()); 6988aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6989aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6990aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 69911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6993ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 6994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 699591be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor !ArgumentChanged) { 699691be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor // FIXME: Instantiation-specific 6997ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 69983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.MaybeBindToTemporary(E); 699991be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor } 7000ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7001ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXTemporaryObjectExpr(T, 7002ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7003b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 700860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 7010454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXUnresolvedConstructExpr *E) { 7011ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7012ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7013f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7016ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7017aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->arg_size()); 7018aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 7019aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7020aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7021aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7023ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 70253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: we're faking the locations of the commas 7028ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXUnresolvedConstructExpr(T, 7029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLParenLoc(), 7030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 703560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7036865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 70372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CXXDependentScopeMemberExpr *E) { 7038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the base of the expression. 703960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7040aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *OldBase; 7041aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7042aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType ObjectType; 7043aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->isImplicitAccess()) { 7044aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = E->getBase(); 7045aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(OldBase); 7046aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7047f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7049aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall // Start the member reference and compute the object's type. 7050b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTy; 7051d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool MayBePseudoDestructor = false; 70529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7053aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall E->getOperatorLoc(), 7054a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7055d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ObjectTy, 7056d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor MayBePseudoDestructor); 7057aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7058f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7059aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 7060b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ObjectTy.get(); 7061aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 7062aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7063aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = 0; 7064aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(E->getBaseType()); 7065aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); 7066aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 70671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70686cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // Transform the first part of the nested-name-specifier that qualifies 70696cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // the member name. 7070c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope 70716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor = getDerived().TransformFirstQualifierInScope( 70727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getFirstQualifierFoundInScope(), 70737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getQualifierLoc().getBeginLoc()); 70741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 7076a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (E->getQualifier()) { 70777c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc 70787c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 70797c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, 70807c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor FirstQualifierInScope); 70817c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor if (!QualifierLoc) 7082f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7083a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor } 70841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 708543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 708643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 708743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 708843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 70892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 709043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 70912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7094aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->hasExplicitTemplateArgs()) { 70953b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // This is a reference to a member without an explicitly-specified 70963b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // template argument list. Optimize for this common case. 70973b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor if (!getDerived().AlwaysRebuild() && 7098aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base.get() == OldBase && 7099aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType == E->getBaseType() && 71007c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc == E->getQualifierLoc() && 71012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getMember() && 71023b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 71033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7106aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 71073b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->isArrow(), 71083b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getOperatorLoc(), 71097c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 7110129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall FirstQualifierInScope, 71112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7112129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /*TemplateArgs*/ 0); 71133b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 71143b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor 7115d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7116fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7117fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7118fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7119fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 71201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7122aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7123b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 7124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 71257c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 71263b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope, 71272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7128129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall &TransArgs); 7129129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall} 7130129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7131129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived> 713260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7133454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 7134129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform the base of the expression. 713560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7136aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7137aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!Old->isImplicitAccess()) { 7138aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(Old->getBase()); 7139aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7140f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7141aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 7142aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7143aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(Old->getBaseType()); 7144aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 7145129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 71464c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 71474c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 71484c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc 71494c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 71504c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7151f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7152129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7153129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 71542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(SemaRef, Old->getMemberNameInfo(), 7155129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Sema::LookupOrdinaryName); 7156129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7157129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform all the decls. 7158129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), 7159129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = Old->decls_end(); I != E; ++I) { 71607c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 71617c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getMemberLoc(), 71627c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 71639f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 71649f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 71659f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 71669f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 71679f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 71689f54ad4381370c6b771424b53d219e661d6d6706John McCall else 7169f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71709f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7171129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7172129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Expand using declarations. 7173129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (isa<UsingDecl>(InstD)) { 7174129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7175129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7176129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = UD->shadow_end(); I != E; ++I) 7177129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(*I); 7178129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall continue; 7179129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7180129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7181129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(InstD); 7182129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7183129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7184129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.resolveKind(); 7185129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7186c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor // Determine the naming class. 7187042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth if (Old->getNamingClass()) { 7188c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt CXXRecordDecl *NamingClass 7189c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 719066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getMemberLoc(), 719166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 719266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7193f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 719566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7196c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor } 7197c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7198129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TemplateArgumentListInfo TransArgs; 7199129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->hasExplicitTemplateArgs()) { 7200129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setLAngleLoc(Old->getLAngleLoc()); 7201129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setRAngleLoc(Old->getRAngleLoc()); 7202fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7203fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7204fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7205fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7206129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7207c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 7208c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 7209c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 7210c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 7211c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 7212c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 7213c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 72149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 7215aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7216129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getOperatorLoc(), 7217129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->isArrow(), 72184c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc, 7219c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope, 7220129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R, 7221129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall (Old->hasExplicitTemplateArgs() 7222129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall ? &TransArgs : 0)); 7223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 722660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 72272e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 72282e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 72292e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (SubExpr.isInvalid()) 72302e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return ExprError(); 72312e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 72322e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 72333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 72342e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 72352e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 72362e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl} 72372e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 72382e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived> 72392e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult 7240be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 72414f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 72424f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (Pattern.isInvalid()) 72434f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return ExprError(); 72444f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 72454f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 72464f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return SemaRef.Owned(E); 72474f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 724867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 724967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor E->getNumExpansions()); 7250be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor} 7251ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7252ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived> 7253ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult 7254ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 7255ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // If E is not value-dependent, then nothing will change when we transform it. 7256ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: This is an instantiation-centric view. 7257ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!E->isValueDependent()) 7258ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7259ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7260ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: None of the implementations of TryExpandParameterPacks can ever 7261ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // produce a diagnostic when given only a single unexpanded parameter pack, 7262ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // so 7263ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 7264ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor bool ShouldExpand = false; 7265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 7266cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 7267ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 7268ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor &Unexpanded, 1, 7269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, RetainExpansion, 7270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 7271ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return ExprError(); 7272ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7273d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!ShouldExpand || RetainExpansion) 7274ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7275be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 7276ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // We now know the length of the parameter pack, so build a new expression 7277ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // that stores that length. 7278ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), 7279ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor E->getPackLoc(), E->getRParenLoc(), 7280cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor *NumExpansions); 7281ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor} 7282ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7283be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived> 7284be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult 7285c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 7286c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SubstNonTypeTemplateParmPackExpr *E) { 7287c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Default behavior is to do nothing with this transformation. 7288c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return SemaRef.Owned(E); 7289c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor} 7290c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 7291c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived> 7292c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult 7293454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 72943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 72971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 729860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7299454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 730081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedTypeInfo 730181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 730281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor if (!EncodedTypeInfo) 7303f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 730681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 73073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 731081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo, 7311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 731560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7316454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 731792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Transform arguments. 731892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor bool ArgChanged = false; 7319ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7320aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->getNumArgs()); 7321aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 7322aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 7323aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 732592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (E->getReceiverKind() == ObjCMessageExpr::Class) { 732692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Class message: transform the receiver type. 732792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor TypeSourceInfo *ReceiverTypeInfo 732892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformType(E->getClassReceiverTypeInfo()); 732992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!ReceiverTypeInfo) 7330f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7331c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 733292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 733392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 733492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 73353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 733692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 733792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new class message send. 733892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 733992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 7340f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis E->getSelectorLoc(), 734192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 734292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 734392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 734492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 734592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 734692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 734792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Instance message: transform the receiver 734892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 734992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor "Only class and instance messages may be instantiated"); 735060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver 735192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformExpr(E->getInstanceReceiver()); 735292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Receiver.isInvalid()) 7353f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 735492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 735592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 735692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 735792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 73583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7359c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 736092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new instance message send. 73619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCMessageExpr(Receiver.get(), 736292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 7363f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis E->getSelectorLoc(), 736492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 736592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 736692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 736792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 7368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 73701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 737160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7372454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 73733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 73761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 737760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7378454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 73793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 73821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 738360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7384454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 7385f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 738660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7387f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 7388f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7389f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor 7390f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // We don't need to transform the ivar; it will never change. 7391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7392f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 7393f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 7394f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 73953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7396c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 73979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 7398f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->getLocation(), 7399f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow(), E->isFreeIvar()); 7400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 74021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 740360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7404454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 740512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // 'super' and types never change. Property never changes. Just 740612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // retain the existing expression. 740712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!E->isObjectReceiver()) 74083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 74098ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 7410e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // Transform the base expression. 741160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7412e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Base.isInvalid()) 7413f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7414c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7415e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // We don't need to transform the property; it will never change. 7416c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7417e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // If nothing changed, just retain the existing expression. 7418e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (!getDerived().AlwaysRebuild() && 7419e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Base.get() == E->getBase()) 74203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 742212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (E->isExplicitProperty()) 742312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 742412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getExplicitProperty(), 742512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 742612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 742712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 742812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getType(), 742912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertyGetter(), 743012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertySetter(), 743112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 7432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 74341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 743560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7436454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 7437f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 743860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7439f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 7440f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7441c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7442f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 7443f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 7444f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 74453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7446c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 74479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 7448f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow()); 7449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 74511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 745260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7453454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 7454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7455ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> SubExprs(SemaRef); 7456aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs.reserve(E->getNumSubExprs()); 7457aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 7458aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs, &ArgumentChanged)) 7459aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 74601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 74633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 74641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7465b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 7466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(SubExprs), 7467b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 74701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 747160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7472454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 7473c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockDecl *oldBlock = E->getBlockDecl(); 7474a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 7475c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); 7476c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 7477c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7478c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 7479c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall llvm::SmallVector<ParmVarDecl*, 4> params; 7480c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall llvm::SmallVector<QualType, 4> paramTypes; 7481a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 7482a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Parameter substitution. 7483c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), 7484c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_begin(), 7485c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_size(), 7486c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 0, paramTypes, ¶ms)) 7487a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return true; 7488c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7489c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall const FunctionType *exprFunctionType = E->getFunctionType(); 7490c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType exprResultType = exprFunctionType->getResultType(); 7491c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!exprResultType.isNull()) { 7492c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!exprResultType->isDependentType()) 7493c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = exprResultType; 7494c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall else if (exprResultType != getSema().Context.DependentTy) 7495c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = getDerived().TransformType(exprResultType); 7496a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 7497a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 7498a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // If the return type has not been determined yet, leave it as a dependent 7499a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // type; it'll get set when we process the body. 7500c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType.isNull()) 7501c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = getSema().Context.DependentTy; 7502a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 7503a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // Don't allow returning a objc interface by value. 7504c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType->isObjCObjectType()) { 7505c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall getSema().Diag(E->getCaretLocation(), 7506a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor diag::err_object_cannot_be_passed_returned_by_value) 7507c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall << 0 << blockScope->ReturnType; 7508a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return ExprError(); 7509a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor } 7510711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 7511c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType functionType = getDerived().RebuildFunctionProtoType( 7512c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType, 7513c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.data(), 7514c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.size(), 7515c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->isVariadic(), 7516c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 0, RQ_None, 7517c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall exprFunctionType->getExtInfo()); 7518c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->FunctionType = functionType; 7519711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 7520711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Set the parameters on the block decl. 7521c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!params.empty()) 7522c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setParams(params.data(), params.size()); 7523a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 7524a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // If the return type wasn't explicitly set, it will have been marked as a 7525a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // dependent type (DependentTy); clear out the return type setting so 7526a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // we will deduce the return type when type-checking the block's body. 7527c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType == getSema().Context.DependentTy) 7528c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = QualType(); 7529a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 7530711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Transform the body 7531c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall StmtResult body = getDerived().TransformStmt(E->getBody()); 7532c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (body.isInvalid()) 7533711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return ExprError(); 7534711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 7535c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG 7536c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // In builds with assertions, make sure that we captured everything we 7537c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // captured before. 7538c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7539c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis); 7540c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7541c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), 7542c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall e = oldBlock->capture_end(); i != e; ++i) { 75436b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *oldCapture = i->getVariable(); 7544c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7545c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // Ignore parameter packs. 7546c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (isa<ParmVarDecl>(oldCapture) && 7547c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall cast<ParmVarDecl>(oldCapture)->isParameterPack()) 7548c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall continue; 7549c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7550c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall VarDecl *newCapture = 7551c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 7552c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldCapture)); 75536b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall assert(blockScope->CaptureMap.count(newCapture)); 7554c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall } 7555c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif 7556c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 7557c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 7558c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall /*Scope=*/0); 7559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 75611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 756260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7563454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { 7564a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ValueDecl *ND 7565a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 7566a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian E->getDecl())); 7567a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!ND) 7568f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7570a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!getDerived().AlwaysRebuild() && 7571a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ND == E->getDecl()) { 7572a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Mark it referenced in the new context regardless. 7573a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // FIXME: this is a bit instantiation-specific. 7574a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 7575a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 75763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7577a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 7578a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 75792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); 758040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), 75812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ND, NameInfo, 0); 7582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 7585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction 7586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 7587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 75881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 758985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 759085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 75912865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildPointerType(PointeeType, Star, 7592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 7593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 75951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 759685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 759785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 75982865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildBlockPointerType(PointeeType, Star, 7599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 7600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 76021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 76031eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 760485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 760585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool WrittenAsLValue, 760685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 76072865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 760885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 7609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 76111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 76121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 761385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 761485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType ClassType, 761585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 76162865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 761785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 7618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 7619577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 76211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 7622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType, 7623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 7624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 7625577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 7626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 7627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 7628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (SizeExpr || !Size) 7629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 7630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 7631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseEntity()); 76321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Types[] = { 76341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 76351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 76361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 7637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor }; 7638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const unsigned NumTypes = sizeof(Types) / sizeof(QualType); 7639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType SizeType; 7640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor for (unsigned I = 0; I != NumTypes; ++I) 7641577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 7642577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SizeType = Types[I]; 7643577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor break; 7644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 76451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, 76479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME*/BracketsRange.getBegin()); 76481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, 7649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 76501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDerived().getBaseEntity()); 7651577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 76521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 76541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 76551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 7656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 7657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 765885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 765985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 76601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, 766185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 7662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 7663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 76651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 76661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 7667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 766885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 766985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 76701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, 767185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 7672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 76731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 76751eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 76761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 7677577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 76789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 7679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 7680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 76811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 76829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 7683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 7684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 7685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 76871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 76881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 7689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 76909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 7691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 7692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 76931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 76949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 7695577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 7696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 7697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7698577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 7699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 7700e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson unsigned NumElements, 7701e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind) { 7702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor // FIXME: semantic checking! 7703e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 7704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 77051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7706577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 7707577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 7708577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumElements, 7709577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 7710577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 7711577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NumElements, true); 7712577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IntegerLiteral *VectorSize 77139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 77149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis AttributeLoc); 77159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 7716577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 77171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7718577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 77191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 77201eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 77219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 7722577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 77239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 7724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 77251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 7727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, 77281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 7729577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 77301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool Variadic, 7731fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman unsigned Quals, 7732c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 7733fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info) { 77341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, 7735c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor Quals, RefQualifier, 7736577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseLocation(), 7737fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman getDerived().getBaseEntity(), 7738fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman Info); 7739577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 77401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 7742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 7743a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return SemaRef.Context.getFunctionNoProtoType(T); 7744a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 7745a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 7746a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 7747ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { 7748ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(D && "no decl found"); 7749ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (D->isInvalidDecl()) return QualType(); 7750ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 775192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // FIXME: Doesn't account for ObjCInterfaceDecl! 7752ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeDecl *Ty; 7753ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (isa<UsingDecl>(D)) { 7754ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingDecl *Using = cast<UsingDecl>(D); 7755ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(Using->isTypeName() && 7756ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-typename using"); 7757ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 7758ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // A valid resolved using typename decl points to exactly one type decl. 7759ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(++Using->shadow_begin() == Using->shadow_end()); 7760ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 7761c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7762ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } else { 7763ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(isa<UnresolvedUsingTypenameDecl>(D) && 7764ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-using decl"); 7765ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<UnresolvedUsingTypenameDecl>(D); 7766ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 7767ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 7768ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return SemaRef.Context.getTypeDeclType(Ty); 7769ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 7770ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 7771ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> 77722a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 77732a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 77742a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildTypeofExprType(E, Loc); 7775577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 7776577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7777577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 7778577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 7779577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeOfType(Underlying); 7780577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 7781577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7782577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 77832a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 77842a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 77852a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildDecltypeType(E, Loc); 7786577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 7787577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7788577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 7789577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 7790833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateName Template, 7791833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateNameLoc, 7792d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &TemplateArgs) { 7793d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 7794577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 77951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7796dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 7797dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier * 7798dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 7799dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 7800a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor IdentifierInfo &II, 7801c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor QualType ObjectType, 7802d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NamedDecl *FirstQualifierInScope) { 7803dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor CXXScopeSpec SS; 7804dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor // FIXME: The source location information is all wrong. 7805c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor SS.MakeTrivial(SemaRef.Context, Prefix, Range); 78062e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(), 78072e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor /*FIXME:*/Range.getEnd(), 78082e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor ObjectType, false, 78092e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor SS, FirstQualifierInScope, 78102e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor false)) 78112e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor return 0; 78122e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor 78132e4c34ac53d08633b9473df921db4c7e4c9cd577Douglas Gregor return SS.getScopeRep(); 7814dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor} 7815dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 7816dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 7817dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier * 7818dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 7819dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 7820dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NamespaceDecl *NS) { 7821dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); 7822dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor} 7823dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 7824dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 7825dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier * 7826dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 7827dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 782814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NamespaceAliasDecl *Alias) { 782914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias); 783014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor} 783114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 783214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregortemplate<typename Derived> 783314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas GregorNestedNameSpecifier * 783414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 783514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor SourceRange Range, 7836dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor bool TemplateKW, 7837edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor QualType T) { 7838edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor if (T->isDependentType() || T->isRecordType() || 7839dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { 7840a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); 7841dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, 7842dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor T.getTypePtr()); 7843dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 78441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7845dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; 7846dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return 0; 7847dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor} 78481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7849d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 78501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 7851d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, 7852d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 7853d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template) { 78541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, 7855d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor Template); 7856d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 7857d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 7858d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 78591eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 7860d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, 78611efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SourceRange QualifierRange, 78623b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor const IdentifierInfo &II, 786343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 786443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 7865d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor CXXScopeSpec SS; 7866c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange); 7867014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor UnqualifiedId Name; 7868014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); 7869d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 7870d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 7871d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*FIXME:*/getDerived().getBaseLocation(), 7872d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 7873d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Name, 7874b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 7875d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 7876d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 787743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return Template.get(); 7878d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 78791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7880b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 7881ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 7882ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, 7883ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 7884ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType) { 7885ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor CXXScopeSpec SS; 7886c34348a7ef1a6b3f92a644a227953800cd1f9947Douglas Gregor SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation())); 7887ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId Name; 7888ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. 7889ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), 7890ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Operator, SymbolLocations); 7891d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 7892d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 7893ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /*FIXME:*/getDerived().getBaseLocation(), 7894d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 7895d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Name, 7896b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 7897d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 7898d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 7899d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return Template.template getAsVal<TemplateName>(); 7900ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 7901c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7902ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived> 790360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 7905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 79069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *OrigCallee, 79079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 79089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second) { 79099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee = OrigCallee->IgnoreParenCasts(); 79109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 79111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7912b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Determine whether this should be a builtin operation. 7913f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) { 79149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 79159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) 79169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinArraySubscriptExpr(First, 79179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee->getLocStart(), 79189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second, OpLoc); 79191a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman } else if (Op == OO_Arrow) { 79201a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman // -> is never a builtin operation. 79219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); 79229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall } else if (Second == 0 || isPostIncDec) { 79239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType()) { 7924b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The argument is not of overloadable type, so try to create a 7925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // built-in unary operation. 79262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 7927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 79281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 7930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 7931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } else { 79329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 79339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) { 7934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Neither of the arguments is an overloadable type, so try to 7935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // create a built-in binary operation. 79362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 793760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 79389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 7939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 7940f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 79411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 7943b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 7944b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 79451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Compute the transformed set of functions (and function templates) to be 7947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // used during overload resolution. 79486e26689f5d513e24ad7783a4493201930fdeccc0John McCall UnresolvedSet<16> Functions; 79491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 7951ba13543329afac4a0d01304ec2ec4924d99306a6John McCall assert(ULE->requiresADL()); 7952ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 7953ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // FIXME: Do we have to check 7954ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // IsAcceptableNonMemberOperatorCandidate for each of these? 79556e26689f5d513e24ad7783a4493201930fdeccc0John McCall Functions.append(ULE->decls_begin(), ULE->decls_end()); 7956ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } else { 79579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); 7958ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 79591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Add any functions found via argument-dependent lookup. 79619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Args[2] = { First, Second }; 79629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall unsigned NumArgs = 1 + (Second != 0); 79631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for unary operators. 7965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (NumArgs == 1 || isPostIncDec) { 79662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 7967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 79689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); 7969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 79701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7971f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) 79729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), 7973ba13543329afac4a0d01304ec2ec4924d99306a6John McCall OpLoc, 79749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First, 79759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second); 7976f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl 7977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for binary operators. 79782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 797960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 7980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); 7981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 7982f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 79831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 7985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 79861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 798726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived> 798860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 79899ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 799026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation OperatorLoc, 799126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor bool isArrow, 7992f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 799326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 799426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 7995fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 7996a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed) { 79979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 79989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (Base->isTypeDependent() || Destroyed.getIdentifier() || 799926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor (!isArrow && !BaseType->getAs<RecordType>()) || 8000c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (isArrow && BaseType->getAs<PointerType>() && 8001bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif !BaseType->getAs<PointerType>()->getPointeeType() 8002bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif ->template getAs<RecordType>())){ 800326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // This pseudo-destructor expression is still a pseudo-destructor. 80049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, 800526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor isArrow? tok::arrow : tok::period, 8006fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SS, ScopeType, CCLoc, TildeLoc, 8007a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed, 800826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*FIXME?*/true); 800926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 80102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8011a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 80122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 80132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 80142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 80152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.setNamedTypeInfo(DestroyedType); 80162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 801726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // FIXME: the ScopeType should be tacked onto SS. 80182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 80199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, 802026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor OperatorLoc, isArrow, 802126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SS, /*FIXME: FirstQualifier*/ 0, 80222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 802326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*TemplateArgs*/ 0); 802426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor} 802526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 8026577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang 8027577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8028577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H 8029